Skip to content

Commit

Permalink
Use default clang CC
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Nov 4, 2024
1 parent 3a49884 commit fe115dc
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions examples/toolchains/cc_cross_osx_to_linux_amd64/toolchains/cc.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# We need to write a fancy nix file to handle the CC compiler due to OSX: https://github.com/tweag/rules_nixpkgs/issues/368
# What this file is basically saying is: if OSX, change the CXX compiler to use a bunch of Apple frameworks, LLVM libs,
# libc++ instead of libstdc++, and some additional compiler flags to ignore some warnings, otherwise, just use clang11
# libc++ instead of libstdc++, and some additional compiler flags to ignore some warnings, otherwise, just use clang
let
pkgs = import <nixpkgs> {};
in let
clang = pkgs.clang_11;
pkgs = import <nixpkgs> { };
in
let
inherit (pkgs) clang;

# 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
Expand All @@ -24,18 +26,18 @@ in let
# See also https://github.com/NixOS/nixpkgs/pull/41589.
pkgs.wrapCCWith rec {
cc = clang;
bintools = pkgs.stdenv.cc.bintools.override {inherit postLinkSignHook;};
bintools = pkgs.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_11.libcxx.dev}/include/c++/v1" >> $out/nix-support/cc-cflags
echo "-isystem ${pkgs.llvmPackages_11.clang-unwrapped.lib}/lib/clang/${cc.version}/include" >> $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 "-L${pkgs.llvmPackages_11.libcxx}/lib" >> $out/nix-support/cc-cflags
echo "-L${pkgs.llvmPackages_11.libcxxabi}/lib" >> $out/nix-support/cc-cflags
echo "-L${pkgs.llvmPackages.libcxx}/lib" >> $out/nix-support/cc-cflags
echo "-L${pkgs.llvmPackages.libcxxabi}/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
Expand All @@ -44,29 +46,30 @@ in let
linuxCC = pkgs.wrapCCWith rec {
cc = clang;
bintools = pkgs.stdenv.cc.bintools;
extraPackages = [pkgs.glibc.static];
extraPackages = [ pkgs.glibc.static ];
extraBuildCommands = ''
echo "-isystem ${pkgs.llvmPackages_11.clang-unwrapped.lib}/lib/clang/${cc.version}/include" >> $out/nix-support/cc-cflags
echo "-isystem ${pkgs.llvmPackages.clang-unwrapped.lib}/lib/clang/${cc.version}/include" >> $out/nix-support/cc-cflags
echo "-L ${pkgs.glibc.static}/lib" >> $out/nix-support/cc-ldflags
echo "-resource-dir=${cc}/resource-root" >> $out/nix-support/cc-cflags
'';
};
in
pkgs.buildEnv (
let
cc =
if pkgs.stdenv.isDarwin
then darwinCC
else linuxCC;
in {
name = "bazel-nixpkgs-cc";
# 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.cctools;
pathsToLink = ["/bin"];
passthru = {
inherit (cc) isClang targetPrefix;
orignalName = cc.name;
};
}
)
pkgs.buildEnv (
let
cc =
if pkgs.stdenv.isDarwin
then darwinCC
else linuxCC;
in
{
name = "bazel-nixpkgs-cc";
# 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.cctools;
pathsToLink = [ "/bin" ];
passthru = {
inherit (cc) isClang targetPrefix;
orignalName = cc.name;
};
}
)

0 comments on commit fe115dc

Please sign in to comment.