1 # N.B. It may be a surprise that the derivation-specific variables are exported,
2 # since this is just sourced by the wrapped binaries---the end consumers. This
3 # is because one wrapper binary may invoke another (e.g. cc invoking ld). In
4 # that case, it is cheaper/better to not repeat this step and let the forked
5 # wrapped binary just inherit the work of the forker's wrapper script.
9 NIX_CFLAGS_COMPILE_BEFORE
21 # We need to mangle names for hygiene, but also take parameters/overrides
22 # from the environment.
23 for var
in "${var_templates_list[@]}"; do
24 mangleVarList
"$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
26 for var
in "${var_templates_bool[@]}"; do
27 mangleVarBool
"$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
30 # Arocc does not support "-B"
31 if [[ -z "@isArocc@" ]]; then
32 # `-B@bintools@/bin' forces cc to use ld-wrapper.sh when calling ld.
33 NIX_CFLAGS_COMPILE_@suffixSalt@
="-B@bintools@/bin/ $NIX_CFLAGS_COMPILE_@suffixSalt@"
36 # Export and assign separately in order that a failing $(..) will fail
39 # Currently bootstrap-tools does not split glibc, and gcc files into
40 # separate directories. As a workaround we want resulting cflags to be
41 # ordered as: crt1-cflags libc-cflags cc-cflags. Otherwise we mix crt/libc.so
42 # from different libc as seen in
43 # https://github.com/NixOS/nixpkgs/issues/158042
45 # Note that below has reverse ordering as we prepend flags one-by-one.
46 # Once bootstrap-tools is split into different directories we can stop
47 # relying on flag ordering below.
49 if [ -e @out@
/nix-support
/cc-cflags
]; then
50 NIX_CFLAGS_COMPILE_@suffixSalt@
="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
53 if [[ "$cInclude" = 1 ]] && [ -e @out@
/nix-support
/libc-cflags
]; then
54 NIX_CFLAGS_COMPILE_@suffixSalt@
="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
57 if [ -e @out@
/nix-support
/libc-crt1-cflags
]; then
58 NIX_CFLAGS_COMPILE_@suffixSalt@
="$(< @out@/nix-support/libc-crt1-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
61 if [ -e @out@
/nix-support
/libcxx-cxxflags
]; then
62 NIX_CXXSTDLIB_COMPILE_@suffixSalt@
+=" $(< @out@/nix-support/libcxx-cxxflags)"
65 if [ -e @out@
/nix-support
/libcxx-ldflags
]; then
66 NIX_CXXSTDLIB_LINK_@suffixSalt@
+=" $(< @out@/nix-support/libcxx-ldflags)"
69 if [ -e @out@
/nix-support
/gnat-cflags
]; then
70 NIX_GNATFLAGS_COMPILE_@suffixSalt@
="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE_@suffixSalt@"
73 if [ -e @out@
/nix-support
/cc-ldflags
]; then
74 NIX_LDFLAGS_@suffixSalt@
+=" $(< @out@/nix-support/cc-ldflags)"
77 if [ -e @out@
/nix-support
/cc-cflags-before
]; then
78 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@
="$(< @out@/nix-support/cc-cflags-before) $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
81 # Only add darwin min version flag and set up `DEVELOPER_DIR` if a default darwin min version is set,
82 # which is a signal that we're targetting darwin.
83 if [ "@darwinMinVersion@" ]; then
84 mangleVarSingle @darwinMinVersionVariable@
${role_suffixes[@]+"${role_suffixes[@]}"}
86 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@
="-m@darwinPlatformForCC@-version-min=${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@} $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
88 # `DEVELOPER_DIR` is used to dynamically locate libSystem (and the SDK frameworks) based on the SDK at that path.
89 mangleVarSingle DEVELOPER_DIR
${role_suffixes[@]+"${role_suffixes[@]}"}
91 # Allow wrapped compilers to do something useful when no `DEVELOPER_DIR` is set, which can happen when
92 # the compiler is run outside of a stdenv or intentionally in an environment with no environment variables set.
93 DEVELOPER_DIR
=${DEVELOPER_DIR_@suffixSalt@:-@fallback_sdk@}
95 # xcbuild needs `SDKROOT` to be the name of the SDK, which it sets in its own wrapper,
96 # but compilers expect it to point to the absolute path.
97 SDKROOT
="$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
99 # Set up various library paths since compilers may not support (or may have disabled) finding them in the sysroot.
100 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@
+=" -isysroot $SDKROOT"
101 NIX_CFLAGS_COMPILE_@suffixSalt@
+=" -idirafter $SDKROOT/usr/include"
102 NIX_CFLAGS_COMPILE_@suffixSalt@
+=" -iframework $SDKROOT/System/Library/Frameworks"
105 # That way forked processes will not extend these environment variables again.
106 export NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@
=1