2015-01-09 19:22:12 +00:00
|
|
|
# The Nixpkgs CC is not directly usable, since it doesn't know where
|
2014-10-10 11:49:26 +00:00
|
|
|
# the C library and standard header files are. Therefore the compiler
|
|
|
|
# produced by that package cannot be installed directly in a user
|
|
|
|
# environment and used from the command line. So we use a wrapper
|
|
|
|
# script that sets up the right environment variables so that the
|
|
|
|
# compiler and the linker just "work".
|
2008-06-26 11:07:46 +00:00
|
|
|
|
2018-02-01 00:00:00 +00:00
|
|
|
{ name ? ""
|
2021-01-24 03:02:59 +00:00
|
|
|
, lib
|
2018-09-05 18:33:56 +00:00
|
|
|
, stdenvNoCC
|
2024-04-11 22:14:16 +00:00
|
|
|
, runtimeShell
|
|
|
|
, cc ? null, libc ? null, bintools, coreutils ? null
|
2024-09-29 17:54:47 +00:00
|
|
|
, apple-sdk ? null
|
2019-09-20 10:05:57 +00:00
|
|
|
, zlib ? null
|
2018-09-05 18:33:56 +00:00
|
|
|
, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
|
|
|
|
, propagateDoc ? cc != null && cc ? man
|
2020-03-18 15:28:52 +00:00
|
|
|
, extraTools ? [], extraPackages ? [], extraBuildCommands ? ""
|
2022-04-30 02:54:03 +00:00
|
|
|
, nixSupport ? {}
|
2024-07-01 02:01:07 +00:00
|
|
|
, isGNU ? false, isClang ? cc.isClang or false, isZig ? cc.isZig or false
|
|
|
|
, isArocc ? cc.isArocc or false, isCcache ? cc.isCcache or false
|
2024-06-07 14:57:29 +00:00
|
|
|
, gnugrep ? null
|
2024-04-16 15:44:08 +00:00
|
|
|
, expand-response-params
|
2019-01-26 15:17:57 +00:00
|
|
|
, libcxx ? null
|
stdenv: Nix-driven bootstrap of gcc
#### Summary
By default, when you type `make`, GCC will compile itself three
times. This PR inhibits that behavior by configuring GCC with
`--disable-bootstrap`, and reimplements the triple-rebuild using
Nix rather than `make`/`sh`.
#### Immediate Benefits
- Allow `gcc11` and `gcc12` on `aarch64` (without needing new
`bootstrapFiles`)
- Faster stdenv rebuilds: the third compilation of gcc
(i.e. stageCompare) is no longer a `drvInput` of the final stdenv.
This allows Nix to build stageCompare in parallel with the rest of
nixpkgs instead of in series.
- No more copying `libgcc_s` out of the bootstrap-files or other
derivations
- No more Frankenstein compiler: the final gcc and the libraries it
links against (mpfr, mpc, isl, glibc) are all built by the same
compiler (xgcc) instead of a mixture of the bootstrapFiles'
compiler and xgcc.
- No more [static lib{mpfr,mpc,gmp,isl}.a hack]
- Many other small `stdenv` hacks eliminated
- `gcc` and `clang` share the same codepath for more of `cc-wrapper`.
#### Future Benefits
- This should allow using a [foreign] `bootstrap-files` so long as
`hostPlatform.canExecute bootstrapFiles`.
- This should allow each of the libraries that ship with `gcc`
(lib{backtrace, atomic, cc1, decnumber, ffi, gomp, iberty,
offloadatomic, quadmath, sanitizer, ssp, stdc++-v3, vtv}) to be
built in separate (one-liner) derivations which `inherit src;`
from `gcc`, much like https://github.com/NixOS/nixpkgs/pull/132343
#### Incorporates
- https://github.com/NixOS/nixpkgs/pull/210004
- https://github.com/NixOS/nixpkgs/pull/36948 (unreverted)
- https://github.com/NixOS/nixpkgs/pull/210325
- https://github.com/NixOS/nixpkgs/pull/210118
- https://github.com/NixOS/nixpkgs/pull/210132
- https://github.com/NixOS/nixpkgs/pull/210109
- https://github.com/NixOS/nixpkgs/pull/213909
- https://github.com/NixOS/nixpkgs/pull/216136
- https://github.com/NixOS/nixpkgs/pull/216237
- https://github.com/NixOS/nixpkgs/pull/210019
- https://github.com/NixOS/nixpkgs/pull/216232
- https://github.com/NixOS/nixpkgs/pull/216016
- https://github.com/NixOS/nixpkgs/pull/217977
- https://github.com/NixOS/nixpkgs/pull/217995
#### Closes
- Closes #108305
- Closes #108111
- Closes #201254
- Closes #208412
#### Credits
This project was made possible by three important insights, none of
which were mine:
1. @ericson2314 was the first to advocate for this change, and
probably the first to appreciate its advantages. Nix-driven
(external) bootstrap is "cross by default".
2. @trofi has figured out a lot about how to get gcc to not mix up
the copy of `libstdc++` that it depends on with the copy that it
builds, by moving the `bootstrapFiles`' `libstdc++` into a
[versioned directory]. This allows a Nix-driven bootstrap of gcc
without the final gcc would still having references to the
`bootstrapFiles`.
3. Using the undocumented variable [`user-defined-trusted-dirs`]
when building glibc. When glibc `dlopen()`s `libgcc_s.so`, it
uses a completely different and totally special set of rules for
finding `libgcc_s.so`. This trick is the only way we can put
`libgcc_s.so` in its own separate outpath without creating
circular dependencies or dependencies on the bootstrapFiles. I
would never have guessed to use this (or that it existed!) if it
were not for a [comment in guix] which @Mic92 [mentioned].
My own role in this PR was basically: being available to go on a
coding binge at an opportune moment, so we wouldn't waste a
[crisis].
[aarch64-compare-ofborg]: https://github.com/NixOS/nixpkgs/pull/209870/checks?check_run_id=10662822938
[amd64-compare-ofborg]: https://github.com/NixOS/nixpkgs/pull/209870/checks?check_run_id=10662825857
[nonexistent sysroot]: https://github.com/NixOS/nixpkgs/pull/210004
[versioned directory]: https://github.com/NixOS/nixpkgs/pull/209054
[`user-defined-trusted-dirs`]: https://sourceware.org/legacy-ml/libc-help/2013-11/msg00026.html
[comment in guix]: https://github.com/guix-mirror/guix/blob/5e4ec8218142eee8e6e148e787381a5ef891c5b1/gnu/packages/gcc.scm#L253
[mentioned]: https://github.com/NixOS/nixpkgs/pull/210112#issuecomment-1379608483
[crisis]: https://github.com/NixOS/nixpkgs/issues/108305
[foreign]: https://github.com/NixOS/nixpkgs/pull/170857#issuecomment-1170558348
[static lib{mpfr,mpc,gmp,isl}.a hack]: https://github.com/NixOS/nixpkgs/blob/2f1948af9c984ebb82dfd618e67dc949755823e2/pkgs/stdenv/linux/default.nix#L380
2023-02-24 05:32:36 +00:00
|
|
|
|
|
|
|
# Whether or not to add `-B` and `-L` to `nix-support/cc-{c,ld}flags`
|
|
|
|
, useCcForLibs ?
|
|
|
|
|
|
|
|
# Always add these flags for Clang, because in order to compile (most
|
|
|
|
# software) it needs libraries that are shipped and compiled with gcc.
|
|
|
|
if isClang then true
|
|
|
|
|
|
|
|
# Never add these flags for a build!=host cross-compiler or a host!=target
|
|
|
|
# ("cross-built-native") compiler; currently nixpkgs has a special build
|
|
|
|
# path for these (`crossStageStatic`). Hopefully at some point that build
|
|
|
|
# path will be merged with this one and this conditional will be removed.
|
|
|
|
else if (with stdenvNoCC; buildPlatform != hostPlatform || hostPlatform != targetPlatform) then false
|
|
|
|
|
|
|
|
# Never add these flags when wrapping the bootstrapFiles' compiler; it has a
|
|
|
|
# /usr/-like layout with everything smashed into a single outpath, so it has
|
|
|
|
# no trouble finding its own libraries.
|
|
|
|
else if (cc.passthru.isFromBootstrapFiles or false) then false
|
|
|
|
|
|
|
|
# Add these flags when wrapping `xgcc` (the first compiler that nixpkgs builds)
|
|
|
|
else if (cc.passthru.isXgcc or false) then true
|
|
|
|
|
|
|
|
# Add these flags when wrapping `stdenv.cc`
|
|
|
|
else if (cc.stdenv.cc.cc.passthru.isXgcc or false) then true
|
|
|
|
|
|
|
|
# Do not add these flags in any other situation. This is `false` mainly to
|
|
|
|
# prevent these flags from being added when wrapping *old* versions of gcc
|
|
|
|
# (e.g. `gcc6Stdenv`), since they will cause the old gcc to get `-B` and
|
|
|
|
# `-L` flags pointing at the new gcc's libstdc++ headers. Example failure:
|
|
|
|
# https://hydra.nixos.org/build/213125495
|
|
|
|
else false
|
|
|
|
|
|
|
|
# the derivation at which the `-B` and `-L` flags added by `useCcForLibs` will point
|
2023-02-13 21:50:09 +00:00
|
|
|
, gccForLibs ? if useCcForLibs then cc else null
|
2023-02-28 18:18:51 +00:00
|
|
|
, fortify-headers ? null
|
|
|
|
, includeFortifyHeaders ? null
|
2008-06-26 11:07:46 +00:00
|
|
|
}:
|
|
|
|
|
2018-02-01 00:00:00 +00:00
|
|
|
assert nativeTools -> !propagateDoc && nativePrefix != "";
|
2024-03-12 07:34:58 +00:00
|
|
|
assert !nativeTools -> cc != null && coreutils != null && gnugrep != null;
|
2017-05-23 00:59:39 +00:00
|
|
|
assert !(nativeLibc && noLibc);
|
|
|
|
assert (noLibc || nativeLibc) == (libc == null);
|
2008-06-26 11:07:46 +00:00
|
|
|
|
2009-04-09 15:24:33 +00:00
|
|
|
let
|
2024-03-12 07:34:58 +00:00
|
|
|
inherit (lib)
|
|
|
|
attrByPath
|
|
|
|
concatMapStrings
|
|
|
|
concatStringsSep
|
|
|
|
escapeShellArg
|
2024-06-04 19:06:58 +00:00
|
|
|
escapeShellArgs
|
2024-03-12 07:34:58 +00:00
|
|
|
getBin
|
|
|
|
getDev
|
|
|
|
getLib
|
|
|
|
getName
|
|
|
|
getVersion
|
|
|
|
mapAttrsToList
|
|
|
|
optional
|
|
|
|
optionalAttrs
|
|
|
|
optionals
|
|
|
|
optionalString
|
|
|
|
removePrefix
|
|
|
|
replaceStrings
|
|
|
|
toList
|
|
|
|
versionAtLeast
|
|
|
|
;
|
|
|
|
|
2024-04-14 13:32:41 +00:00
|
|
|
inherit (stdenvNoCC) hostPlatform targetPlatform;
|
2024-03-12 07:34:58 +00:00
|
|
|
|
2023-02-28 18:18:51 +00:00
|
|
|
includeFortifyHeaders' = if includeFortifyHeaders != null
|
|
|
|
then includeFortifyHeaders
|
2023-08-26 12:25:46 +00:00
|
|
|
else (targetPlatform.libc == "musl" && isGNU);
|
2023-02-28 18:18:51 +00:00
|
|
|
|
2017-02-13 23:01:04 +00:00
|
|
|
# Prefix for binaries. Customarily ends with a dash separator.
|
|
|
|
#
|
2024-03-12 07:34:58 +00:00
|
|
|
# TODO(@Ericson2314) Make unconditional, or optional but always true by default.
|
|
|
|
targetPrefix = optionalString (targetPlatform != hostPlatform) (targetPlatform.config + "-");
|
2009-04-09 15:24:33 +00:00
|
|
|
|
2024-03-12 07:34:58 +00:00
|
|
|
ccVersion = getVersion cc;
|
|
|
|
ccName = removePrefix targetPrefix (getName cc);
|
2012-08-03 17:23:51 +00:00
|
|
|
|
2023-06-24 18:19:19 +00:00
|
|
|
libc_bin = optionalString (libc != null) (getBin libc);
|
|
|
|
libc_dev = optionalString (libc != null) (getDev libc);
|
|
|
|
libc_lib = optionalString (libc != null) (getLib libc);
|
2019-08-12 22:59:01 +00:00
|
|
|
cc_solib = getLib cc
|
|
|
|
+ optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}";
|
|
|
|
|
2016-02-03 15:54:03 +00:00
|
|
|
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
|
2023-06-24 18:19:19 +00:00
|
|
|
coreutils_bin = optionalString (!nativeTools) (getBin coreutils);
|
2017-06-08 18:00:40 +00:00
|
|
|
|
2020-04-28 04:08:48 +00:00
|
|
|
# The "suffix salt" is a arbitrary string added in the end of env vars
|
2017-06-26 04:43:06 +00:00
|
|
|
# defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
|
|
|
|
# without interfering. For the moment, it is defined as the target triple,
|
|
|
|
# adjusted to be a valid bash identifier. This should be considered an
|
|
|
|
# unstable implementation detail, however.
|
2024-09-29 17:54:47 +00:00
|
|
|
suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config
|
|
|
|
+ lib.optionalString (targetPlatform.isDarwin && targetPlatform.isStatic) "_static";
|
2017-06-19 15:10:27 +00:00
|
|
|
|
2023-02-13 21:50:09 +00:00
|
|
|
useGccForLibs = useCcForLibs
|
2020-09-07 19:08:11 +00:00
|
|
|
&& libcxx == null
|
2024-04-14 13:41:03 +00:00
|
|
|
&& !targetPlatform.isDarwin
|
|
|
|
&& !(targetPlatform.useLLVM or false)
|
|
|
|
&& !(targetPlatform.useAndroidPrebuilt or false)
|
|
|
|
&& !(targetPlatform.isiOS or false)
|
2020-09-07 19:08:11 +00:00
|
|
|
&& gccForLibs != null;
|
2022-09-22 16:41:40 +00:00
|
|
|
gccForLibs_solib = getLib gccForLibs
|
|
|
|
+ optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}";
|
2020-09-07 19:08:11 +00:00
|
|
|
|
2024-01-10 23:23:05 +00:00
|
|
|
# Analogously to cc_solib and gccForLibs_solib
|
2024-03-12 07:34:58 +00:00
|
|
|
libcxx_solib = "${getLib libcxx}/lib";
|
2024-01-10 23:23:05 +00:00
|
|
|
|
cc-wrapper: fix -mtune= validation, add ARM, add fallbacks
Before this commit, cc-wrapper/default.nix was using
`isGccArchSupported` to validate `-mtune=` values. This has two
problems:
- On x86, `-mtune=` can take the same values as `-march`, plus two
additional values `generic` and `intel` which are not valid for
`-march`.
- On ARM, `-mtune=` does not take the same values as `-march=`;
instead it takes the same values as `-mcpu`.
This commit fixes these two problems by adding a new
`isGccTuneSupported` function. For `isx86` this returns `true` for
the two special values and otherwise defers to `isGccArchSupported`.
This commit also adds support for `-mtune=` on Aarch64.
Unfortunately on Aarch64, Clang does not accept as wide a variety of
`-mtune=` values as Gcc does. In particular, Clang does not tune
for big.LITTLE mixed-model chips like the very popular RK3399, which
is targeted using `-march=cortex-a72.cortex-a53` in gcc.
To address this problem, this commit also adds a function
`findBestTuneApproximation` which can be used to map
clang-unsupported tunings like `cortex-a72.cortex-a53` to
less-precise tunings like `cortex-a53`.
The work which led to this commit arose because we now have
packages, like `crosvm`, which use *both* `clang` *and* `gcc`.
Previously I had been using `overrideAttrs` to set
`NIX_CFLAGS_COMPILE` on a package-by-package basis based on which
compiler that package used. Since we now have packages which use
*both* compilers, this strategy no longer works.
I briefly considered splitting `NIX_CFLAGS_COMPILE` into
`NIX_CFLAGS_COMPILE_GCC` and `NIX_CFLAGS_COMPILE_CLANG`, but since
`NIX_CFLAGS_COMPILE` is sort of a hack to begin with I figured that
adding the logic to `cc-wrapper` would be preferable.
2022-12-08 02:56:32 +00:00
|
|
|
# The following two functions, `isGccArchSupported` and
|
|
|
|
# `isGccTuneSupported`, only handle those situations where a flag
|
|
|
|
# (`-march` or `-mtune`) is accepted by one compiler but rejected
|
|
|
|
# by another, and both compilers are relevant to nixpkgs. We are
|
|
|
|
# not trying to maintain a complete list of all flags accepted by
|
|
|
|
# all versions of all compilers ever in nixpkgs.
|
|
|
|
#
|
|
|
|
# The two main cases of interest are:
|
|
|
|
#
|
|
|
|
# - One compiler is gcc and the other is clang
|
|
|
|
# - One compiler is pkgs.gcc and the other is bootstrap-files.gcc
|
|
|
|
# -- older compilers (for example bootstrap's GCC 5) fail with
|
|
|
|
# -march=too-modern-cpu
|
|
|
|
|
2019-04-21 16:13:37 +00:00
|
|
|
isGccArchSupported = arch:
|
2022-12-09 03:57:17 +00:00
|
|
|
if targetPlatform.isPower then false else # powerpc does not allow -march=
|
2020-04-14 00:44:43 +00:00
|
|
|
if isGNU then
|
2022-11-27 22:18:20 +00:00
|
|
|
{ # Generic
|
|
|
|
x86-64-v2 = versionAtLeast ccVersion "11.0";
|
|
|
|
x86-64-v3 = versionAtLeast ccVersion "11.0";
|
|
|
|
x86-64-v4 = versionAtLeast ccVersion "11.0";
|
|
|
|
|
|
|
|
# Intel
|
2024-09-13 18:10:19 +00:00
|
|
|
skylake = true;
|
|
|
|
skylake-avx512 = true;
|
2019-04-21 16:13:37 +00:00
|
|
|
cannonlake = versionAtLeast ccVersion "8.0";
|
|
|
|
icelake-client = versionAtLeast ccVersion "8.0";
|
|
|
|
icelake-server = versionAtLeast ccVersion "8.0";
|
2020-12-24 00:02:10 +00:00
|
|
|
cascadelake = versionAtLeast ccVersion "9.0";
|
|
|
|
cooperlake = versionAtLeast ccVersion "10.0";
|
|
|
|
tigerlake = versionAtLeast ccVersion "10.0";
|
2019-04-21 16:13:37 +00:00
|
|
|
knm = versionAtLeast ccVersion "8.0";
|
2023-05-16 12:58:40 +00:00
|
|
|
alderlake = versionAtLeast ccVersion "12.0";
|
2024-10-07 10:54:21 +00:00
|
|
|
sapphirerapids = versionAtLeast ccVersion "11.0";
|
|
|
|
emeraldrapids = versionAtLeast ccVersion "13.0";
|
2022-11-27 22:18:20 +00:00
|
|
|
|
2019-05-05 23:40:20 +00:00
|
|
|
# AMD
|
2024-09-13 18:10:19 +00:00
|
|
|
znver1 = true;
|
2020-08-05 02:32:41 +00:00
|
|
|
znver2 = versionAtLeast ccVersion "9.0";
|
2020-12-24 00:02:10 +00:00
|
|
|
znver3 = versionAtLeast ccVersion "11.0";
|
2023-06-15 04:41:43 +00:00
|
|
|
znver4 = versionAtLeast ccVersion "13.0";
|
2019-04-21 16:13:37 +00:00
|
|
|
}.${arch} or true
|
2020-04-14 00:44:43 +00:00
|
|
|
else if isClang then
|
2022-11-27 22:18:20 +00:00
|
|
|
{ #Generic
|
|
|
|
x86-64-v2 = versionAtLeast ccVersion "12.0";
|
|
|
|
x86-64-v3 = versionAtLeast ccVersion "12.0";
|
|
|
|
x86-64-v4 = versionAtLeast ccVersion "12.0";
|
|
|
|
|
|
|
|
# Intel
|
2019-05-05 23:40:20 +00:00
|
|
|
cannonlake = versionAtLeast ccVersion "5.0";
|
2019-04-21 16:13:37 +00:00
|
|
|
icelake-client = versionAtLeast ccVersion "7.0";
|
|
|
|
icelake-server = versionAtLeast ccVersion "7.0";
|
|
|
|
knm = versionAtLeast ccVersion "7.0";
|
2023-05-16 12:58:40 +00:00
|
|
|
alderlake = versionAtLeast ccVersion "16.0";
|
2024-10-07 10:54:21 +00:00
|
|
|
sapphirerapids = versionAtLeast ccVersion "12.0";
|
|
|
|
emeraldrapids = versionAtLeast ccVersion "16.0";
|
2022-11-27 22:18:20 +00:00
|
|
|
|
2019-05-05 23:40:20 +00:00
|
|
|
# AMD
|
|
|
|
znver1 = versionAtLeast ccVersion "4.0";
|
2020-08-05 02:32:41 +00:00
|
|
|
znver2 = versionAtLeast ccVersion "9.0";
|
2023-06-15 04:41:43 +00:00
|
|
|
znver3 = versionAtLeast ccVersion "12.0";
|
|
|
|
znver4 = versionAtLeast ccVersion "16.0";
|
2019-04-21 16:13:37 +00:00
|
|
|
}.${arch} or true
|
|
|
|
else
|
|
|
|
false;
|
|
|
|
|
cc-wrapper: fix -mtune= validation, add ARM, add fallbacks
Before this commit, cc-wrapper/default.nix was using
`isGccArchSupported` to validate `-mtune=` values. This has two
problems:
- On x86, `-mtune=` can take the same values as `-march`, plus two
additional values `generic` and `intel` which are not valid for
`-march`.
- On ARM, `-mtune=` does not take the same values as `-march=`;
instead it takes the same values as `-mcpu`.
This commit fixes these two problems by adding a new
`isGccTuneSupported` function. For `isx86` this returns `true` for
the two special values and otherwise defers to `isGccArchSupported`.
This commit also adds support for `-mtune=` on Aarch64.
Unfortunately on Aarch64, Clang does not accept as wide a variety of
`-mtune=` values as Gcc does. In particular, Clang does not tune
for big.LITTLE mixed-model chips like the very popular RK3399, which
is targeted using `-march=cortex-a72.cortex-a53` in gcc.
To address this problem, this commit also adds a function
`findBestTuneApproximation` which can be used to map
clang-unsupported tunings like `cortex-a72.cortex-a53` to
less-precise tunings like `cortex-a53`.
The work which led to this commit arose because we now have
packages, like `crosvm`, which use *both* `clang` *and* `gcc`.
Previously I had been using `overrideAttrs` to set
`NIX_CFLAGS_COMPILE` on a package-by-package basis based on which
compiler that package used. Since we now have packages which use
*both* compilers, this strategy no longer works.
I briefly considered splitting `NIX_CFLAGS_COMPILE` into
`NIX_CFLAGS_COMPILE_GCC` and `NIX_CFLAGS_COMPILE_CLANG`, but since
`NIX_CFLAGS_COMPILE` is sort of a hack to begin with I figured that
adding the logic to `cc-wrapper` would be preferable.
2022-12-08 02:56:32 +00:00
|
|
|
isGccTuneSupported = tune:
|
|
|
|
# for x86 -mtune= takes the same values as -march, plus two more:
|
|
|
|
if targetPlatform.isx86 then
|
|
|
|
{
|
|
|
|
generic = true;
|
|
|
|
intel = true;
|
|
|
|
}.${tune} or (isGccArchSupported tune)
|
|
|
|
# on arm64, the -mtune= values are specific processors
|
|
|
|
else if targetPlatform.isAarch64 then
|
|
|
|
(if isGNU then
|
|
|
|
{
|
2024-09-13 18:10:19 +00:00
|
|
|
cortex-a53 = true;
|
|
|
|
cortex-a72 = true;
|
|
|
|
"cortex-a72.cortex-a53" = true;
|
cc-wrapper: fix -mtune= validation, add ARM, add fallbacks
Before this commit, cc-wrapper/default.nix was using
`isGccArchSupported` to validate `-mtune=` values. This has two
problems:
- On x86, `-mtune=` can take the same values as `-march`, plus two
additional values `generic` and `intel` which are not valid for
`-march`.
- On ARM, `-mtune=` does not take the same values as `-march=`;
instead it takes the same values as `-mcpu`.
This commit fixes these two problems by adding a new
`isGccTuneSupported` function. For `isx86` this returns `true` for
the two special values and otherwise defers to `isGccArchSupported`.
This commit also adds support for `-mtune=` on Aarch64.
Unfortunately on Aarch64, Clang does not accept as wide a variety of
`-mtune=` values as Gcc does. In particular, Clang does not tune
for big.LITTLE mixed-model chips like the very popular RK3399, which
is targeted using `-march=cortex-a72.cortex-a53` in gcc.
To address this problem, this commit also adds a function
`findBestTuneApproximation` which can be used to map
clang-unsupported tunings like `cortex-a72.cortex-a53` to
less-precise tunings like `cortex-a53`.
The work which led to this commit arose because we now have
packages, like `crosvm`, which use *both* `clang` *and* `gcc`.
Previously I had been using `overrideAttrs` to set
`NIX_CFLAGS_COMPILE` on a package-by-package basis based on which
compiler that package used. Since we now have packages which use
*both* compilers, this strategy no longer works.
I briefly considered splitting `NIX_CFLAGS_COMPILE` into
`NIX_CFLAGS_COMPILE_GCC` and `NIX_CFLAGS_COMPILE_CLANG`, but since
`NIX_CFLAGS_COMPILE` is sort of a hack to begin with I figured that
adding the logic to `cc-wrapper` would be preferable.
2022-12-08 02:56:32 +00:00
|
|
|
}.${tune} or false
|
|
|
|
else if isClang then
|
|
|
|
{
|
|
|
|
cortex-a53 = versionAtLeast ccVersion "3.9"; # llvm dfc5d1
|
|
|
|
}.${tune} or false
|
|
|
|
else false)
|
|
|
|
else if targetPlatform.isPower then
|
|
|
|
# powerpc does not support -march
|
|
|
|
true
|
|
|
|
else if targetPlatform.isMips then
|
|
|
|
# for mips -mtune= takes the same values as -march
|
|
|
|
isGccArchSupported tune
|
|
|
|
else
|
|
|
|
false;
|
|
|
|
|
|
|
|
# Clang does not support as many `-mtune=` values as gcc does;
|
|
|
|
# this function will return the best possible approximation of the
|
|
|
|
# provided `-mtune=` value, or `null` if none exists.
|
|
|
|
#
|
|
|
|
# Note: this function can make use of ccVersion; for example, `if
|
|
|
|
# versionOlder ccVersion "12" then ...`
|
|
|
|
findBestTuneApproximation = tune:
|
|
|
|
let guess = if isClang
|
|
|
|
then {
|
|
|
|
# clang does not tune for big.LITTLE chips
|
|
|
|
"cortex-a72.cortex-a53" = "cortex-a72";
|
|
|
|
}.${tune} or tune
|
|
|
|
else tune;
|
|
|
|
in if isGccTuneSupported guess
|
|
|
|
then guess
|
|
|
|
else null;
|
2021-04-10 04:11:28 +00:00
|
|
|
|
2024-06-04 19:06:58 +00:00
|
|
|
thumb = if targetPlatform.gcc.thumb then "thumb" else "arm";
|
|
|
|
tune = if targetPlatform ? gcc.tune
|
|
|
|
then findBestTuneApproximation targetPlatform.gcc.tune
|
|
|
|
else null;
|
|
|
|
|
|
|
|
# Machine flags. These are necessary to support
|
|
|
|
|
|
|
|
# TODO: We should make a way to support miscellaneous machine
|
|
|
|
# flags and other gcc flags as well.
|
|
|
|
|
|
|
|
machineFlags =
|
|
|
|
# Always add -march based on cpu in triple. Sometimes there is a
|
|
|
|
# discrepency (x86_64 vs. x86-64), so we provide an "arch" arg in
|
|
|
|
# that case.
|
|
|
|
optional (targetPlatform ? gcc.arch && !(targetPlatform.isDarwin && targetPlatform.isAarch64) && isGccArchSupported targetPlatform.gcc.arch) "-march=${targetPlatform.gcc.arch}" ++
|
|
|
|
# TODO: aarch64-darwin has mcpu incompatible with gcc
|
|
|
|
optional (targetPlatform ? gcc.cpu && !(targetPlatform.isDarwin && targetPlatform.isAarch64)) "-mcpu=${targetPlatform.gcc.cpu}" ++
|
|
|
|
# -mfloat-abi only matters on arm32 but we set it here
|
|
|
|
# unconditionally just in case. If the abi specifically sets hard
|
|
|
|
# vs. soft floats we use it here.
|
|
|
|
optional (targetPlatform ? gcc.float-abi) "-mfloat-abi=${targetPlatform.gcc.float-abi}" ++
|
|
|
|
optional (targetPlatform ? gcc.fpu) "-mfpu=${targetPlatform.gcc.fpu}" ++
|
|
|
|
optional (targetPlatform ? gcc.mode) "-mmode=${targetPlatform.gcc.mode}" ++
|
|
|
|
optional (targetPlatform ? gcc.thumb) "-m${thumb}" ++
|
|
|
|
optional (tune != null) "-mtune=${tune}";
|
|
|
|
|
2023-10-02 18:38:56 +00:00
|
|
|
defaultHardeningFlags = bintools.defaultHardeningFlags or [];
|
|
|
|
|
2023-12-17 14:04:44 +00:00
|
|
|
# if cc.hardeningUnsupportedFlagsByTargetPlatform exists, this is
|
|
|
|
# called with the targetPlatform as an argument and
|
|
|
|
# cc.hardeningUnsupportedFlags is completely ignored - the function
|
|
|
|
# is responsible for including the constant hardeningUnsupportedFlags
|
|
|
|
# list however it sees fit.
|
|
|
|
ccHardeningUnsupportedFlags = if cc ? hardeningUnsupportedFlagsByTargetPlatform
|
|
|
|
then cc.hardeningUnsupportedFlagsByTargetPlatform targetPlatform
|
|
|
|
else (cc.hardeningUnsupportedFlags or []);
|
|
|
|
|
2024-04-14 13:41:03 +00:00
|
|
|
darwinPlatformForCC = optionalString targetPlatform.isDarwin (
|
2021-04-10 04:11:28 +00:00
|
|
|
if (targetPlatform.darwinPlatform == "macos" && isGNU) then "macosx"
|
|
|
|
else targetPlatform.darwinPlatform
|
|
|
|
);
|
2009-04-09 15:24:33 +00:00
|
|
|
in
|
2009-03-25 17:34:38 +00:00
|
|
|
|
2023-02-28 18:18:51 +00:00
|
|
|
assert includeFortifyHeaders' -> fortify-headers != null;
|
|
|
|
|
2017-08-28 18:56:08 +00:00
|
|
|
# Ensure bintools matches
|
|
|
|
assert libc_bin == bintools.libc_bin;
|
|
|
|
assert libc_dev == bintools.libc_dev;
|
|
|
|
assert libc_lib == bintools.libc_lib;
|
|
|
|
assert nativeTools == bintools.nativeTools;
|
|
|
|
assert nativeLibc == bintools.nativeLibc;
|
|
|
|
assert nativePrefix == bintools.nativePrefix;
|
|
|
|
|
2024-04-14 13:32:41 +00:00
|
|
|
stdenvNoCC.mkDerivation {
|
2019-06-24 00:42:48 +00:00
|
|
|
pname = targetPrefix
|
|
|
|
+ (if name != "" then name else "${ccName}-wrapper");
|
2023-06-24 18:19:19 +00:00
|
|
|
version = optionalString (cc != null) ccVersion;
|
2014-02-04 15:58:12 +00:00
|
|
|
|
2014-10-10 11:49:26 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2018-02-01 00:00:00 +00:00
|
|
|
outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ];
|
2017-06-08 18:00:40 +00:00
|
|
|
|
2024-07-01 02:01:07 +00:00
|
|
|
# Cannot be in "passthru" due to "substituteAll"
|
|
|
|
inherit isArocc;
|
|
|
|
|
2016-10-07 14:31:37 +00:00
|
|
|
passthru = {
|
2022-12-06 22:08:33 +00:00
|
|
|
inherit targetPrefix suffixSalt;
|
2017-10-10 23:01:42 +00:00
|
|
|
# "cc" is the generic name for a C compiler, but there is no one for package
|
|
|
|
# providing the linker and related tools. The two we use now are GNU
|
2017-08-28 18:56:08 +00:00
|
|
|
# Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
|
2017-10-10 23:01:42 +00:00
|
|
|
# unused middle-ground name that evokes both.
|
2017-08-28 18:56:08 +00:00
|
|
|
inherit bintools;
|
2024-06-07 14:57:29 +00:00
|
|
|
inherit cc libc libcxx nativeTools nativeLibc nativePrefix isGNU isClang isZig;
|
2016-10-07 14:31:37 +00:00
|
|
|
|
|
|
|
emacsBufferSetup = pkgs: ''
|
|
|
|
; We should handle propagation here too
|
2017-08-28 18:56:08 +00:00
|
|
|
(mapc
|
|
|
|
(lambda (arg)
|
|
|
|
(when (file-directory-p (concat arg "/include"))
|
2020-04-28 04:08:48 +00:00
|
|
|
(setenv "NIX_CFLAGS_COMPILE_${suffixSalt}" (concat (getenv "NIX_CFLAGS_COMPILE_${suffixSalt}") " -isystem " arg "/include"))))
|
2017-08-28 18:56:08 +00:00
|
|
|
'(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
|
2016-10-07 14:31:37 +00:00
|
|
|
'';
|
2022-04-30 02:54:03 +00:00
|
|
|
|
2024-04-16 15:44:08 +00:00
|
|
|
# Expose expand-response-params we are /actually/ using. In stdenv
|
|
|
|
# bootstrapping, expand-response-params usually comes from an earlier stage,
|
|
|
|
# so it is important to expose this for reference checking.
|
2022-07-31 15:26:35 +00:00
|
|
|
inherit expand-response-params;
|
|
|
|
|
2022-04-30 02:54:03 +00:00
|
|
|
inherit nixSupport;
|
2023-10-02 18:38:56 +00:00
|
|
|
|
|
|
|
inherit defaultHardeningFlags;
|
2016-10-07 14:31:37 +00:00
|
|
|
};
|
2014-10-10 11:49:26 +00:00
|
|
|
|
2017-08-23 20:55:55 +00:00
|
|
|
dontBuild = true;
|
|
|
|
dontConfigure = true;
|
2022-05-14 01:13:49 +00:00
|
|
|
enableParallelBuilding = true;
|
2017-08-23 20:55:55 +00:00
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
src=$PWD
|
|
|
|
'';
|
|
|
|
|
2019-11-27 19:15:56 +00:00
|
|
|
wrapper = ./cc-wrapper.sh;
|
|
|
|
|
2017-08-23 20:55:55 +00:00
|
|
|
installPhase =
|
2014-10-10 11:49:26 +00:00
|
|
|
''
|
2018-02-01 00:00:00 +00:00
|
|
|
mkdir -p $out/bin $out/nix-support
|
2014-10-10 11:49:26 +00:00
|
|
|
|
|
|
|
wrap() {
|
|
|
|
local dst="$1"
|
|
|
|
local wrapper="$2"
|
|
|
|
export prog="$3"
|
2022-06-19 21:18:01 +00:00
|
|
|
export use_response_file_by_default=${if isClang && !isCcache then "1" else "0"}
|
2014-10-10 11:49:26 +00:00
|
|
|
substituteAll "$wrapper" "$out/bin/$dst"
|
|
|
|
chmod +x "$out/bin/$dst"
|
|
|
|
}
|
|
|
|
''
|
|
|
|
|
|
|
|
+ (if nativeTools then ''
|
2017-08-23 20:55:55 +00:00
|
|
|
echo ${if targetPlatform.isDarwin then cc else nativePrefix} > $out/nix-support/orig-cc
|
|
|
|
|
2017-05-21 18:51:02 +00:00
|
|
|
ccPath="${if targetPlatform.isDarwin then cc else nativePrefix}/bin"
|
2014-10-10 11:49:26 +00:00
|
|
|
'' else ''
|
2015-01-09 19:22:12 +00:00
|
|
|
echo $cc > $out/nix-support/orig-cc
|
2014-10-10 11:49:26 +00:00
|
|
|
|
2016-01-02 10:14:09 +00:00
|
|
|
ccPath="${cc}/bin"
|
2014-10-10 11:49:26 +00:00
|
|
|
'')
|
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
# Create symlinks to everything in the bintools wrapper.
|
2014-10-10 11:49:26 +00:00
|
|
|
+ ''
|
2017-08-28 18:56:08 +00:00
|
|
|
for bbin in $bintools/bin/*; do
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
ln -s "$bbin" "$out/bin/$(basename $bbin)"
|
|
|
|
done
|
2020-06-30 15:04:10 +00:00
|
|
|
''
|
2014-10-10 12:01:38 +00:00
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
# We export environment variables pointing to the wrapped nonstandard
|
|
|
|
# cmds, lest some lousy configure script use those to guess compiler
|
|
|
|
# version.
|
|
|
|
+ ''
|
2017-11-25 18:43:57 +00:00
|
|
|
export named_cc=${targetPrefix}cc
|
|
|
|
export named_cxx=${targetPrefix}c++
|
2017-06-26 05:17:09 +00:00
|
|
|
|
2017-11-25 18:43:57 +00:00
|
|
|
if [ -e $ccPath/${targetPrefix}gcc ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc
|
2017-11-25 18:43:57 +00:00
|
|
|
ln -s ${targetPrefix}gcc $out/bin/${targetPrefix}cc
|
|
|
|
export named_cc=${targetPrefix}gcc
|
|
|
|
export named_cxx=${targetPrefix}g++
|
2015-01-09 19:22:12 +00:00
|
|
|
elif [ -e $ccPath/clang ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}clang $wrapper $ccPath/clang
|
2017-11-25 18:43:57 +00:00
|
|
|
ln -s ${targetPrefix}clang $out/bin/${targetPrefix}cc
|
|
|
|
export named_cc=${targetPrefix}clang
|
|
|
|
export named_cxx=${targetPrefix}clang++
|
2024-07-01 02:01:07 +00:00
|
|
|
elif [ -e $ccPath/arocc ]; then
|
|
|
|
wrap ${targetPrefix}arocc $wrapper $ccPath/arocc
|
|
|
|
ln -s ${targetPrefix}arocc $out/bin/${targetPrefix}cc
|
|
|
|
export named_cc=${targetPrefix}arocc
|
2014-10-10 11:49:26 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-25 18:43:57 +00:00
|
|
|
if [ -e $ccPath/${targetPrefix}g++ ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}g++ $wrapper $ccPath/${targetPrefix}g++
|
2017-11-25 18:43:57 +00:00
|
|
|
ln -s ${targetPrefix}g++ $out/bin/${targetPrefix}c++
|
2015-01-09 19:22:12 +00:00
|
|
|
elif [ -e $ccPath/clang++ ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}clang++ $wrapper $ccPath/clang++
|
2017-11-25 18:43:57 +00:00
|
|
|
ln -s ${targetPrefix}clang++ $out/bin/${targetPrefix}c++
|
2014-10-10 13:48:34 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-17 18:03:33 +00:00
|
|
|
if [ -e $ccPath/${targetPrefix}cpp ]; then
|
2023-03-17 15:03:44 +00:00
|
|
|
wrap ${targetPrefix}cpp $wrapper $ccPath/${targetPrefix}cpp
|
2023-03-17 18:03:33 +00:00
|
|
|
elif [ -e $ccPath/cpp ]; then
|
|
|
|
wrap ${targetPrefix}cpp $wrapper $ccPath/cpp
|
2014-10-10 11:49:26 +00:00
|
|
|
fi
|
|
|
|
''
|
|
|
|
|
2023-01-06 09:32:49 +00:00
|
|
|
# No need to wrap gnat, gnatkr, gnatname or gnatprep; we can just symlink them in
|
2019-05-11 21:16:17 +00:00
|
|
|
+ optionalString cc.langAda or false ''
|
2023-01-06 09:32:49 +00:00
|
|
|
for cmd in gnatbind gnatchop gnatclean gnatlink gnatls gnatmake; do
|
|
|
|
wrap ${targetPrefix}$cmd ${./gnat-wrapper.sh} $ccPath/${targetPrefix}$cmd
|
|
|
|
done
|
|
|
|
|
|
|
|
for cmd in gnat gnatkr gnatname gnatprep; do
|
|
|
|
ln -s $ccPath/${targetPrefix}$cmd $out/bin/${targetPrefix}$cmd
|
|
|
|
done
|
gprbuild, xmlada: init at 21.0.0
GPRbuild is a multi language build system developed by AdaCore which
is mostly used for build Ada-related projects using GNAT.
Since GPRbuild is used to build itself and its dependency library
XML/Ada we first build a bootstrap version of it using the provided
bash build script bootstrap.sh as the gprbuild-boot derivation.
gprbuild-boot is then used to build xmlada and the proper gprbuild
derivation.
GPRbuild has its own search path mechanism via GPR_PROJECT_PATH which
we address via a setupHook. It currently works quite similar to the
pkg-config one: It accumulates all inputs into GPR_PROJECT_PATH,
GPR_PROJECT_PATH_FOR_BUILD etc. However this is quite limited at the
moment as we don't have a gprbuild wrapper yet which understands the
_FOR_BUILD suffix. However, we'll need to address this in the future
as it is currently basically impossible to test since the distinction
only affects cross-compilation, but it is not possible to build a GNAT
cross-compiler in nixpkgs at the moment (I'm working on changing that,
however).
Another issue we had to solve was GPRbuild not finding the right GNAT
via its gprconfig tool: GPRbuild has a knowledge base with compiler
definitions which run some checks and collect info about binaries
which are in PATH. In the end the first compiler in PATH that supports
the desired language is selected.
We want GPRbuild to discover our wrapped GNAT since the unwrapped one
is incapable of producing working binaries since it won't find the
crt*.o objects distributed with libc. GPRbuild however needs to find
the Ada runtime distributed with GNAT which is not part of the wrapper
derivation, so it will skip the wrapper and select the unwrapped GNAT.
Symlinking the unwrapped's lib directory into the wrapper fixes this
problem, but breaks linking in some cases (e. g. when linking against
OMP from gcc, the runtime variant will shadow the problem dynamic lib
from buildInputs). Additionally it uses gnatls as an indicator it has
found GNAT which is not part of the wrapper.
The solution we opted to adopt here is to install a custom compiler
description into gprbuild's knowledge base which properly detects the
nixpkgs GNAT wrapper: It uses gnatmake to detect GNAT instead of
gnatls and discovers the runtime via a symlink we add to
`$out/nix-support`. This additional definition is enough to properly
detect GNAT, since the plain wrapped gcc detection works out of the
box. It may, however, be necessary to add special definitions for
other languages in the future where gprbuild also needs to discover
the runtime.
One future improvement would be to install libgpr into a separate
output or split it into a separate derivation (which would require to
link gprbuild statically always since otherwise we end up with a
cyclical dependency).
2021-07-22 11:52:40 +00:00
|
|
|
|
|
|
|
# this symlink points to the unwrapped gnat's output "out". It is used by
|
|
|
|
# our custom gprconfig compiler description to find GNAT's ada runtime. See
|
2024-02-19 20:17:42 +00:00
|
|
|
# ../../development/ada-modules/gprbuild/{boot.nix, nixpkgs-gnat.xml}
|
gprbuild, xmlada: init at 21.0.0
GPRbuild is a multi language build system developed by AdaCore which
is mostly used for build Ada-related projects using GNAT.
Since GPRbuild is used to build itself and its dependency library
XML/Ada we first build a bootstrap version of it using the provided
bash build script bootstrap.sh as the gprbuild-boot derivation.
gprbuild-boot is then used to build xmlada and the proper gprbuild
derivation.
GPRbuild has its own search path mechanism via GPR_PROJECT_PATH which
we address via a setupHook. It currently works quite similar to the
pkg-config one: It accumulates all inputs into GPR_PROJECT_PATH,
GPR_PROJECT_PATH_FOR_BUILD etc. However this is quite limited at the
moment as we don't have a gprbuild wrapper yet which understands the
_FOR_BUILD suffix. However, we'll need to address this in the future
as it is currently basically impossible to test since the distinction
only affects cross-compilation, but it is not possible to build a GNAT
cross-compiler in nixpkgs at the moment (I'm working on changing that,
however).
Another issue we had to solve was GPRbuild not finding the right GNAT
via its gprconfig tool: GPRbuild has a knowledge base with compiler
definitions which run some checks and collect info about binaries
which are in PATH. In the end the first compiler in PATH that supports
the desired language is selected.
We want GPRbuild to discover our wrapped GNAT since the unwrapped one
is incapable of producing working binaries since it won't find the
crt*.o objects distributed with libc. GPRbuild however needs to find
the Ada runtime distributed with GNAT which is not part of the wrapper
derivation, so it will skip the wrapper and select the unwrapped GNAT.
Symlinking the unwrapped's lib directory into the wrapper fixes this
problem, but breaks linking in some cases (e. g. when linking against
OMP from gcc, the runtime variant will shadow the problem dynamic lib
from buildInputs). Additionally it uses gnatls as an indicator it has
found GNAT which is not part of the wrapper.
The solution we opted to adopt here is to install a custom compiler
description into gprbuild's knowledge base which properly detects the
nixpkgs GNAT wrapper: It uses gnatmake to detect GNAT instead of
gnatls and discovers the runtime via a symlink we add to
`$out/nix-support`. This additional definition is enough to properly
detect GNAT, since the plain wrapped gcc detection works out of the
box. It may, however, be necessary to add special definitions for
other languages in the future where gprbuild also needs to discover
the runtime.
One future improvement would be to install libgpr into a separate
output or split it into a separate derivation (which would require to
link gprbuild statically always since otherwise we end up with a
cyclical dependency).
2021-07-22 11:52:40 +00:00
|
|
|
ln -sf ${cc} $out/nix-support/gprconfig-gnat-unwrapped
|
2019-05-11 21:16:17 +00:00
|
|
|
''
|
|
|
|
|
2019-09-20 10:05:57 +00:00
|
|
|
+ optionalString cc.langD or false ''
|
|
|
|
wrap ${targetPrefix}gdc $wrapper $ccPath/${targetPrefix}gdc
|
|
|
|
''
|
|
|
|
|
2022-08-19 07:08:11 +00:00
|
|
|
+ optionalString cc.langFortran or false ''
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}gfortran $wrapper $ccPath/${targetPrefix}gfortran
|
2017-11-25 18:43:57 +00:00
|
|
|
ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}g77
|
|
|
|
ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}f77
|
2020-07-06 04:22:19 +00:00
|
|
|
export named_fc=${targetPrefix}gfortran
|
2014-10-10 11:49:26 +00:00
|
|
|
''
|
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
+ optionalString cc.langJava or false ''
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}gcj $wrapper $ccPath/${targetPrefix}gcj
|
2014-10-10 11:49:26 +00:00
|
|
|
''
|
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
+ optionalString cc.langGo or false ''
|
2019-11-27 19:15:56 +00:00
|
|
|
wrap ${targetPrefix}gccgo $wrapper $ccPath/${targetPrefix}gccgo
|
2023-01-20 13:31:54 +00:00
|
|
|
wrap ${targetPrefix}go ${./go-wrapper.sh} $ccPath/${targetPrefix}go
|
2017-08-23 20:55:55 +00:00
|
|
|
'';
|
|
|
|
|
2018-05-13 15:31:24 +00:00
|
|
|
strictDeps = true;
|
2023-06-07 05:37:59 +00:00
|
|
|
propagatedBuildInputs = [ bintools ] ++ extraTools ++ optionals cc.langD or cc.langJava or false [ zlib ];
|
2020-04-14 00:44:43 +00:00
|
|
|
depsTargetTargetPropagated = optional (libcxx != null) libcxx ++ extraPackages;
|
2017-08-23 20:55:55 +00:00
|
|
|
|
2018-05-07 17:07:19 +00:00
|
|
|
setupHooks = [
|
|
|
|
../setup-hooks/role.bash
|
2024-03-12 07:34:58 +00:00
|
|
|
] ++ optional (cc.langC or true) ./setup-hook.sh
|
|
|
|
++ optional (cc.langFortran or false) ./fortran-hook.sh
|
2024-04-14 13:32:41 +00:00
|
|
|
++ optional (targetPlatform.isWindows) (stdenvNoCC.mkDerivation {
|
2023-08-30 23:40:11 +00:00
|
|
|
name = "win-dll-hook.sh";
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib" > $out
|
|
|
|
echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib64" >> $out
|
|
|
|
echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib32" >> $out
|
|
|
|
'';
|
|
|
|
});
|
2017-08-23 20:55:55 +00:00
|
|
|
|
|
|
|
postFixup =
|
2020-06-30 18:26:37 +00:00
|
|
|
# Ensure flags files exists, as some other programs cat them. (That these
|
|
|
|
# are considered an exposed interface is a bit dubious, but fine for now.)
|
|
|
|
''
|
|
|
|
touch "$out/nix-support/cc-cflags"
|
|
|
|
touch "$out/nix-support/cc-ldflags"
|
|
|
|
''
|
|
|
|
|
2023-05-20 02:11:55 +00:00
|
|
|
# Backwards compatibility for packages expecting this file, e.g. with
|
2020-06-30 15:04:10 +00:00
|
|
|
# `$NIX_CC/nix-support/dynamic-linker`.
|
|
|
|
#
|
|
|
|
# TODO(@Ericson2314): Remove this after stable release and force
|
|
|
|
# everyone to refer to bintools-wrapper directly.
|
2024-07-01 02:01:07 +00:00
|
|
|
+ optionalString (!isArocc) ''
|
2017-08-28 18:56:08 +00:00
|
|
|
if [[ -f "$bintools/nix-support/dynamic-linker" ]]; then
|
|
|
|
ln -s "$bintools/nix-support/dynamic-linker" "$out/nix-support"
|
|
|
|
fi
|
|
|
|
if [[ -f "$bintools/nix-support/dynamic-linker-m32" ]]; then
|
|
|
|
ln -s "$bintools/nix-support/dynamic-linker-m32" "$out/nix-support"
|
|
|
|
fi
|
2017-08-23 20:55:55 +00:00
|
|
|
''
|
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## GCC libs for non-GCC support
|
|
|
|
##
|
2023-04-12 06:49:48 +00:00
|
|
|
+ optionalString (useGccForLibs && isClang) ''
|
2020-04-14 00:44:43 +00:00
|
|
|
|
2020-06-17 20:33:56 +00:00
|
|
|
echo "-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-cflags
|
2023-04-12 07:34:40 +00:00
|
|
|
''
|
2024-07-01 02:01:07 +00:00
|
|
|
+ optionalString (useGccForLibs && !isArocc) ''
|
2020-06-17 20:33:56 +00:00
|
|
|
echo "-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-ldflags
|
2022-09-22 16:41:40 +00:00
|
|
|
echo "-L${gccForLibs_solib}/lib" >> $out/nix-support/cc-ldflags
|
2020-04-14 00:44:43 +00:00
|
|
|
''
|
|
|
|
|
2021-01-20 23:45:52 +00:00
|
|
|
# TODO We would like to connect this to `useGccForLibs`, but we cannot yet
|
|
|
|
# because `libcxxStdenv` on linux still needs this. Maybe someday we'll
|
|
|
|
# always set `useLLVM` on Darwin, and maybe also break down `useLLVM` into
|
|
|
|
# fine-grained use flags (libgcc vs compiler-rt, ld.lld vs legacy, libc++
|
|
|
|
# vs libstdc++, etc.) since Darwin isn't `useLLVM` on all counts. (See
|
|
|
|
# https://clang.llvm.org/docs/Toolchain.html for all the axes one might
|
|
|
|
# break `useLLVM` into.)
|
2021-04-10 17:39:07 +00:00
|
|
|
+ optionalString (isClang
|
2021-02-10 18:38:17 +00:00
|
|
|
&& targetPlatform.isLinux
|
2024-04-14 13:41:03 +00:00
|
|
|
&& !(targetPlatform.useAndroidPrebuilt or false)
|
|
|
|
&& !(targetPlatform.useLLVM or false)
|
2023-02-22 06:09:38 +00:00
|
|
|
&& gccForLibs != null) (''
|
2021-01-20 23:45:52 +00:00
|
|
|
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
|
2023-01-27 21:30:14 +00:00
|
|
|
|
|
|
|
# Pull in 'cc.out' target to get 'libstdc++fs.a'. It should be in
|
|
|
|
# 'cc.lib'. But it's a gcc package bug.
|
|
|
|
# TODO(trofi): remove once gcc is fixed to move libraries to .lib output.
|
|
|
|
echo "-L${gccForLibs}/${optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}"}/lib" >> $out/nix-support/cc-ldflags
|
2021-01-20 23:45:52 +00:00
|
|
|
''
|
2023-02-22 06:09:38 +00:00
|
|
|
# this ensures that when clang passes -lgcc_s to lld (as it does
|
|
|
|
# when building e.g. firefox), lld is able to find libgcc_s.so
|
2024-07-01 02:01:07 +00:00
|
|
|
+ optionals (!isArocc) (concatMapStrings (libgcc: ''
|
2023-05-07 08:27:01 +00:00
|
|
|
echo "-L${libgcc}/lib" >> $out/nix-support/cc-ldflags
|
2024-07-01 02:01:07 +00:00
|
|
|
'') (toList (gccForLibs.libgcc or []))))
|
2021-01-20 23:45:52 +00:00
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## General libc support
|
|
|
|
##
|
|
|
|
|
|
|
|
# The "-B${libc_lib}/lib/" flag is a quick hack to force gcc to link
|
|
|
|
# against the crt1.o from our own glibc, rather than the one in
|
|
|
|
# /usr/lib. (This is only an issue when using an `impure'
|
|
|
|
# compiler/linker, i.e., one that searches /usr/lib and so on.)
|
|
|
|
#
|
|
|
|
# Unfortunately, setting -B appears to override the default search
|
|
|
|
# path. Thus, the gcc-specific "../includes-fixed" directory is
|
|
|
|
# now longer searched and glibc's <limits.h> header fails to
|
|
|
|
# compile, because it uses "#include_next <limits.h>" to find the
|
|
|
|
# limits.h file in ../includes-fixed. To remedy the problem,
|
|
|
|
# another -idirafter is necessary to add that directory again.
|
2019-11-26 00:55:16 +00:00
|
|
|
+ optionalString (libc != null) (''
|
2020-06-30 18:26:37 +00:00
|
|
|
touch "$out/nix-support/libc-cflags"
|
|
|
|
touch "$out/nix-support/libc-ldflags"
|
2024-07-01 02:01:07 +00:00
|
|
|
'' + optionalString (!isArocc) ''
|
2020-07-01 20:55:06 +00:00
|
|
|
echo "-B${libc_lib}${libc.libdir or "/lib/"}" >> $out/nix-support/libc-crt1-cflags
|
2019-09-20 10:05:57 +00:00
|
|
|
'' + optionalString (!(cc.langD or false)) ''
|
2024-07-01 02:01:07 +00:00
|
|
|
echo "-${if isArocc then "I" else "idirafter"} ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags
|
2019-09-20 10:05:57 +00:00
|
|
|
'' + optionalString (isGNU && (!(cc.langD or false))) ''
|
2019-11-26 00:55:16 +00:00
|
|
|
for dir in "${cc}"/lib/gcc/*/*/include-fixed; do
|
|
|
|
echo '-idirafter' ''${dir} >> $out/nix-support/libc-cflags
|
|
|
|
done
|
|
|
|
'' + ''
|
2017-08-23 20:55:55 +00:00
|
|
|
|
|
|
|
echo "${libc_lib}" > $out/nix-support/orig-libc
|
|
|
|
echo "${libc_dev}" > $out/nix-support/orig-libc-dev
|
2023-02-28 18:18:51 +00:00
|
|
|
''
|
|
|
|
# fortify-headers is a set of wrapper headers that augment libc
|
|
|
|
# and use #include_next to pass through to libc's true
|
|
|
|
# implementations, so must appear before them in search order.
|
|
|
|
# in theory a correctly placed -idirafter could be used, but in
|
|
|
|
# practice the compiler may have been built with a --with-headers
|
|
|
|
# like option that forces the libc headers before all -idirafter,
|
|
|
|
# hence -isystem here.
|
|
|
|
+ optionalString includeFortifyHeaders' ''
|
|
|
|
echo "-isystem ${fortify-headers}/include" >> $out/nix-support/libc-cflags
|
2019-11-26 00:55:16 +00:00
|
|
|
'')
|
2017-08-23 20:55:55 +00:00
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## General libc++ support
|
|
|
|
##
|
2020-06-30 18:26:37 +00:00
|
|
|
|
|
|
|
# We have a libc++ directly, we have one via "smuggled" GCC, or we have one
|
|
|
|
# bundled with the C compiler because it is GCC
|
2020-09-07 19:08:11 +00:00
|
|
|
+ optionalString (libcxx != null || (useGccForLibs && gccForLibs.langCC or false) || (isGNU && cc.langCC or false)) ''
|
2020-06-30 18:26:37 +00:00
|
|
|
touch "$out/nix-support/libcxx-cxxflags"
|
|
|
|
touch "$out/nix-support/libcxx-ldflags"
|
2020-06-17 20:33:56 +00:00
|
|
|
''
|
2023-04-08 04:44:28 +00:00
|
|
|
# Adding -isystem flags should be done only for clang; gcc
|
|
|
|
# already knows how to find its own libstdc++, and adding
|
|
|
|
# additional -isystem flags will confuse gfortran (see
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/209870#issuecomment-1500550903)
|
|
|
|
+ optionalString (libcxx == null && isClang && (useGccForLibs && gccForLibs.langCC or false)) ''
|
2023-11-09 06:53:22 +00:00
|
|
|
for dir in ${gccForLibs}/include/c++/*; do
|
2020-04-14 00:44:43 +00:00
|
|
|
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
|
|
|
|
done
|
2023-11-09 06:53:22 +00:00
|
|
|
for dir in ${gccForLibs}/include/c++/*/${targetPlatform.config}; do
|
2020-04-14 00:44:43 +00:00
|
|
|
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
|
|
|
|
done
|
|
|
|
''
|
2023-01-13 20:03:29 +00:00
|
|
|
+ optionalString (libcxx.isLLVM or false) ''
|
2024-03-12 07:34:58 +00:00
|
|
|
echo "-isystem ${getDev libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
|
2020-04-14 00:44:43 +00:00
|
|
|
echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags
|
llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxxabi into libcxx (#292043)
- merge libcxxabi into libcxx for LLVM 12, 13, 14, 15, 16, 17, and git.
- remove the link time workaround `-lc++ -lc++abi` from 58 packages as it is no longer required.
- fixes https://github.com/NixOS/nixpkgs/issues/166205
- provides alternative fixes for. https://github.com/NixOS/nixpkgs/issues/269548 https://github.com/NixOS/nix/issues/9640
- pkgsCross.x86_64-freebsd builds work again
This change can be represented in 3 stages
1. merge libcxxabi into libcxx -- files: pkgs/development/compilers/llvm/[12, git]/{libcxx, libcxxabi}
2. update stdenv to account for merge -- files: stdenv.{adapters, cc.wrapper, darwin}
3. remove all references to libcxxabi outside of llvm (about 58 packages modified)
### merging libcxxabi into libcxx
- take the union of the libcxxabi and libcxx cmake flags
- eliminate the libcxx-headers-only package - it was only needed to break libcxx <-> libcxxabi circular dependency
- libcxx.cxxabi is removed. external cxxabi (freebsd) will symlink headers / libs into libcxx.
- darwin will re-export the libcxxabi symbols into libcxx so linking `-lc++` is sufficient.
- linux/freebsd `libc++.so` is a linker script `LINK(libc++.so.1, -lc++abi)` making `-lc++` sufficient.
- libcxx/default.nix [12, 17] are identical except for patches and `LIBCXX_ADDITIONAL_LIBRARIES` (only used in 16+)
- git/libcxx/defaul.nix does not link with -nostdlib when useLLVM is true so flag is removed. this is not much different than before as libcxxabi used -nostdlib where libcxx did not, so libc was linked in anyway.
### stdenv changes
- darwin bootstrap, remove references to libcxxabi and cxxabi
- cc-wrapper: remove c++ link workaround when libcxx.cxxabi doesn't exist (still exists for LLVM pre 12)
- adapter: update overrideLibcxx to account for a pkgs.stdenv that only has libcxx
### 58 package updates
- remove `NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}` as no longer needed
- swift, nodejs_v8 remove libcxxabi references in the clang override
https://github.com/NixOS/nixpkgs/pull/292043
2024-03-11 10:53:37 +00:00
|
|
|
''
|
2020-04-14 00:44:43 +00:00
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## Initial CFLAGS
|
|
|
|
##
|
|
|
|
|
|
|
|
# GCC shows ${cc_solib}/lib in `gcc -print-search-dirs', but not
|
|
|
|
# ${cc_solib}/lib64 (even though it does actually search there...)..
|
|
|
|
# This confuses libtool. So add it to the compiler tool search
|
|
|
|
# path explicitly.
|
2024-07-01 02:01:07 +00:00
|
|
|
+ optionalString (!nativeTools && !isArocc) ''
|
2017-08-23 20:55:55 +00:00
|
|
|
if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then
|
|
|
|
ccLDFlags+=" -L${cc_solib}/lib64"
|
|
|
|
ccCFlags+=" -B${cc_solib}/lib64"
|
|
|
|
fi
|
|
|
|
ccLDFlags+=" -L${cc_solib}/lib"
|
|
|
|
ccCFlags+=" -B${cc_solib}/lib"
|
|
|
|
|
2024-07-01 02:01:07 +00:00
|
|
|
'' + optionalString (cc.langAda or false && !isArocc) ''
|
2020-06-30 18:26:37 +00:00
|
|
|
touch "$out/nix-support/gnat-cflags"
|
|
|
|
touch "$out/nix-support/gnat-ldflags"
|
2019-05-11 21:16:17 +00:00
|
|
|
basePath=$(echo $cc/lib/*/*/*)
|
|
|
|
ccCFlags+=" -B$basePath -I$basePath/adainclude"
|
|
|
|
gnatCFlags="-I$basePath/adainclude -I$basePath/adalib"
|
|
|
|
|
2020-06-30 18:26:37 +00:00
|
|
|
echo "$gnatCFlags" >> $out/nix-support/gnat-cflags
|
2019-05-11 21:16:17 +00:00
|
|
|
'' + ''
|
2020-06-30 18:26:37 +00:00
|
|
|
echo "$ccLDFlags" >> $out/nix-support/cc-ldflags
|
|
|
|
echo "$ccCFlags" >> $out/nix-support/cc-cflags
|
2019-01-26 15:17:57 +00:00
|
|
|
'' + optionalString (targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false)) ''
|
2024-01-10 23:23:05 +00:00
|
|
|
echo " -L${libcxx_solib}" >> $out/nix-support/cc-ldflags
|
2020-06-30 15:04:10 +00:00
|
|
|
''
|
2017-08-23 20:55:55 +00:00
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## Man page and info support
|
|
|
|
##
|
|
|
|
+ optionalString propagateDoc ''
|
2018-09-05 18:35:16 +00:00
|
|
|
ln -s ${cc.man} $man
|
|
|
|
ln -s ${cc.info} $info
|
2024-07-01 02:01:07 +00:00
|
|
|
'' + optionalString (cc.langD or cc.langJava or false && !isArocc) ''
|
2019-09-20 10:05:57 +00:00
|
|
|
echo "-B${zlib}${zlib.libdir or "/lib/"}" >> $out/nix-support/libc-cflags
|
2014-10-10 11:49:26 +00:00
|
|
|
''
|
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## Hardening support
|
|
|
|
##
|
2014-10-10 11:49:26 +00:00
|
|
|
+ ''
|
2024-03-12 07:34:58 +00:00
|
|
|
export hardening_unsupported_flags="${concatStringsSep " " ccHardeningUnsupportedFlags}"
|
2017-06-20 18:04:24 +00:00
|
|
|
''
|
|
|
|
|
2024-02-27 18:30:29 +00:00
|
|
|
# For clang, this is handled in add-clang-cc-cflags-before.sh
|
2024-06-04 19:06:58 +00:00
|
|
|
+ lib.optionalString (!isClang && machineFlags != []) ''
|
|
|
|
printf "%s\n" ${lib.escapeShellArgs machineFlags} >> $out/nix-support/cc-cflags-before
|
2018-10-15 21:11:20 +00:00
|
|
|
''
|
|
|
|
|
2019-04-09 18:21:54 +00:00
|
|
|
# TODO: categorize these and figure out a better place for them
|
2023-04-26 14:03:11 +00:00
|
|
|
+ optionalString targetPlatform.isWindows ''
|
2019-04-09 18:21:54 +00:00
|
|
|
hardening_unsupported_flags+=" pic"
|
|
|
|
'' + optionalString targetPlatform.isMinGW ''
|
2021-08-11 09:07:42 +00:00
|
|
|
hardening_unsupported_flags+=" stackprotector fortify"
|
2019-04-09 18:21:54 +00:00
|
|
|
'' + optionalString targetPlatform.isAvr ''
|
|
|
|
hardening_unsupported_flags+=" stackprotector pic"
|
2022-07-20 08:38:08 +00:00
|
|
|
'' + optionalString (targetPlatform.libc == "newlib" || targetPlatform.libc == "newlib-nano") ''
|
2018-10-15 21:11:20 +00:00
|
|
|
hardening_unsupported_flags+=" stackprotector fortify pie pic"
|
2019-06-07 22:40:28 +00:00
|
|
|
'' + optionalString (targetPlatform.libc == "musl" && targetPlatform.isx86_32) ''
|
2019-06-07 08:07:18 +00:00
|
|
|
hardening_unsupported_flags+=" stackprotector"
|
2019-06-07 22:40:28 +00:00
|
|
|
'' + optionalString targetPlatform.isNetBSD ''
|
2019-04-09 18:21:54 +00:00
|
|
|
hardening_unsupported_flags+=" stackprotector fortify"
|
2019-05-11 21:16:17 +00:00
|
|
|
'' + optionalString cc.langAda or false ''
|
2020-12-23 00:42:11 +00:00
|
|
|
hardening_unsupported_flags+=" format stackprotector strictoverflow"
|
2019-09-20 10:05:57 +00:00
|
|
|
'' + optionalString cc.langD or false ''
|
|
|
|
hardening_unsupported_flags+=" format"
|
2022-05-26 10:14:43 +00:00
|
|
|
'' + optionalString cc.langFortran or false ''
|
|
|
|
hardening_unsupported_flags+=" format"
|
2019-09-20 10:05:57 +00:00
|
|
|
'' + optionalString targetPlatform.isWasm ''
|
2019-01-30 02:01:24 +00:00
|
|
|
hardening_unsupported_flags+=" stackprotector fortify pie pic"
|
2022-06-20 07:57:03 +00:00
|
|
|
'' + optionalString targetPlatform.isMicroBlaze ''
|
|
|
|
hardening_unsupported_flags+=" stackprotector"
|
2019-01-30 02:01:24 +00:00
|
|
|
''
|
|
|
|
|
2024-07-01 02:01:07 +00:00
|
|
|
+ optionalString (libc != null && targetPlatform.isAvr && !isArocc) ''
|
2024-03-14 19:09:11 +00:00
|
|
|
for isa in avr5 avr3 avr4 avr6 avr25 avr31 avr35 avr51 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 tiny-stack; do
|
|
|
|
echo "-B${getLib libc}/avr/lib/$isa" >> $out/nix-support/libc-crt1-cflags
|
|
|
|
done
|
|
|
|
''
|
|
|
|
|
2024-04-14 13:41:03 +00:00
|
|
|
+ optionalString targetPlatform.isDarwin ''
|
2021-04-10 04:11:28 +00:00
|
|
|
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags
|
2021-05-06 04:15:34 +00:00
|
|
|
''
|
|
|
|
|
|
|
|
+ optionalString targetPlatform.isAndroid ''
|
2024-09-10 22:06:52 +00:00
|
|
|
echo "-D__ANDROID_API__=${targetPlatform.androidSdkVersion}" >> $out/nix-support/cc-cflags
|
2021-04-10 04:11:28 +00:00
|
|
|
''
|
|
|
|
|
2020-02-27 15:39:35 +00:00
|
|
|
# There are a few tools (to name one libstdcxx5) which do not work
|
|
|
|
# well with multi line flags, so make the flags single line again
|
2017-06-20 18:04:24 +00:00
|
|
|
+ ''
|
2020-06-30 18:26:37 +00:00
|
|
|
for flags in "$out/nix-support"/*flags*; do
|
2020-04-14 00:44:43 +00:00
|
|
|
substituteInPlace "$flags" --replace $'\n' ' '
|
|
|
|
done
|
2020-02-27 15:39:35 +00:00
|
|
|
|
2017-06-26 04:43:06 +00:00
|
|
|
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
|
|
|
|
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
|
2020-09-07 14:31:59 +00:00
|
|
|
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
|
2024-10-25 18:41:08 +00:00
|
|
|
substituteAll ${../wrapper-common/darwin-sdk-setup.bash} $out/nix-support/darwin-sdk-setup.bash
|
2015-07-20 11:42:30 +00:00
|
|
|
''
|
2018-02-01 00:00:00 +00:00
|
|
|
|
2023-01-06 02:29:46 +00:00
|
|
|
+ optionalString cc.langAda or false ''
|
|
|
|
substituteAll ${./add-gnat-extra-flags.sh} $out/nix-support/add-gnat-extra-flags.sh
|
|
|
|
''
|
|
|
|
|
2022-06-13 18:24:52 +00:00
|
|
|
##
|
|
|
|
## General Clang support
|
|
|
|
## Needs to go after ^ because the for loop eats \n and makes this file an invalid script
|
|
|
|
##
|
|
|
|
+ optionalString isClang ''
|
2024-02-27 18:30:29 +00:00
|
|
|
# Escape twice: once for this script, once for the one it gets substituted into.
|
2024-06-04 19:06:58 +00:00
|
|
|
export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)}
|
2022-06-13 18:24:52 +00:00
|
|
|
export defaultTarget=${targetPlatform.config}
|
|
|
|
substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh
|
|
|
|
''
|
|
|
|
|
2020-06-30 15:04:10 +00:00
|
|
|
##
|
|
|
|
## Extra custom steps
|
|
|
|
##
|
2022-04-30 02:54:03 +00:00
|
|
|
+ extraBuildCommands
|
2024-03-12 07:34:58 +00:00
|
|
|
+ concatStringsSep "; "
|
|
|
|
(mapAttrsToList
|
2022-04-30 02:54:03 +00:00
|
|
|
(name: value: "echo ${toString value} >> $out/nix-support/${name}")
|
|
|
|
nixSupport);
|
2014-10-10 11:49:26 +00:00
|
|
|
|
2017-07-01 00:27:48 +00:00
|
|
|
|
2022-12-06 22:08:33 +00:00
|
|
|
env = {
|
2023-07-15 05:35:50 +00:00
|
|
|
inherit isClang;
|
|
|
|
|
2022-12-06 22:08:33 +00:00
|
|
|
# for substitution in utils.bash
|
2024-04-16 15:44:08 +00:00
|
|
|
# TODO(@sternenseemann): invent something cleaner than passing in "" in case of absence
|
2024-09-12 04:58:28 +00:00
|
|
|
expandResponseParams = lib.optionalString (expand-response-params != "") (lib.getExe expand-response-params);
|
2024-04-11 22:14:16 +00:00
|
|
|
# TODO(@sternenseemann): rename env var via stdenv rebuild
|
|
|
|
shell = getBin runtimeShell + runtimeShell.shellPath or "";
|
2023-06-24 18:19:19 +00:00
|
|
|
gnugrep_bin = optionalString (!nativeTools) gnugrep;
|
2024-10-18 17:50:27 +00:00
|
|
|
rm = if nativeTools then "rm" else lib.getExe' coreutils "rm";
|
|
|
|
mktemp = if nativeTools then "mktemp" else lib.getExe' coreutils "mktemp";
|
2023-02-18 18:44:44 +00:00
|
|
|
# stdenv.cc.cc should not be null and we have nothing better for now.
|
|
|
|
# if the native impure bootstrap is gotten rid of this can become `inherit cc;` again.
|
2023-06-24 18:19:19 +00:00
|
|
|
cc = optionalString (!nativeTools) cc;
|
2022-12-07 04:16:50 +00:00
|
|
|
wrapperName = "CC_WRAPPER";
|
2023-02-18 18:44:44 +00:00
|
|
|
inherit suffixSalt coreutils_bin bintools;
|
2022-12-07 04:16:50 +00:00
|
|
|
inherit libc_bin libc_dev libc_lib;
|
2024-10-25 18:41:08 +00:00
|
|
|
inherit darwinPlatformForCC;
|
2023-10-02 18:38:56 +00:00
|
|
|
default_hardening_flags_str = builtins.toString defaultHardeningFlags;
|
2024-10-25 18:41:08 +00:00
|
|
|
} // lib.mapAttrs (_: lib.optionalString targetPlatform.isDarwin) {
|
|
|
|
# These will become empty strings when not targeting Darwin.
|
|
|
|
inherit (targetPlatform) darwinMinVersion darwinMinVersionVariable;
|
2024-09-29 17:54:47 +00:00
|
|
|
} // lib.optionalAttrs (apple-sdk != null && stdenvNoCC.targetPlatform.isDarwin) {
|
|
|
|
# Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`.
|
|
|
|
fallback_sdk = apple-sdk.__spliced.buildTarget or apple-sdk;
|
2022-12-06 22:08:33 +00:00
|
|
|
};
|
2010-12-04 21:45:37 +00:00
|
|
|
|
2009-03-25 18:34:27 +00:00
|
|
|
meta =
|
2024-03-12 07:34:58 +00:00
|
|
|
let cc_ = optionalAttrs (cc != null) cc; in
|
|
|
|
(optionalAttrs (cc_ ? meta) (removeAttrs cc.meta ["priority"])) //
|
|
|
|
{ description = attrByPath ["meta" "description"] "System C compiler" cc_ + " (wrapper script)";
|
2019-02-01 01:07:55 +00:00
|
|
|
priority = 10;
|
2024-06-30 15:13:51 +00:00
|
|
|
mainProgram = if name != "" then name else "${targetPrefix}${ccName}";
|
2017-07-18 03:36:17 +00:00
|
|
|
};
|
2008-06-26 11:07:46 +00:00
|
|
|
}
|