cc-wrapper: Allow for override of -target for clang/clang++

This enables users to make use of clang's multi-platform/target support
without having to go through full cross system setup. This is especially useful
for generating bpf object files, I'm not even usre what would a no-userland
cross compile system tuple even look like to even try going that route.

Fixes #176128
This commit is contained in:
Manuel Mendez 2022-06-03 17:00:10 -04:00
parent e91b5670e3
commit 19b6ccd9ac
2 changed files with 11 additions and 8 deletions

View File

@ -29,6 +29,7 @@ cc1=0
cxxInclude=1
cxxLibrary=1
cInclude=1
needsTarget=@needsTarget@
expandResponseParams "$@"
linkType=$(checkLinkType "${params[@]}")
@ -46,6 +47,7 @@ while (( "$n" < "$nParams" )); do
-nostdinc) cInclude=0 cxxInclude=0 ;;
-nostdinc++) cxxInclude=0 ;;
-nostdlib) cxxLibrary=0 ;;
-target|--target=*) needsTarget=0;;
-x)
case "$p2" in
*-header) dontLink=1 ;;
@ -159,6 +161,10 @@ if [ "$dontLink" != 1 ]; then
export NIX_LINK_TYPE_@suffixSalt@=$linkType
fi
if [ $needsTarget == 1 ]; then
extraAfter+=(-target @defaultTarget@)
fi
# As a very special hack, if the arguments are just `-v', then don't
# add anything. This is to prevent `gcc -v' (which normally prints
# out the version number and returns exit code 0) from printing out

View File

@ -208,6 +208,7 @@ stdenv.mkDerivation {
+ ''
export named_cc=${targetPrefix}cc
export named_cxx=${targetPrefix}c++
export needsTarget=0
if [ -e $ccPath/${targetPrefix}gcc ]; then
wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc
@ -215,6 +216,8 @@ stdenv.mkDerivation {
export named_cc=${targetPrefix}gcc
export named_cxx=${targetPrefix}g++
elif [ -e $ccPath/clang ]; then
needsTarget=1
export defaultTarget=${targetPlatform.config}
wrap ${targetPrefix}clang $wrapper $ccPath/clang
ln -s ${targetPrefix}clang $out/bin/${targetPrefix}cc
export named_cc=${targetPrefix}clang
@ -225,6 +228,8 @@ stdenv.mkDerivation {
wrap ${targetPrefix}g++ $wrapper $ccPath/${targetPrefix}g++
ln -s ${targetPrefix}g++ $out/bin/${targetPrefix}c++
elif [ -e $ccPath/clang++ ]; then
needsTarget=1
export defaultTarget=${targetPlatform.config}
wrap ${targetPrefix}clang++ $wrapper $ccPath/clang++
ln -s ${targetPrefix}clang++ $out/bin/${targetPrefix}c++
fi
@ -297,14 +302,6 @@ stdenv.mkDerivation {
fi
''
##
## General Clang support
##
+ optionalString isClang ''
echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags
''
##
## GCC libs for non-GCC support
##