diff --git a/toolchains/cc/cc.nix b/toolchains/cc/cc.nix index b1c348d0..897dc2b6 100644 --- a/toolchains/cc/cc.nix +++ b/toolchains/cc/cc.nix @@ -29,7 +29,35 @@ let ${darwin.sigtool}/bin/codesign -f -s - "$linkerOutput" ''; }; - darwinCC = + oldDarwinCC = + # 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 + ''; + }; + # for nixpkgs 24.11 and later + newDarwinCC = # Work around https://github.com/NixOS/nixpkgs/issues/42059. # See also https://github.com/NixOS/nixpkgs/pull/41589. pkgs.wrapCCWith rec { @@ -65,7 +93,12 @@ let pkgs.buildEnv ( let cc = - if stdenv.isDarwin && pkgs.lib.versionOlder pkgs.lib.version "24.11" then darwinCC else stdenv.cc; + if !stdenv.isDarwin then + stdenv.cc + else if pkgs.lib.versionOlder pkgs.lib.version "24.11" then + oldDarwinCC + else + newDarwinCC; in { name = "bazel-${cc.name}-wrapper";