Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel 7 macos debug #2231

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ jobs:
# Execute the tests dumping out memory/process information before and after each test.
RHT_PRINT_MEMORY=true ./bazel-ci-bin/tests/run-tests
bazel coverage //...
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true

test-bindist:
name: Build & Test - bindist
Expand Down
39 changes: 22 additions & 17 deletions haskell/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ load(
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load(
"//haskell:providers.bzl",
"GhcPluginInfo",
"HaskellInfo",
)
load(":private/cc_libraries.bzl", "deps_HaskellCcLibrariesInfo", "get_cc_libraries")
Expand Down Expand Up @@ -156,6 +155,11 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
cc_libraries_info = deps_HaskellCcLibrariesInfo(
ctx.attr.deps + getattr(ctx.attr, "plugins", []) + getattr(ctx.attr, "setup_deps", []),
)

transitive_libraries = _transitive_libraries_from_attr(ctx, "deps")
plugin_libraries = _transitive_libraries_from_attr(ctx, "plugins")
setup_libraries = _transitive_libraries_from_attr(ctx, "setup_deps")

return CcInteropInfo(
tools = struct(**tools),
env = env,
Expand All @@ -171,22 +175,9 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
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]),
transitive_libraries = [lib for li in cc_common.merge_cc_infos(cc_infos = [
dep[CcInfo]
for dep in ctx.attr.deps
if CcInfo in dep
]).linking_context.linker_inputs.to_list() for lib in li.libraries],
plugin_libraries = [lib for li in cc_common.merge_cc_infos(cc_infos = [
dep[CcInfo]
for plugin in getattr(ctx.attr, "plugins", [])
for dep in plugin[GhcPluginInfo].deps
if CcInfo in dep
]).linking_context.linker_inputs.to_list() for lib in li.libraries],
setup_libraries = [lib for li in cc_common.merge_cc_infos(cc_infos = [
dep[CcInfo]
for dep in getattr(ctx.attr, "setup_deps", [])
if CcInfo in dep
]).linking_context.linker_inputs.to_list() for lib in li.libraries],
transitive_libraries = transitive_libraries,
plugin_libraries = plugin_libraries,
setup_libraries = setup_libraries,
)

def ghc_cc_program_args(hs, cc, ld):
Expand Down Expand Up @@ -237,3 +228,17 @@ def ghc_cc_program_args(hs, cc, ld):
"-r",
])
return args

def _transitive_libraries_from_attr(ctx, attr_name):
cc_infos = [
input[CcInfo]
for input in getattr(ctx.attr, attr_name, [])
if CcInfo in input
]
cc_shared_library_infos = [
input[CcSharedLibraryInfo]
for input in getattr(ctx.attr, attr_name, [])
if CcSharedLibraryInfo in input
]
linker_inputs = cc_common.merge_cc_infos(cc_infos = cc_infos).linking_context.linker_inputs.to_list() + [info.linker_input for info in cc_shared_library_infos]
return [lib for li in linker_inputs for lib in li.libraries]
55 changes: 51 additions & 4 deletions haskell/private/cc_libraries.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def get_library_files(hs, cc_libraries_info, libraries_to_link, dynamic = False,
# happens during profiling builds.
static_libs.append(lib_to_link.static_library)

print("get_library_files -> {}, {}".format(static_libs, dynamic_libs))
return (static_libs, dynamic_libs)

def link_libraries(libs, args, get_dirname = get_dirname, prefix_optl = False):
Expand Down Expand Up @@ -290,6 +291,7 @@ def extend_HaskellCcLibrariesInfo(
ctx,
cc_libraries_info,
cc_info,
cc_shared_info,
is_haskell):
"""Adapt new LibraryToLink and add to HaskellCcLibrariesInfo.

Expand All @@ -301,6 +303,7 @@ def extend_HaskellCcLibrariesInfo(
ctx: Aspect or rule context.
cc_libraries_info: HaskellCcLibrariesInfo of all dependencies.
cc_info: CcInfo of the current target.
cc_shared_info: CcSharedLibraryInfo of the current target.
is_haskell: Bool, whether the current target is a Haskell library.

Returns:
Expand All @@ -309,7 +312,11 @@ def extend_HaskellCcLibrariesInfo(
posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
libraries = dict(cc_libraries_info.libraries)

for li in cc_info.linking_context.linker_inputs.to_list():
linker_inputs = cc_info.linking_context.linker_inputs.to_list() if cc_info else []
if cc_shared_info:
linker_inputs.append(cc_shared_info.linker_input)

for li in linker_inputs:
for lib_to_link in li.libraries:
key = cc_library_key(lib_to_link)
if key in libraries:
Expand Down Expand Up @@ -343,7 +350,7 @@ def extend_HaskellCcLibrariesInfo(

def _haskell_cc_libraries_aspect_impl(target, ctx):
if HaskellProtobufInfo in target:
# haskell_cc_libraries_aspect depends on the CcInfo and optionally
# haskell_cc_libraries_aspect depends on the CcInfo, CcSharedLibraryInfo and optionally
# HaskellInfo providers of a target. In the case of proto_library
# targets these providers are returned by the _haskell_proto_aspect.
# That aspect in turn requires HaskellCcLibrariesInfo in all its
Expand All @@ -361,11 +368,14 @@ def _haskell_cc_libraries_aspect_impl(target, ctx):
if HaskellCcLibrariesInfo in dep
])

if CcInfo in target:
cc_info = target[CcInfo] if CcInfo in target else None
cc_shared_info = target[CcSharedLibraryInfo] if CcSharedLibraryInfo in target else None
if cc_info or cc_shared_info:
cc_libraries_info = extend_HaskellCcLibrariesInfo(
ctx = ctx,
cc_libraries_info = cc_libraries_info,
cc_info = target[CcInfo],
cc_info = cc_info,
cc_shared_info = cc_shared_info,
is_haskell = HaskellInfo in target,
)

Expand All @@ -386,3 +396,40 @@ haskell_cc_libraries_aspect = aspect(
Create a symbolic link for each static library whose name doesn't match the
mangled name of the corresponding dynamic library.
"""

def merge_cc_shared_library_infos(owner, cc_shared_library_infos):
"""Similar to cc_common.merge_cc_infos but for CcSharedLibraryInfo

Args:
owner: The label of the target that produced all files used in this input.
cc_shared_library_infos: CcSharedLibraryInfo providers to be merged.

Returns:
CcSharedLibraryInfo
"""
dynamic_deps = []
exports = []
link_once_static_libs = {}
transitive_dynamic_deps = []
libraries_to_link = []
for cc_shared_library_info in cc_shared_library_infos:
dynamic_dep_entry = struct(
exports = cc_shared_library_info.exports,
linker_input = cc_shared_library_info.linker_input,
link_once_static_libs = cc_shared_library_info.link_once_static_libs,
)
dynamic_deps.append(dynamic_dep_entry)
transitive_dynamic_deps.append(cc_shared_library_info.dynamic_deps)
libraries_to_link.extend(cc_shared_library_info.linker_input.libraries)
link_once_static_libs.update(pairs = cc_shared_library_info.link_once_static_libs)
exports.extend(cc_shared_library_info.exports)

return CcSharedLibraryInfo(
dynamic_deps = depset(direct = dynamic_deps, transitive = transitive_dynamic_deps, order = "topological"),
exports = exports,
link_once_static_libs = link_once_static_libs,
linker_input = cc_common.create_linker_input(
owner = owner,
libraries = depset(libraries_to_link),
),
)
6 changes: 6 additions & 0 deletions haskell/private/haskell_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ load(
)
load(":private/actions/package.bzl", "package")
load(":private/actions/runghc.bzl", "build_haskell_runghc")
load(":private/cc_libraries.bzl", "merge_cc_shared_library_infos")
load(":private/context.bzl", "haskell_context")
load(":private/dependencies.bzl", "gather_dep_info")
load(":private/expansions.bzl", "haskell_library_expand_make_variables")
Expand Down Expand Up @@ -710,10 +711,15 @@ def haskell_library_impl(ctx):
),
] + [dep[CcInfo] for dep in deps if CcInfo in dep],
)
out_cc_shared_library_info = merge_cc_shared_library_infos(
owner = ctx.label,
cc_shared_library_infos = [dep[CcSharedLibraryInfo] for dep in deps if CcSharedLibraryInfo in dep],
)

return [
hs_info,
out_cc_info,
out_cc_shared_library_info,
coverage_info,
default_info,
lib_info,
Expand Down
2 changes: 2 additions & 0 deletions haskell/private/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ SUPPORTED_BAZEL_VERSIONS = [
"6.0.0",
"6.3.2",
"6.5.0",
"7.1.0",
]

SUPPORTED_NIXPKGS_BAZEL_PACKAGES = [
"bazel_6",
"bazel_7",
]

def _parse_version_chunk(version_chunk):
Expand Down
4 changes: 3 additions & 1 deletion haskell/protobuf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _haskell_proto_aspect_impl(target, ctx):
# TODO this pattern match is very brittle. Let's not do this. The
# order should match the order in the return value expression in
# haskell_library_impl().
[hs_info, cc_info, _coverage_info, default_info, library_info, output_groups] = _haskell_library_impl(patched_ctx)
[hs_info, cc_info, cc_shared_library_info, _coverage_info, default_info, library_info, output_groups] = _haskell_library_impl(patched_ctx)

# Build haddock informations
transitive_html = {}
Expand Down Expand Up @@ -255,11 +255,13 @@ def _haskell_proto_aspect_impl(target, ctx):
for dep in getattr(ctx.rule.attr, attr, [])
]),
cc_info = cc_info,
cc_shared_info = cc_shared_library_info,
is_haskell = True,
)

return [
cc_info, # CcInfo
cc_shared_library_info, # CcSharedLibraryInfo
hs_info, # HaskellInfo
library_info, # HaskellLibraryInfo
# We can't return DefaultInfo here because target already provides that.
Expand Down
31 changes: 29 additions & 2 deletions haskell/repl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ load(
"haskell_cc_libraries_aspect",
"link_libraries",
"merge_HaskellCcLibrariesInfo",
"merge_cc_shared_library_infos",
)
load(":private/context.bzl", "haskell_context", "render_env")
load(":private/expansions.bzl", "expand_make_variables")
Expand Down Expand Up @@ -48,6 +49,7 @@ HaskellReplLoadInfo = provider(
"import_dirs": "Depset of Haskell import directories.",
"cc_libraries_info": "HaskellCcLibrariesInfo of transitive C dependencies.",
"cc_info": "CcInfo of transitive C dependencies.",
"cc_shared_library_infos": "CcSharedLibraryInfo providers of transitive C dependencies.",
"compiler_flags": "Flags to pass to the Haskell compiler.",
"repl_ghci_args": "Arbitrary extra arguments to pass to GHCi. This extends `compiler_flags` and `repl_ghci_args` from the toolchain",
"data_runfiles": "Runtime data dependencies of this target, i.e. the files and runfiles of the `data` attribute.",
Expand All @@ -68,6 +70,7 @@ HaskellReplDepInfo = provider(
"interface_dirs": "Set of interface dirs for all the dependencies",
"cc_libraries_info": "HaskellCcLibrariesInfo of transitive C dependencies.",
"cc_info": "CcInfo of the package itself (includes its transitive dependencies).",
"cc_shared_library_infos": "CcSharedLibraryInfo providers of transitive C dependencies.",
"runfiles": "Runfiles of this target.",
},
)
Expand Down Expand Up @@ -146,6 +149,7 @@ def _merge_HaskellReplLoadInfo(load_infos):
import_dirs = depset()
cc_libraries_infos = []
cc_infos = []
cc_shared_library_infos = []
compiler_flags = []
repl_ghci_args = []
data_runfiles = []
Expand All @@ -158,6 +162,7 @@ def _merge_HaskellReplLoadInfo(load_infos):
import_dirs = depset(transitive = [import_dirs, load_info.import_dirs])
cc_libraries_infos.append(load_info.cc_libraries_info)
cc_infos.append(load_info.cc_info)
cc_shared_library_infos.extend(load_info.cc_shared_library_infos)
compiler_flags += load_info.compiler_flags
repl_ghci_args += load_info.repl_ghci_args
data_runfiles.append(load_info.data_runfiles)
Expand All @@ -171,6 +176,7 @@ def _merge_HaskellReplLoadInfo(load_infos):
import_dirs = import_dirs,
cc_libraries_info = merge_HaskellCcLibrariesInfo(infos = cc_libraries_infos),
cc_info = cc_common.merge_cc_infos(cc_infos = cc_infos),
cc_shared_library_infos = cc_shared_library_infos,
compiler_flags = compiler_flags,
repl_ghci_args = repl_ghci_args,
data_runfiles = _merge_runfiles(data_runfiles),
Expand All @@ -180,11 +186,13 @@ def _merge_HaskellReplLoadInfo(load_infos):
def _merge_HaskellReplLoadInfoMulti(root_info, load_infos):
cc_libraries_infos = []
cc_infos = []
cc_shared_library_infos = []
data_runfiles = []
java_deps = []
for load_info in load_infos:
cc_libraries_infos.append(load_info.cc_libraries_info)
cc_infos.append(load_info.cc_info)
cc_shared_library_infos.extend(load_info.cc_shared_library_infos)
data_runfiles.append(load_info.data_runfiles)
java_deps.append(load_info.java_deps)

Expand All @@ -197,6 +205,7 @@ def _merge_HaskellReplLoadInfoMulti(root_info, load_infos):
import_dirs = root_info.import_dirs,
cc_libraries_info = merge_HaskellCcLibrariesInfo(infos = cc_libraries_infos),
cc_info = cc_common.merge_cc_infos(cc_infos = cc_infos),
cc_shared_library_infos = cc_shared_library_infos,
compiler_flags = root_info.compiler_flags,
repl_ghci_args = root_info.repl_ghci_args,
data_runfiles = _merge_runfiles(data_runfiles),
Expand All @@ -209,6 +218,7 @@ def _merge_HaskellReplDepInfo(dep_infos):
interface_dirs = depset()
cc_libraries_infos = []
cc_infos = []
cc_shared_library_infos = []
runfiles = []

for dep_info in dep_infos:
Expand All @@ -217,6 +227,7 @@ def _merge_HaskellReplDepInfo(dep_infos):
interface_dirs = depset(transitive = [interface_dirs, dep_info.interface_dirs])
cc_libraries_infos.append(dep_info.cc_libraries_info)
cc_infos.append(dep_info.cc_info)
cc_shared_library_infos.extend(dep_info.cc_shared_library_infos)
runfiles.append(dep_info.runfiles)

return HaskellReplDepInfo(
Expand All @@ -226,6 +237,7 @@ def _merge_HaskellReplDepInfo(dep_infos):
interface_dirs = interface_dirs,
cc_libraries_info = merge_HaskellCcLibrariesInfo(infos = cc_libraries_infos),
cc_info = cc_common.merge_cc_infos(cc_infos = cc_infos),
cc_shared_library_infos = cc_shared_library_infos,
runfiles = _merge_runfiles(runfiles),
)

Expand Down Expand Up @@ -257,6 +269,11 @@ def _create_HaskellReplCollectInfo(target, dep_labels, dep_package_ids, dep_pack
for dep in getattr(ctx.rule.attr, "deps", []) + getattr(ctx.rule.attr, "narrowed_deps", [])
if CcInfo in dep and not HaskellInfo in dep
]
ccSharedLibraryInfoDeps = [
dep
for dep in getattr(ctx.rule.attr, "deps", []) + getattr(ctx.rule.attr, "narrowed_deps", [])
if CcSharedLibraryInfo in dep and not HaskellInfo in dep
]
if HaskellLibraryInfo in target:
package_id = target[HaskellLibraryInfo].package_id
load_info = HaskellReplLoadInfo(
Expand All @@ -266,12 +283,19 @@ def _create_HaskellReplCollectInfo(target, dep_labels, dep_package_ids, dep_pack
boot_files = hs_info.boot_files,
module_names = hs_info.module_names,
import_dirs = set.to_depset(hs_info.import_dirs),
cc_libraries_info = deps_HaskellCcLibrariesInfo(ccInfoDeps),
cc_libraries_info = deps_HaskellCcLibrariesInfo(ccInfoDeps + ccSharedLibraryInfoDeps),
cc_info = cc_common.merge_cc_infos(cc_infos = [
# Collect pure C library dependencies, no Haskell dependencies.
dep[CcInfo]
for dep in ccInfoDeps
]),
cc_shared_library_infos = [merge_cc_shared_library_infos(
owner = ctx.label,
cc_shared_library_infos = [
dep[CcSharedLibraryInfo]
for dep in ccSharedLibraryInfoDeps
],
)],
compiler_flags = hs_info.user_compile_flags,
repl_ghci_args = hs_info.user_repl_flags,
data_runfiles = _data_runfiles(ctx, ctx.rule, "data"),
Expand All @@ -287,6 +311,7 @@ def _create_HaskellReplCollectInfo(target, dep_labels, dep_package_ids, dep_pack
interface_dirs = hs_info.interface_dirs,
cc_libraries_info = target[HaskellCcLibrariesInfo],
cc_info = target[CcInfo],
cc_shared_library_infos = [target[CcSharedLibraryInfo]] if CcSharedLibraryInfo in target else [],
runfiles = target[DefaultInfo].default_runfiles,
)
dep_infos[target.label] = dep_info
Expand Down Expand Up @@ -484,7 +509,9 @@ def _compiler_flags_and_inputs(hs, cc, repl_info, get_dirname, static = False, i
repl_info.load_info.cc_info,
repl_info.dep_info.cc_info,
])
all_libraries = [lib for li in cc_info.linking_context.linker_inputs.to_list() for lib in li.libraries]
cc_shared_library_infos = repl_info.load_info.cc_shared_library_infos + repl_info.dep_info.cc_shared_library_infos
linker_inputs = cc_info.linking_context.linker_inputs.to_list() + [info.linker_input for info in cc_shared_library_infos]
all_libraries = [lib for li in linker_inputs for lib in li.libraries]
cc_libraries = get_cc_libraries(cc_libraries_info, all_libraries)
if static:
cc_library_files = _concat(get_library_files(hs, cc_libraries_info, cc_libraries))
Expand Down
Loading
Loading