Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Remove deprecated darwin toolchain stuff #632

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 26 additions & 13 deletions nix/flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
Expand All @@ -11,21 +11,34 @@
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{ nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells.default = with pkgs; mkShell {
# do not use Xcode on macOS
BAZEL_USE_CPP_ONLY_TOOLCHAIN = "1";
# for nixpkgs cc wrappers, select C++ explicitly (see https://github.com/NixOS/nixpkgs/issues/150655)
BAZEL_CXXOPTS = "-x:c++";
devShells.default =
with pkgs;
mkShell {
# do not use Xcode on macOS
BAZEL_USE_CPP_ONLY_TOOLCHAIN = "1";
# for nixpkgs cc wrappers, select C++ explicitly (see https://github.com/NixOS/nixpkgs/issues/150655)
BAZEL_CXXOPTS = "-x:c++";

name = "rules_nixpkgs_shell";
buildInputs = lib.optional pkgs.stdenv.isDarwin darwin.cctools;
packages = [ bazel_6 bazel-buildtools cacert gcc nix git openssh ];
};
});
name = "rules_nixpkgs_shell";
buildInputs = lib.optional pkgs.stdenv.isDarwin darwin.cctools;
packages = [
bazel_6
bazel-buildtools
cacert
gcc
nix
git
openssh
];
};
}
);
}
144 changes: 87 additions & 57 deletions toolchains/cc/cc.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{ ccType
, ccAttrPath ? null
, ccAttrSet ? null
, ccExpr ? null
, ccPkgs ? import <nixpkgs> { config = { }; overlays = [ ]; }
, ccLang ? "c++"
, ccStd ? "c++0x"
{
ccType,
ccAttrPath ? null,
ccAttrSet ? null,
ccExpr ? null,
ccPkgs ? import <nixpkgs> {
config = { };
overlays = [ ];
},
ccLang ? "c++",
ccStd ? "c++0x",
}:

let
Expand All @@ -15,7 +19,8 @@ let
# `CODESIGN_ALLOCATE` to an absolute path here and override the hook for
# `darwinCC` below.
postLinkSignHook =
with pkgs; writeTextFile {
with pkgs;
writeTextFile {
name = "post-link-sign-hook";
executable = true;

Expand All @@ -24,29 +29,60 @@ 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
'';
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 {
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
'';
};
cc =
if ccType == "ccTypeAttribute" then
Expand All @@ -56,19 +92,29 @@ let
else
pkgs.buildEnv (
let
cc = if stdenv.isDarwin then darwinCC else stdenv.cc;
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";
# 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
Expand All @@ -77,18 +123,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
Expand Down Expand Up @@ -211,9 +255,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.
Expand Down Expand Up @@ -256,9 +298,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=(
Expand All @@ -278,20 +318,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=(
$(
Expand Down
Loading