Skip to content

Commit

Permalink
Add mold integration (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored Nov 7, 2022
1 parent adb43e4 commit 39de4d1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# TODO: Remove once mold supports -S
build --strip=never

test --test_output=errors
7 changes: 6 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_apple_linker//:rules.bzl", "lld_override", "zld_override")
load("@rules_apple_linker//:rules.bzl", "lld_override", "mold_override", "zld_override")

zld_override(
name = "zld",
Expand All @@ -9,3 +9,8 @@ lld_override(
name = "lld",
visibility = ["//visibility:public"],
)

mold_override(
name = "mold",
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ def rules_apple_linker_deps():
sha256 = "28566b943082349269b6460a5c23a305a73460bac54f5cd21eb490ff7d84fed7",
url = "https://github.com/keith/ld64.lld/releases/download/10-14-22/ld64.tar.xz",
)

http_archive(
name = "rules_apple_linker_mold",
build_file_content = 'filegroup(name = "mold_bin", srcs = ["ld64.mold"], visibility = ["//visibility:public"])',
sha256 = "2b1ab27d4ab0d6319cf79b6bc94710e8a515c069670191dea022c3dffaef64fd",
url = "https://github.com/keith/ld64.mold/releases/download/11-7-22/ld64.tar.xz",
)
17 changes: 17 additions & 0 deletions rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,20 @@ lld_override = rule(
),
provides = [apple_common.Objc, CcInfo],
)

def _mold_override(ctx):
return _linker_override(ctx, ctx.attr.mold_linkopts)

mold_override = rule(
implementation = _mold_override,
attrs = _attrs(
"@rules_apple_linker_mold//:mold_bin",
{
"mold_linkopts": attr.string_list(
mandatory = False,
doc = "The options to pass to mold, and not ld64 (see enable)",
),
},
),
provides = [apple_common.Objc, CcInfo],
)
17 changes: 17 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ cc_test(
deps = ["@rules_apple_linker//:zld"],
)

cc_test(
name = "mold_test",
srcs = ["main.c"],
features = [
"-dynamic_linking_mode", # TODO: https://github.com/bazelbuild/bazel/pull/16414
],
deps = ["@rules_apple_linker//:mold"],
)

cc_library(
name = "binary_lib",
srcs = ["main.c"],
Expand Down Expand Up @@ -158,7 +167,15 @@ action_command_line_test(
mnemonics = ["CppLink"],
not_expected_argv = [
"--ld-path=external/rules_apple_linker_lld/ld64.lld",
"--ld-path=external/rules_apple_linker_mold/ld64.mold",
"--ld-path=external/rules_apple_linker_zld/zld",
],
target_under_test = ":default_test",
)

action_command_line_test(
name = "use_mold_test",
expected_argv = ["--ld-path=external/rules_apple_linker_mold/ld64.mold"],
mnemonics = ["CppLink"],
target_under_test = ":mold_test",
)

0 comments on commit 39de4d1

Please sign in to comment.