From cec3a259c0c1d120de4c23cf9d9970fbff5b3507 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Tue, 7 Jan 2025 18:08:18 +0100 Subject: [PATCH] Add patch to rules_nixpkgs_cc to remove postLinkSignHook See https://github.com/flurie/rules_nixpkgs/commit/9e5f2aefe6c82d35f6d02e0c721bfb88c2133a5e --- .../0.12.0/patches/postLinkSignHook.patch | 180 ++++++++++++++++++ .../rules_nixpkgs_cc/0.12.0/source.json | 3 +- 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 registry/modules/rules_nixpkgs_cc/0.12.0/patches/postLinkSignHook.patch diff --git a/registry/modules/rules_nixpkgs_cc/0.12.0/patches/postLinkSignHook.patch b/registry/modules/rules_nixpkgs_cc/0.12.0/patches/postLinkSignHook.patch new file mode 100644 index 0000000..76453c8 --- /dev/null +++ b/registry/modules/rules_nixpkgs_cc/0.12.0/patches/postLinkSignHook.patch @@ -0,0 +1,180 @@ +diff --git a/toolchains/cc/cc.nix b/toolchains/cc/cc.nix +index f66a8c0b..3312785c 100644 +--- a/toolchains/cc/cc.nix ++++ b/toolchains/cc/cc.nix +@@ -1,52 +1,44 @@ +-{ ccType +-, ccAttrPath ? null +-, ccAttrSet ? null +-, ccExpr ? null +-, ccPkgs ? import { config = { }; overlays = [ ]; } +-, ccLang ? "c++" +-, ccStd ? "c++0x" ++{ ++ ccType, ++ ccAttrPath ? null, ++ ccAttrSet ? null, ++ ccExpr ? null, ++ ccPkgs ? import { ++ config = { }; ++ overlays = [ ]; ++ }, ++ ccLang ? "c++", ++ ccStd ? "c++0x", + }: + + let + pkgs = ccPkgs.buildPackages; + stdenv = ccPkgs.stdenv; +- # The original `postLinkSignHook` from nixpkgs assumes `codesign_allocate` is +- # in the PATH which is not the case when using our cc_wrapper. Set +- # `CODESIGN_ALLOCATE` to an absolute path here and override the hook for +- # `darwinCC` below. +- postLinkSignHook = +- with pkgs; writeTextFile { +- name = "post-link-sign-hook"; +- executable = true; +- +- text = '' +- CODESIGN_ALLOCATE=${darwin.cctools}/bin/codesign_allocate \ +- ${darwin.sigtool}/bin/codesign -f -s - "$linkerOutput" +- ''; +- }; + darwinCC = + # Work around https://github.com/NixOS/nixpkgs/issues/42059. + # See also https://github.com/NixOS/nixpkgs/pull/41589. + pkgs.wrapCCWith rec { + cc = stdenv.cc.cc; +- bintools = stdenv.cc.bintools.override { inherit postLinkSignHook; }; +- extraBuildCommands = with pkgs.darwin.apple_sdk.frameworks; '' +- echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags +- echo "-Wno-elaborated-enum-base" >> $out/nix-support/cc-cflags +- echo "-isystem ${pkgs.llvmPackages.libcxx.dev}/include/c++/v1" >> $out/nix-support/cc-cflags +- echo "-isystem ${pkgs.llvmPackages.clang-unwrapped.lib}/lib/clang/${cc.version}/include" >> $out/nix-support/cc-cflags +- echo "-F${CoreFoundation}/Library/Frameworks" >> $out/nix-support/cc-cflags +- echo "-F${CoreServices}/Library/Frameworks" >> $out/nix-support/cc-cflags +- echo "-F${Security}/Library/Frameworks" >> $out/nix-support/cc-cflags +- echo "-F${Foundation}/Library/Frameworks" >> $out/nix-support/cc-cflags +- echo "-F${SystemConfiguration}/Library/Frameworks" >> $out/nix-support/cc-cflags +- echo "-L${pkgs.llvmPackages.libcxx}/lib" >> $out/nix-support/cc-cflags +- echo "-L${pkgs.libiconv}/lib" >> $out/nix-support/cc-cflags +- echo "-L${pkgs.darwin.libobjc}/lib" >> $out/nix-support/cc-cflags +- echo "-resource-dir=${pkgs.stdenv.cc}/resource-root" >> $out/nix-support/cc-cflags +- '' + pkgs.lib.optionalString (builtins.hasAttr "libcxxabi" pkgs.llvmPackages) '' +- echo "-L${pkgs.llvmPackages.libcxxabi}/lib" >> $out/nix-support/cc-cflags +- ''; ++ extraBuildCommands = ++ with pkgs.darwin.apple_sdk.frameworks; ++ '' ++ echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags ++ echo "-Wno-elaborated-enum-base" >> $out/nix-support/cc-cflags ++ echo "-isystem ${pkgs.llvmPackages.libcxx.dev}/include/c++/v1" >> $out/nix-support/cc-cflags ++ echo "-isystem ${pkgs.llvmPackages.clang-unwrapped.lib}/lib/clang/${cc.version}/include" >> $out/nix-support/cc-cflags ++ echo "-F${CoreFoundation}/Library/Frameworks" >> $out/nix-support/cc-cflags ++ echo "-F${CoreServices}/Library/Frameworks" >> $out/nix-support/cc-cflags ++ echo "-F${Security}/Library/Frameworks" >> $out/nix-support/cc-cflags ++ echo "-F${Foundation}/Library/Frameworks" >> $out/nix-support/cc-cflags ++ echo "-F${SystemConfiguration}/Library/Frameworks" >> $out/nix-support/cc-cflags ++ echo "-L${pkgs.llvmPackages.libcxx}/lib" >> $out/nix-support/cc-cflags ++ echo "-L${pkgs.libiconv}/lib" >> $out/nix-support/cc-cflags ++ echo "-L${pkgs.darwin.libobjc}/lib" >> $out/nix-support/cc-cflags ++ echo "-resource-dir=${pkgs.stdenv.cc}/resource-root" >> $out/nix-support/cc-cflags ++ '' ++ + pkgs.lib.optionalString (builtins.hasAttr "libcxxabi" pkgs.llvmPackages) '' ++ echo "-L${pkgs.llvmPackages.libcxxabi}/lib" >> $out/nix-support/cc-cflags ++ ''; + }; + cc = + if ccType == "ccTypeAttribute" then +@@ -62,13 +54,17 @@ let + name = "bazel-${cc.name}-wrapper"; + # XXX: `gcov` is missing in `/bin`. + # It exists in `stdenv.cc.cc` but that collides with `stdenv.cc`. +- paths = [ cc cc.bintools ] ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.sigtool; ++ paths = [ ++ cc ++ cc.bintools ++ ] ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.sigtool; + pathsToLink = [ "/bin" ]; + passthru = { + inherit (cc) isClang targetPrefix; + orignalName = cc.name; + }; +- } // (pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { ++ } ++ // (pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { + # only add tools from darwin.cctools, but don't overwrite existing tools + postBuild = '' + for tool in libtool objdump; do +@@ -77,18 +73,16 @@ let + fi + done + ''; +- } +- ) +- ) +- ; ++ }) ++ ); + in + pkgs.runCommand "bazel-${cc.orignalName or cc.name}-toolchain" +-{ +- executable = false; +- # Pointless to do this on a remote machine. +- preferLocalBuild = true; +- allowSubstitutes = false; +-} ++ { ++ executable = false; ++ # Pointless to do this on a remote machine. ++ preferLocalBuild = true; ++ allowSubstitutes = false; ++ } + '' + # This constructs the substitutions for + # `@bazel_tools//tools/cpp:BUILD.tpl` following the example of +@@ -211,9 +205,7 @@ pkgs.runCommand "bazel-${cc.orignalName or cc.name}-toolchain" + add_linker_option_if_supported -Wl,-z,relro,-z,now -z + ) + ${ +- if stdenv.isDarwin +- then "-undefined dynamic_lookup -headerpad_max_install_names" +- else "-B${cc}/bin" ++ if stdenv.isDarwin then "-undefined dynamic_lookup -headerpad_max_install_names" else "-B${cc}/bin" + } + $( + # Have gcc return the exit code from ld. +@@ -256,9 +248,7 @@ pkgs.runCommand "bazel-${cc.orignalName or cc.name}-toolchain" + ) + OPT_LINK_FLAGS=( + ${ +- if stdenv.isDarwin +- then "" +- else "$(add_linker_option_if_supported -Wl,--gc-sections -gc-sections)" ++ if stdenv.isDarwin then "" else "$(add_linker_option_if_supported -Wl,--gc-sections -gc-sections)" + } + ) + UNFILTERED_COMPILE_FLAGS=( +@@ -278,20 +268,10 @@ pkgs.runCommand "bazel-${cc.orignalName or cc.name}-toolchain" + ) + DBG_COMPILE_FLAGS=(-g) + COVERAGE_COMPILE_FLAGS=( +- ${ +- if stdenv.isDarwin then +- "-fprofile-instr-generate -fcoverage-mapping" +- else +- "--coverage" +- } ++ ${if stdenv.isDarwin then "-fprofile-instr-generate -fcoverage-mapping" else "--coverage"} + ) + COVERAGE_LINK_FLAGS=( +- ${ +- if stdenv.isDarwin then +- "-fprofile-instr-generate" +- else +- "--coverage" +- } ++ ${if stdenv.isDarwin then "-fprofile-instr-generate" else "--coverage"} + ) + SUPPORTS_START_END_LIB=( + $( diff --git a/registry/modules/rules_nixpkgs_cc/0.12.0/source.json b/registry/modules/rules_nixpkgs_cc/0.12.0/source.json index 362b2c9..2c80a46 100644 --- a/registry/modules/rules_nixpkgs_cc/0.12.0/source.json +++ b/registry/modules/rules_nixpkgs_cc/0.12.0/source.json @@ -4,6 +4,7 @@ "url": "https://github.com/tweag/rules_nixpkgs/releases/download/v0.12.0/rules_nixpkgs-0.12.0.tar.gz", "patch_strip": 3, "patches": { - "extra_flags_per_feature.patch": "sha256-576dBOkky5p+LmRvl9uF+SOZ09Wzu0md7LETX8Oi0CI=" + "extra_flags_per_feature.patch": "sha256-576dBOkky5p+LmRvl9uF+SOZ09Wzu0md7LETX8Oi0CI=", + "postLinkSignHook.patch": "sha256-IHlLw3z0xklLUU3ZwSLyzi2zR8LvITTxQQGKz5k7D3k=" } }