lol

Merge pull request #176152 from mmlb/cc-wrapper-allow-target-override

cc-wrapper: Allow user to override -target for clang

authored by

John Ericson and committed by
GitHub
e23e71f9 bb52e84b

+60 -55
+11
pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh
··· 1 + needsTarget=true 2 + 3 + for p in "${params[@]}"; do 4 + case "$p" in 5 + -target | --target=*) needsTarget=false ;; 6 + esac 7 + done 8 + 9 + if $needsTarget; then 10 + extraBefore+=(-target @defaultTarget@) 11 + fi
+40 -47
pkgs/build-support/cc-wrapper/cc-wrapper.sh
··· 38 38 while (( "$n" < "$nParams" )); do 39 39 p=${params[n]} 40 40 p2=${params[n+1]:-} # handle `p` being last one 41 - if [ "$p" = -c ]; then 42 - dontLink=1 43 - elif [ "$p" = -S ]; then 44 - dontLink=1 45 - elif [ "$p" = -E ]; then 46 - dontLink=1 47 - elif [ "$p" = -E ]; then 48 - dontLink=1 49 - elif [ "$p" = -M ]; then 50 - dontLink=1 51 - elif [ "$p" = -MM ]; then 52 - dontLink=1 53 - elif [[ "$p" = -x && "$p2" = *-header ]]; then 54 - dontLink=1 55 - elif [[ "$p" = -x && "$p2" = c++* && "$isCxx" = 0 ]]; then 56 - isCxx=1 57 - elif [ "$p" = -nostdlib ]; then 58 - cxxLibrary=0 59 - elif [ "$p" = -nostdinc ]; then 60 - cInclude=0 61 - cxxInclude=0 62 - elif [ "$p" = -nostdinc++ ]; then 63 - cxxInclude=0 64 - elif [[ "$p" != -?* ]]; then 65 - # A dash alone signifies standard input; it is not a flag 66 - nonFlagArgs=1 67 - elif [ "$p" = -cc1 ]; then 68 - cc1=1 69 - fi 70 41 n+=1 42 + 43 + case "$p" in 44 + -[cSEM] | -MM) dontLink=1 ;; 45 + -cc1) cc1=1 ;; 46 + -nostdinc) cInclude=0 cxxInclude=0 ;; 47 + -nostdinc++) cxxInclude=0 ;; 48 + -nostdlib) cxxLibrary=0 ;; 49 + -x) 50 + case "$p2" in 51 + *-header) dontLink=1 ;; 52 + c++*) isCxx=1 ;; 53 + esac 54 + ;; 55 + -?*) ;; 56 + *) nonFlagArgs=1 ;; # Includes a solitary dash (`-`) which signifies standard input; it is not a flag 57 + esac 71 58 done 72 59 73 60 # If we pass a flag like -Wl, then gcc will call the linker unless it ··· 81 68 82 69 # Optionally filter out paths not refering to the store. 83 70 if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then 84 - rest=() 71 + kept=() 85 72 nParams=${#params[@]} 86 73 declare -i n=0 87 74 while (( "$n" < "$nParams" )); do 88 75 p=${params[n]} 89 76 p2=${params[n+1]:-} # handle `p` being last one 90 - if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then 91 - skip "${p:2}" 92 - elif [ "$p" = -L ] && badPath "$p2"; then 93 - n+=1; skip "$p2" 94 - elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then 95 - skip "${p:2}" 96 - elif [ "$p" = -I ] && badPath "$p2"; then 97 - n+=1; skip "$p2" 98 - elif [ "$p" = -isystem ] && badPath "$p2"; then 99 - n+=1; skip "$p2" 100 - else 101 - rest+=("$p") 77 + n+=1 78 + 79 + skipNext=false 80 + path="" 81 + case "$p" in 82 + -[IL]/*) path=${p:2} ;; 83 + -[IL] | -isystem) path=$p2 skipNext=true ;; 84 + esac 85 + 86 + if [[ -n $path ]] && badPath "$path"; then 87 + skip "$path" 88 + $skipNext && n+=1 89 + continue 102 90 fi 103 - n+=1 91 + 92 + kept+=("$p") 104 93 done 105 94 # Old bash empty array hack 106 - params=(${rest+"${rest[@]}"}) 95 + params=(${kept+"${kept[@]}"}) 107 96 fi 108 97 109 98 # Flirting with a layer violation here. ··· 118 107 119 108 # Clear march/mtune=native -- they bring impurity. 120 109 if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then 121 - rest=() 110 + kept=() 122 111 # Old bash empty array hack 123 112 for p in ${params+"${params[@]}"}; do 124 113 if [[ "$p" = -m*=native ]]; then 125 114 skip "$p" 126 115 else 127 - rest+=("$p") 116 + kept+=("$p") 128 117 fi 129 118 done 130 119 # Old bash empty array hack 131 - params=(${rest+"${rest[@]}"}) 120 + params=(${kept+"${kept[@]}"}) 132 121 fi 133 122 134 123 if [[ "$isCxx" = 1 ]]; then ··· 168 157 fi 169 158 done 170 159 export NIX_LINK_TYPE_@suffixSalt@=$linkType 160 + fi 161 + 162 + if [[ -e @out@/nix-support/add-local-cc-cflags-before.sh ]]; then 163 + source @out@/nix-support/add-local-cflags-before.sh 171 164 fi 172 165 173 166 # As a very special hack, if the arguments are just `-v', then don't
+9 -8
pkgs/build-support/cc-wrapper/default.nix
··· 298 298 '' 299 299 300 300 ## 301 - ## General Clang support 302 - ## 303 - + optionalString isClang '' 304 - 305 - echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags 306 - '' 307 - 308 - ## 309 301 ## GCC libs for non-GCC support 310 302 ## 311 303 + optionalString useGccForLibs '' ··· 522 514 substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh 523 515 substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh 524 516 substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash 517 + '' 518 + 519 + ## 520 + ## General Clang support 521 + ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script 522 + ## 523 + + optionalString isClang '' 524 + export defaultTarget=${targetPlatform.config} 525 + substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh 525 526 '' 526 527 527 528 ##