Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module(

bazel_dep(
name = "platforms",
version = "0.0.8",
version = "0.0.10",
)
bazel_dep(
name = "rules_java",
Expand All @@ -15,14 +15,28 @@ bazel_dep(
name = "rules_license",
version = "1.0.0",
)
bazel_dep(
name = "abseil-cpp",
version = "20240116.3",
)
bazel_dep(
name = "protobuf",
version = "21.7",
version = "27.0",
repo_name = "com_google_protobuf",
)

# workaround build problems on Windows
single_version_override(
module_name = "protobuf",
patch_strip = 1,
# see https://github.com/protocolbuffers/protobuf/issues/16844
# TODO: remove for protobuf version >= 31.0
patches = ["//haskell:private/com_google_protobuf-protoc-dbghlp.diff"],
)

bazel_dep(
name = "rules_cc",
version = "0.0.9",
version = "0.0.15",
)
bazel_dep(
name = "rules_nodejs",
Expand All @@ -38,7 +52,7 @@ bazel_dep(
)
bazel_dep(
name = "bazel_skylib",
version = "1.5.0",
version = "1.7.1",
)
bazel_dep(
name = "rules_proto",
Expand Down Expand Up @@ -196,7 +210,7 @@ register_toolchains(
# For buildifier
bazel_dep(
name = "rules_go",
version = "0.39.1",
version = "0.41.0",
dev_dependency = True,
repo_name = "io_bazel_rules_go",
)
Expand Down Expand Up @@ -240,13 +254,6 @@ go_deps.module(
use_repo(
go_deps,
"com_github_gogo_protobuf",
"com_github_golang_mock",
"com_github_golang_protobuf",
"org_golang_google_genproto",
"org_golang_google_grpc",
"org_golang_google_protobuf",
"org_golang_x_net",
"org_golang_x_tools",
)

# For documentation
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")

rules_proto_toolchains()

load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")

rules_java_dependencies()

rules_java_toolchains()

# For buildifier
http_archive(
name = "io_bazel_rules_go",
Expand Down
9 changes: 0 additions & 9 deletions buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ _lint_warnings = [
"-function-docstring-args", # TODO
"-function-docstring-header", # TODO
"-function-docstring-return", # TODO
"-native-cc-common",
"-native-cc-info",
"-native-cc-library",
"-native-cc-shared-library-info",
"-native-java-common",
"-native-java-info",
"-native-proto",
"-native-proto-common",
"-native-proto-info",
"-module-docstring",
]

Expand Down
74 changes: 53 additions & 21 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,55 @@ set_site_end_location(
}),
)

libraries = [
"defs",
"toolchain",
"cabal",
"repositories",
"ghc_bindist",
"nixpkgs",
"protobuf",
"c2hs",
]
#
libraries = {
"defs": [
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@com_google_protobuf//bazel/common:proto_info_bzl",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:srcs",
"@rules_java//java:rules",
"@rules_shell//shell:rules_bzl",
"//haskell",
],
"toolchain": [
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@com_google_protobuf//bazel/common:proto_info_bzl",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:srcs",
"@rules_java//java:rules",
"//haskell",
],
"cabal": [
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@com_google_protobuf//bazel/common:proto_info_bzl",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:srcs",
"@rules_proto//proto:defs",
"//haskell",
],
"repositories": ["//haskell"],
"ghc_bindist": [
"@rules_cc//cc/common",
"//haskell",
],
"nixpkgs": [":haskell_nix"],
"protobuf": [
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@com_google_protobuf//bazel/common:proto_info_bzl",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:srcs",
"@rules_java//java:rules",
"@rules_proto//proto:defs",
"//haskell",
],
"c2hs": [
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:srcs",
"//haskell",
],
}

# moved here so that //haskell is not dependent upon rules_nixpkgs_*
bzl_library(
Expand All @@ -59,11 +98,7 @@ bzl_library(
provider_template = ":templates/metadata/provider.vm",
rule_template = ":templates/metadata/rule.vm",
tags = ["dont_test_on_windows"],
deps = [
":haskell_nix",
"//haskell",
"@rules_shell//shell:rules_bzl",
],
deps = lib_deps,
),
# Generate markdown API documentation.
stardoc(
Expand All @@ -76,11 +111,7 @@ bzl_library(
provider_template = ":templates/markdown/provider.vm",
rule_template = ":templates/markdown/rule.vm",
tags = ["dont_test_on_windows"],
deps = [
":haskell_nix",
"//haskell",
"@rules_shell//shell:rules_bzl",
],
deps = lib_deps,
),
# Convert markdown to html.
genrule(
Expand Down Expand Up @@ -109,7 +140,8 @@ $(execpath //docs/pandoc) \
tools = ["//docs/pandoc"],
),
)
for lib in libraries
#
for lib, lib_deps in libraries.items()
]

# Combine all API documentation metadata.
Expand Down
14 changes: 13 additions & 1 deletion examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ bazel_dep(
name = "rules_nixpkgs_core",
version = "0.13.0",
)
bazel_dep(
name = "rules_nixpkgs_cc",
version = "0.13.0",
)
bazel_dep(
name = "rules_haskell_nix",
version = "1.0",
Expand All @@ -27,7 +31,7 @@ bazel_dep(

bazel_dep(
name = "rules_cc",
version = "0.0.9",
version = "0.1.1",
)
bazel_dep(
name = "rules_sh",
Expand All @@ -43,11 +47,19 @@ non_module_deps = use_extension(":non_module_deps.bzl", "non_module_deps")
use_repo(
non_module_deps,
"Cabal",
"nixpkgs_config_cc",
"nixpkgs_config_cc_info",
"nixpkgs_config_cc_toolchains",
"nixpkgs_default",
"os_info",
"split",
"zlib.hs",
)

register_toolchains(
"@nixpkgs_config_cc_toolchains//:all",
)

stack_snapshot = use_extension(
"@rules_haskell//extensions:stack_snapshot.bzl",
"stack_snapshot",
Expand Down
15 changes: 15 additions & 0 deletions examples/non_module_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@rules_haskell//tools:os_info.bzl", "os_info")
load("@rules_nixpkgs_cc//:cc.bzl", "nixpkgs_cc_configure")
load("@rules_nixpkgs_core//:nixpkgs.bzl", "nixpkgs_local_repository")

def repositories(*, bzlmod):
# Some helpers for platform-dependent configuration
os_info(name = "os_info")

nixpkgs_local_repository(
name = "nixpkgs_default",
nix_file = "@rules_haskell//nixpkgs:default.nix",
)

nixpkgs_cc_configure(
# Don't override the default cc toolchain needed for bindist mode.
name = "nixpkgs_config_cc",
repository = "@nixpkgs_default",
register = not bzlmod,
cc_std = "c++14",
)

# For the cat_hs example.
http_archive(
name = "zlib.hs",
Expand Down
11 changes: 1 addition & 10 deletions haskell/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,12 @@ bzl_library(
],
)

# @rules_cc//cc does not define a bzl_library itself, instead we define our
# own using the @rules_cc//cc:srcs filegroup.
bzl_library(
name = "rules_cc",
srcs = [
"@rules_cc//cc:srcs",
],
)

bzl_library(
name = "haskell",
srcs = glob(["**/*.bzl"]),
visibility = ["//visibility:public"],
deps = [
":bazel_tools",
":rules_cc",
"//haskell/asterius:asterius_bzl",
"//haskell/experimental:defs.bzl",
"//haskell/experimental:providers.bzl",
Expand All @@ -88,6 +78,7 @@ bzl_library(
"@bazel_skylib//lib:shell",
"@bazel_skylib//lib:versions",
"@bazel_skylib//rules:expand_template",
"@rules_cc//cc:bzl_srcs",
"@rules_sh//sh:posix",
],
)
Expand Down
5 changes: 3 additions & 2 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe", "read_netrc", "use_netrc")
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_common")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
load(":cc.bzl", "cc_interop_info", "ghc_cc_program_args")
load(":haddock.bzl", "generate_unified_haddock_info")
Expand Down Expand Up @@ -213,7 +214,7 @@ def _prepare_cabal_inputs(
# already covered by their corresponding package-db entries. We only need
# to add libraries and headers for direct C library dependencies to the
# command line.
direct_libs = get_ghci_library_files(hs, cc.cc_libraries_info, cc.cc_libraries)
direct_libs = get_ghci_library_files(hs, cc.cc_libraries_info, cc.cc_libraries_direct)

# The regular Haskell rules perform mostly static linking, i.e. where
# possible all C library dependencies are linked statically. Cabal has no
Expand Down Expand Up @@ -1508,7 +1509,7 @@ def _pin_packages(repository_ctx, resolved):
)
hashes_url = "https://raw.githubusercontent.com/commercialhaskell/all-cabal-hashes/" + hashes_commit

resolved = dict(**resolved)
resolved = dict(resolved)
for (_name, spec) in resolved.items():
# Determine package sha256
if spec["location"]["type"] == "hackage":
Expand Down
17 changes: 15 additions & 2 deletions haskell/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ load(
"CPP_LINK_EXECUTABLE_ACTION_NAME",
"C_COMPILE_ACTION_NAME",
)
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_common")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("@rules_cc//cc/common:cc_shared_library_info.bzl", "CcSharedLibraryInfo")
load(
"//haskell:providers.bzl",
"HaskellInfo",
Expand All @@ -31,7 +33,8 @@ CcInteropInfo = provider(
"linker_flags": "Flags to forward to the linker",
"include_args": "Extra include dirs",
"cc_libraries_info": "HaskellCcLibrariesInfo",
"cc_libraries": "depset, C libraries from direct linking dependencies.",
"cc_libraries": "depset, C libraries from direct cc_library dependencies (deprecated, use cc_libraries_direct).",
"cc_libraries_direct": "depset, C libraries from direct dependencies, including cc_shared_library.",
"transitive_libraries": "depset, C and Haskell libraries from transitive linking dependencies.",
"plugin_libraries": "depset, C and Haskell libraries from transitive plugin dependencies.",
"setup_libraries": "depset, C and Haskell libraries from Cabal setup dependencies.",
Expand All @@ -50,6 +53,7 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
CcInteropInfo: Information needed for CC interop.
"""
ccs = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep and HaskellInfo not in dep]
cc_shared_libraries = [dep[CcSharedLibraryInfo] for dep in ctx.attr.deps if CcSharedLibraryInfo in dep]

hdrs = []
include_args = []
Expand Down Expand Up @@ -160,6 +164,13 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
plugin_libraries = _transitive_libraries_from_attr(ctx, "plugins")
setup_libraries = _transitive_libraries_from_attr(ctx, "setup_deps")

# Collect direct libraries from CcInfo only (for backward compatibility)
direct_libraries_from_cc_info = [lib for li in cc_common.merge_cc_infos(cc_infos = ccs).linking_context.linker_inputs.to_list() for lib in li.libraries]

# Also include libraries from CcSharedLibraryInfo
direct_libraries_all = list(direct_libraries_from_cc_info)
direct_libraries_all.extend([lib for info in cc_shared_libraries for lib in info.linker_input.libraries])

return CcInteropInfo(
tools = struct(**tools),
env = env,
Expand All @@ -174,7 +185,8 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
# https://github.com/bazelbuild/bazel/issues/4571.
linker_flags = linker_flags,
cc_libraries_info = cc_libraries_info,
cc_libraries = get_cc_libraries(cc_libraries_info, [lib for li in cc_common.merge_cc_infos(cc_infos = ccs).linking_context.linker_inputs.to_list() for lib in li.libraries]),
cc_libraries = get_cc_libraries(cc_libraries_info, direct_libraries_from_cc_info),
cc_libraries_direct = get_cc_libraries(cc_libraries_info, direct_libraries_all),
transitive_libraries = transitive_libraries,
plugin_libraries = plugin_libraries,
setup_libraries = setup_libraries,
Expand All @@ -184,6 +196,7 @@ def ghc_cc_program_args(hs, cc, ld):
"""Returns the -pgm* flags required to override cc.

Args:
hs: HaskellContext
cc: string, path to the C compiler (cc_wrapper).
ld: string, path to the linker (ld).

Expand Down
1 change: 1 addition & 0 deletions haskell/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ load(
"flag_set",
"tool_path",
)
load("@rules_cc//cc:defs.bzl", "cc_common")

def _impl(ctx):
tool_paths = [
Expand Down
Loading