Skip to content

Commit c6c8dcc

Browse files
committed
Do not depend on system tools on Darwin
Our cc wrapper was always using the system tools from a fixed location on Darwin, which is not hermetic (and can lead to problems when using nixpkgs) and requires the Xcode command line tools to be installed. Apply the same heuristic as for the otool and install_name tool for the haskell toolchain and assume the tools are available at the same location as the `ar` binary.
1 parent 18577ae commit c6c8dcc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

haskell/private/cc_wrapper.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//lib:paths.bzl", "paths")
12
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
23
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
34
load("@rules_python//python:defs.bzl", "py_binary")
@@ -46,6 +47,10 @@ def _cc_wrapper_impl(ctx):
4647
feature_configuration = feature_configuration,
4748
action_name = ACTION_NAMES.c_compile,
4849
)
50+
ar = cc_common.get_tool_for_action(
51+
feature_configuration = feature_configuration,
52+
action_name = ACTION_NAMES.cpp_link_static_library,
53+
)
4954
cc_wrapper = ctx.actions.declare_file(ctx.label.name)
5055
ctx.actions.expand_template(
5156
template = ctx.file.template,
@@ -56,6 +61,7 @@ def _cc_wrapper_impl(ctx):
5661
"{:cpu:}": cc_toolchain.cpu,
5762
"{:workspace:}": ctx.workspace_name,
5863
"{:platform:}": ctx.attr.platform,
64+
"{:bindir:}": paths.dirname(ar),
5965
},
6066
)
6167
return [DefaultInfo(

haskell/private/cc_wrapper.py.tpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ WORKSPACE = "{:workspace:}"
8383
CC = os.environ.get("CC_WRAPPER_CC_PATH", "{:cc:}")
8484
PLATFORM = os.environ.get("CC_WRAPPER_PLATFORM", "{:platform:}")
8585
CPU = os.environ.get("CC_WRAPPER_CPU", "{:cpu:}")
86-
INSTALL_NAME_TOOL = "/usr/bin/install_name_tool"
87-
CODESIGN = "/usr/bin/codesign"
88-
OTOOL = "/usr/bin/otool"
86+
INSTALL_NAME_TOOL = "{:bindir:}/install_name_tool"
87+
CODESIGN = "{:bindir:}/codesign"
88+
CODESIGN_ALLOCATE = "{:bindir:}/codesign_allocate"
89+
OTOOL = "{:bindir:}/otool"
8990

9091

9192
def main():
@@ -935,7 +936,7 @@ def darwin_rewrite_load_commands(rewrites, output):
935936
# See this note from nixpkgs for reference:
936937
# https://github.com/NixOS/nixpkgs/blob/5855ff74f511423e3e2646248598b3ffff229223/pkgs/os-specific/darwin/signing-utils/utils.sh#L1-L6
937938
os.rename(output, f"{output}.resign")
938-
subprocess.check_call([CODESIGN] + ["-f", "-s", "-"] + [f"{output}.resign"])
939+
subprocess.check_call([CODESIGN] + ["-f", "-s", "-"] + [f"{output}.resign"], env = {'CODESIGN_ALLOCATE': CODESIGN_ALLOCATE})
939940
os.rename(f"{output}.resign", output)
940941

941942

0 commit comments

Comments
 (0)