@@ -83,9 +83,10 @@ WORKSPACE = "{:workspace:}"
8383CC = os .environ .get ("CC_WRAPPER_CC_PATH" , "{:cc:}" )
8484PLATFORM = os .environ .get ("CC_WRAPPER_PLATFORM" , "{:platform:}" )
8585CPU = 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
9192def main ():
@@ -930,12 +931,18 @@ def darwin_rewrite_load_commands(rewrites, output):
930931 if args :
931932 subprocess .check_call ([INSTALL_NAME_TOOL ] + args + [output ])
932933 # Resign the binary after patching it.
934+ # Fall back to /usr/bin/codesign if the `CODESIGN` executable is not available
935+ # (this might happen when using a default cc toolchain from a nix shell on Darwin instead
936+ # of using a nixpkgs_cc_configure'd toolchain).
937+ # Do the same for codesign_allocate.
938+ codesign = CODESIGN if os .access (CODESIGN , os .X_OK ) else "/usr/bin/codesign"
939+ codesign_allocate = CODESIGN_ALLOCATE if os .access (CODESIGN_ALLOCATE , os .X_OK ) else "/usr/bin/codesign_allocate"
933940 # This is necessary on MacOS Monterey on M1.
934941 # The moving back and forth is necessary because the OS caches the signature.
935942 # See this note from nixpkgs for reference:
936943 # https://github.com/NixOS/nixpkgs/blob/5855ff74f511423e3e2646248598b3ffff229223/pkgs/os-specific/darwin/signing-utils/utils.sh#L1-L6
937944 os .rename (output , f"{ output } .resign" )
938- subprocess .check_call ([CODESIGN ] + ["-f" , "-s" , "-" ] + [f"{ output } .resign" ])
945+ subprocess .check_call ([codesign ] + ["-f" , "-s" , "-" ] + [f"{ output } .resign" ], env = { 'CODESIGN_ALLOCATE' : codesign_allocate } )
939946 os .rename (f"{ output } .resign" , output )
940947
941948
0 commit comments