Skip to content

Commit 7687765

Browse files
authored
Merge pull request #1351 from tweag/cabal-dylib-symlink
Shorter dynamic library symlinks underneath _solib_<cpu> for stack_snapshot
2 parents 1726f67 + 10a4dac commit 7687765

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

haskell/cabal.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ def _gather_transitive_haddocks(deps):
277277
direct = transitive_haddocks_list,
278278
)
279279

280+
def _shorten_library_symlink(dynamic_library):
281+
prefix = dynamic_library.owner.workspace_root.replace("_", "_U").replace("/", "_S")
282+
basename = dynamic_library.basename
283+
return paths.join(prefix, basename)
284+
280285
def _haskell_cabal_library_impl(ctx):
281286
hs = haskell_context(ctx)
282287
dep_info = gather_dep_info(ctx, ctx.attr.deps)
@@ -446,6 +451,8 @@ def _haskell_cabal_library_impl(ctx):
446451
actions = ctx.actions,
447452
feature_configuration = feature_configuration,
448453
dynamic_library = dynamic_library,
454+
dynamic_library_symlink_path =
455+
_shorten_library_symlink(dynamic_library) if dynamic_library and ctx.attr.unique_name else "",
449456
static_library = static_library,
450457
cc_toolchain = cc_toolchain,
451458
)
@@ -520,6 +527,14 @@ haskell_cabal_library = rule(
520527
default = True,
521528
doc = "Whether to show the output of the build",
522529
),
530+
"unique_name": attr.bool(
531+
default = False,
532+
doc = """Whether the library name is known to be unique within the
533+
workspace. This is used by `stack_snapshot` where library names are
534+
known to be unique within the snapshot. If true, then the dynamic
535+
library symlink underneath `_solib_<cpu>` will be shortened to
536+
avoid exceeding the MACH-O header size limit on MacOS.""",
537+
),
523538
},
524539
toolchains = [
525540
"@bazel_tools//tools/cpp:toolchain_type",
@@ -1075,6 +1090,7 @@ haskell_cabal_library(
10751090
visibility = {visibility},
10761091
compiler_flags = ["-w", "-optF=-w"],
10771092
verbose = {verbose},
1093+
unique_name = True,
10781094
)
10791095
""".format(
10801096
name = package.name,

0 commit comments

Comments
 (0)