1
- let
2
- pkgs = import <nixpkgs> { config = { } ; overlays = [ ] ; } ;
3
- in
4
-
5
1
{ ccType
6
2
, ccAttrPath ? null
7
3
, ccAttrSet ? null
8
4
, ccExpr ? null
5
+ , ccPkgs ? import <nixpkgs> { config = { } ; overlays = [ ] ; }
9
6
, ccLang ? "c++"
10
7
} :
11
8
12
9
let
10
+ pkgs = ccPkgs . buildPackages ;
11
+ stdenv = ccPkgs . stdenv ;
13
12
# The original `postLinkSignHook` from nixpkgs assumes `codesign_allocate` is
14
13
# in the PATH which is not the case when using our cc_wrapper. Set
15
14
# `CODESIGN_ALLOCATE` to an absolute path here and override the hook for
28
27
# Work around https://github.com/NixOS/nixpkgs/issues/42059.
29
28
# See also https://github.com/NixOS/nixpkgs/pull/41589.
30
29
pkgs . wrapCCWith rec {
31
- cc = pkgs . stdenv . cc . cc ;
32
- bintools = pkgs . stdenv . cc . bintools . override { inherit postLinkSignHook ; } ;
30
+ cc = stdenv . cc . cc ;
31
+ bintools = stdenv . cc . bintools . override { inherit postLinkSignHook ; } ;
33
32
extraBuildCommands = with pkgs . darwin . apple_sdk . frameworks ; ''
34
33
echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
35
34
echo "-Wno-elaborated-enum-base" >> $out/nix-support/cc-cflags
54
53
else
55
54
pkgs . buildEnv (
56
55
let
57
- cc = if pkgs . stdenv . isDarwin then darwinCC else pkgs . stdenv . cc ;
56
+ cc = if stdenv . isDarwin then darwinCC else stdenv . cc ;
58
57
in
59
58
{
60
- name = "bazel-nixpkgs-cc " ;
59
+ name = "bazel-${ cc . name } -wrapper " ;
61
60
# XXX: `gcov` is missing in `/bin`.
62
61
# It exists in `stdenv.cc.cc` but that collides with `stdenv.cc`.
63
62
paths = [ cc cc . bintools ] ++ pkgs . lib . optional pkgs . stdenv . isDarwin pkgs . darwin . cctools ;
64
63
pathsToLink = [ "/bin" ] ;
65
64
passthru = {
66
- isClang = cc . isClang ;
65
+ inherit ( cc ) isClang targetPrefix ;
66
+ orignalName = cc . name ;
67
67
} ;
68
68
}
69
69
)
70
70
;
71
71
in
72
- pkgs . runCommand "bazel-nixpkgs-cc -toolchain"
72
+ pkgs . runCommand "bazel-${ cc . orignalName or cc . name } -toolchain"
73
73
{
74
74
executable = false ;
75
75
# Pointless to do this on a remote machine.
@@ -89,10 +89,14 @@ pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
89
89
TOOL_NAMES=('' ${!TOOLS[@]})
90
90
declare -A TOOL_PATHS=()
91
91
for tool_name in '' ${!TOOLS[@]}; do
92
- tool_path=${ cc } /bin/'' ${TOOLS[$tool_name]}
92
+ tool_path=${ cc } /bin/${ cc . targetPrefix } '' ${TOOLS[$tool_name]}
93
93
if [[ -x $tool_path ]]; then
94
94
TOOL_PATHS[$tool_name]=$tool_path
95
95
else
96
+ if [[ $tool_name == gcc ]]; then
97
+ echo "Failed to find ${ cc . targetPrefix } '' ${TOOLS[gcc]} in ${ cc } /bin" >&2
98
+ exit 1
99
+ fi
96
100
TOOL_PATHS[$tool_name]=${ pkgs . coreutils } /bin/false
97
101
fi
98
102
done
@@ -188,7 +192,7 @@ pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
188
192
add_linker_option_if_supported -Wl,-z,relro,-z,now -z
189
193
)
190
194
${
191
- if pkgs . stdenv . isDarwin
195
+ if stdenv . isDarwin
192
196
then "-undefined dynamic_lookup -headerpad_max_install_names"
193
197
else "-B${ cc } /bin"
194
198
}
@@ -199,11 +203,11 @@ pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
199
203
)
200
204
LINK_LIBS=(
201
205
${
202
- # Use pkgs. stdenv.isDarwin as a marker instead of cc.isClang because
206
+ # Use stdenv.isDarwin as a marker instead of cc.isClang because
203
207
# we might have usecases with stdenv with clang and libstdc++.
204
208
# On Darwin libstdc++ is not available, so it's safe to assume that
205
209
# everybody use libc++ from LLVM.
206
- if pkgs . stdenv . isDarwin then "-lc++" else "-lstdc++"
210
+ if stdenv . isDarwin then "-lc++" else "-lstdc++"
207
211
}
208
212
-lm
209
213
)
@@ -233,7 +237,7 @@ pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
233
237
)
234
238
OPT_LINK_FLAGS=(
235
239
${
236
- if pkgs . stdenv . isDarwin
240
+ if stdenv . isDarwin
237
241
then ""
238
242
else "$(add_linker_option_if_supported -Wl,--gc-sections -gc-sections)"
239
243
}
@@ -256,15 +260,15 @@ pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
256
260
DBG_COMPILE_FLAGS=(-g)
257
261
COVERAGE_COMPILE_FLAGS=(
258
262
${
259
- if pkgs . stdenv . isDarwin then
263
+ if stdenv . isDarwin then
260
264
"-fprofile-instr-generate -fcoverage-mapping"
261
265
else
262
266
"--coverage"
263
267
}
264
268
)
265
269
COVERAGE_LINK_FLAGS=(
266
270
${
267
- if pkgs . stdenv . isDarwin then
271
+ if stdenv . isDarwin then
268
272
"-fprofile-instr-generate"
269
273
else
270
274
"--coverage"
0 commit comments