Commit Graph

166 Commits

Author SHA1 Message Date
Randy Eckenrode
0e61488c5b
overrideSDK: update for the new SDK
Change the adapter to add the requested SDK to the target’s build
inputs. Note that only the “11.0” (i.e., 11.3) and 12.3 SDKs are
supported. This adapter is retained for compatibility. The preferred way
to override the SDK is to add it to the appropriate inputs directly.
2024-10-10 16:23:08 -04:00
Randy Eckenrode
1c26a2fabc
makeStaticDarwin: handle when env.NIX_CFLAGS_LINK is set 2024-10-10 16:23:08 -04:00
Randy Eckenrode
66fcbb94e7
makeStaticDarwin: drop darwin-portable-libSystem-hook
`${stdenv.cc.libc}/lib/libSystem.B.dylib` does not exist and not existed
for as long as I have used nixpkgs. Since `/usr/lib/libSystem.B.dylib`
is already linked via text-based stubs, continue relying on those.
2024-10-10 16:23:08 -04:00
Randy Eckenrode
b7442b9066
darwin.stdenv: provide an SDK when cross-compiling
Static can rely on the standard cross-SDK because it will be a static
SDK when building for static targets.
2024-10-10 16:23:04 -04:00
Azat Bahawi
e8f0b7b782
stdenv: throw when using mold for targeting darwin
Mold does not support linking Mach-O, but still can be used on MacOS to
emit ELF.

Fixes: #338970
2024-09-02 13:59:59 +03:00
adisbladis
f4579bdf8d stdenv: Fix args.env.NIX_CFLAGS_LINK/args.NIX_CFLAGS_LINK typo 2024-08-07 18:49:56 +12:00
adisbladis
00b9996c9a stdenv: Take nested env.NIX_CFLAGS_LINK into account when making static binaries
https://github.com/NixOS/nixpkgs/pull/315998/files#diff-2828f66a476875b1160e3c241960db085c2a3933211cc187bcd1fb456fb95e7fL213-R216 moved NIX_CFLAGS_LINK from a top-level `mkDerivation` argument to the nested `env` attribute.

This doesn't play nicely with how `stdenv/adapters.nix` adds it's NIX_CFLAGS_LINK in the top-level.

This changes the stdenv adapter to check for the presence of `env.NIX_CFLAGS_LINK`, and override that one if present, and only otherwise override on the top-level drv attrset.
2024-08-03 23:26:42 +12:00
John Ericson
744d7e7477 *bsdCross: Remove these package sets
I realized what rhelmot did in 61202561d9
(specify what packages just need `stdenvNoLibc`) is definitely the right
approach for this, and adjusted NetBSD and OpenBSD to likewise use it.
With that change, we don't need these confusing and ugly `*bsdCross`
package sets at all!

We can get rid of a lot more libc-related `*Cross`, and I will do so
soon, but this is the first step.

(adapted from commit 51f1ecaa59)
2024-06-21 11:47:36 -04:00
Vladimír Čunát
879821772c
Revert #320852: Clean up cross bootstrapping
It rebuilt stdenv on *-darwin; we can't do that in nixpkgs master.
This reverts commit 2f20501c5f, reversing
changes made to fd469c24af.
2024-06-21 07:48:24 +02:00
John Ericson
51f1ecaa59 Clean up cross bootstrapping
For a long time, we've had `crossLibcStdenv`, `*Cross` libc attributes,
and `*bsdCross` pre-libc package sets. This was always bad because
having "cross" things is "not declarative": the naming doesn't reflect
what packages *need* but rather how we *provide* something. This is
ugly, and creates needless friction between cross and native building.

Now, almost all of these `*Cross` attributes are gone: just these are
kept:

- Glibc's and Musl's are kept, because those packages are widely used
  and I didn't want to risk changing the native builds of those at this
  time.

- generic `libcCross`, `theadsCross`, and friends, because these relate
  to the convolulted GCC bootstrap which still needs to be redone.

The BSD and obscure Linux or freestnanding libcs have conversely all
been made to use a new `stdenvNoLibc`, which is like the old
`crossLibcStdenv` except:

1. It usable for native and cross alike

2. It named according to what it *is* ("a standard environment without
   libc but with a C compiler"), rather than some non-compositional
   jargon ("the stdenv used for building libc when cross compiling",
   yuck).

I should have done this change long ago, but I was stymied because of
"infinite recursions". The problem was that in too many cases we are
overriding `stdenv` to *remove* things we don't need, and this risks
cyles since those more minimal stdenvs are used to build things in the
more maximal stdenvs.

The solution is to pass `stage.nix` `stdenvNoCC`, so we can override to
*build up* rather than *tear down*. For now, the full `stdenv` is also
passed, so I don't need to change the native bootstraps, but I can see
this changing as we make things more uniform and clean those up.

Finally, the BSDs also had to be cleaned up, since they have a few
pre-libc dependencies, demanding a systematic approach. I realized what
rhelmot did in 61202561d9 (specify what
packages just need `stdenvNoLibc`) is definitely the right approach for
this, and adjusted NetBSD and OpenBSD to likewise use it.
2024-06-18 17:04:16 -04:00
Randy Eckenrode
f61e189ad3
overrideSDK: support all deps attributes
This is effectively a rewrite of `overrideSDK`. It was required because
`wrapGAppsHook` propagates `depsTargetTarget` with the expectation that
it will effectively be `buildInputs` when the hook is itself used as a
`nativeBuildInput`. This propagates Gtk, which itself propagates the
default Dariwn SDK, making it effectively impossible to override the SDK
when a package depends on Gtk and uses `wrapGAppsHook`.

This rewrite implements the following improvements:

* Cross-compilation should be supported correctly (untested);
* Supports public and private frameworks;
* Supports SDK `libs`;
* Remaps instead of replacing extra (native) build inputs in the stdenv;
* Updates any Darwin framework references in `nix-support`; and
* It updates `xcodebuild` regardless of which input its in.

The implementation avoids recursion for performance reasons. Instead, it
enumerates transitive dependencies and walks the list from the leaf
packages backwards to the parent packages.
2024-03-29 10:03:08 -04:00
Robert Hensing
8f6b396c49
Merge pull request #297711 from hercules-ci/rename-adapters-finalAttrs
pkgs/stdenv/adapters.nix: Rename internal name
2024-03-21 17:15:28 +01:00
Robert Hensing
8da01484cd pkgs/stdenv/adapters.nix: Rename internal name
`finalAttrs` is never the first argument. This should have been
called `prevAttrs` all along.
It confused me for a bit, because the callback _must not_ be strict
in `finalAttrs` (the first of _two_ parameters), or it will
recurse infinitely while trying to figure out what the attrNames are.
2024-03-21 13:51:50 +01:00
github-actions[bot]
36232fff71
Merge master into staging-next 2024-03-20 18:01:02 +00:00
Connor Baker
e871fcf859 stdenvAdapters.useLibsFrom: use targetStdenv.cc.override
As @SomeoneSerge pointed out in https://github.com/NixOS/nixpkgs/pull/281371#discussion_r1531174155,
by avoiding `wrapCCWith` and using `targetStdenv.cc.override`, we avoid roundtrip wrapping and
are able to use `coreutils` from `targetStdenv`.
2024-03-20 16:02:08 +00:00
github-actions[bot]
c160165e60
Merge master into staging-next 2024-03-14 18:01:26 +00:00
Robert Hensing
de516f6f13 make-derivation.nix: Return mkDerivation as an attribute 2024-03-11 17:06:02 +01:00
a-n-n-a-l-e-e
ce789e7e35
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 03:53:37 -07:00
Someone Serge
e6e279913c
stdenvAdapters.useLibsFrom: init 2024-01-12 17:38:00 +00:00
Weijia Wang
2f9e98ccf3 Merge branch 'master' into staging-next 2024-01-10 23:12:44 +01:00
Sergei Trofimovich
55249c817f stdenv.adapters: fixx overrideLibcxx to refer to existing compiler-rt
Before the change `pkgsLLVM` attributes were failing to pull in
`compiler-rt` on `x86_64-linux`:

    $ nix build --no-link -f. pkgsLLVM.asciidoc-full
    error:
       error: attribute 'llvmPackages_13' missing

       at pkgs/stdenv/adapters.nix:86:32:

           85|       inherit libcxx;
           86|       extraPackages = [ cxxabi pkgs.pkgsTargetTarget."llvmPackages_${lib.versions.major llvmLibcxxVersion}".compiler-rt ];
             |                                ^
           87|     });

It happens because `pkgs.pkgsTargetTarget` are always empty for
cross-packages like `pkgsLLVM.`, `pkgsCross.*.` or
`--arg crossSystem '...'`.
2024-01-07 22:11:49 +00:00
Robert Scott
dc2247a3b5 stdenvAdapters: add withDefaultHardeningFlags 2023-12-09 16:32:15 +00:00
Weijia Wang
023d20ae64
Merge pull request #265307 from reckenrode/clang16-fixes-batch2
rubyPackages.iconv, v8: fix build with clang 16
2023-11-04 17:14:36 +01:00
Randy Eckenrode
98b8d3474b
stdenvAdapters.overrideSDK: special case the 10.12 Libsystem
The 10.12 Libsystem is not located as a sub-attribute of
`darwin.apple_sdk_10_12`. This will be fixed as part of the SDK changes
planned for post-23.11. In the meantime, special case it so the adapter
can be used to change the deployment target.
2023-11-04 01:47:58 -04:00
Randy Eckenrode
cc4fcc147b
stdenvAdapters: add overrideLibcxx
This was taken from #264091 to use in the interim before that PR lands
(sometime after the release of 23.11). It allows different versions of
clang to link the same libc++, allowing dependencies to be linked when
they are built with a different version of clang than the stdenv.
2023-11-03 23:11:32 -04:00
Randy Eckenrode
08e1c95e9c
stdenvAdapters.overrideSDK: handle non-drv nativeBuildInputs 2023-11-01 12:30:26 -04:00
Randy Eckenrode
b6a14a3a84
stdenvAdapters.overrideSDK: also remap propagatedBuildInputs 2023-11-01 09:06:44 -04:00
Randy Eckenrode
50d046c32a
stdenvAdapters.overrideSDK: update the SDK version recursively
Update all propagated build inputs recursively, so that propagated
inputs with propagated inputs use the correct SDK.
2023-11-01 09:06:44 -04:00
Randy Eckenrode
3440df992e
stdenvAdapters.overrideSDK: override xcodebuild to use the requested SDK 2023-10-31 00:18:54 -04:00
Randy Eckenrode
c2a623b52a
stdenvAdapters: add overrideSDK
This is a replacement for using `darwin.apple_sdk_<ver>.callPackage`.
Instead of injecting the required packages, it provides a stdenv adapter
that modifies the derivation’s build inputs to use the requested SDK
versions. This modification extends to any build inputs propagated to it
as well. The `callPackage` approach is not deprecated yet, but it is
expected that it will be eventually.

Note that this is an MVP. It should work with most packages, but it only
handles build inputs and also only handles frameworks. Once more SDKs
are added (after #229210 is merged) and the SDK structure is normalized,
it can be extended to handle any package in the SDK namespace.

Cross-compilation may or may not work. Any cross-related issues can be
addressed after #256590 is merged.
2023-10-26 13:26:39 -04:00
github-actions[bot]
34db746ff9
Merge staging-next into staging 2023-10-20 06:35:22 +00:00
Pavel Sobolev
17acba4cd1
stdenvAdapters.useMoldLinker: set allowedRequisites to null 2023-10-19 15:48:42 +03:00
github-actions[bot]
c68d98e9d4
Merge staging-next into staging 2023-10-13 18:01:31 +00:00
Artturin
e64d24fff4
stdenvAdapters.useMoldLinker: automatically add allowedRequisites
Co-Authored-By: Pavel Sobolev <paveloom@riseup.net>
2023-10-13 10:14:40 +03:00
github-actions[bot]
49523dec15
Merge staging-next into staging 2023-10-13 06:01:45 +00:00
Artturin
77bf1395d6 mold: add tests for mold-wrapped and useMoldLinker adapter
Make both ready for cross with prefixes

Currently
`pkgsCross.aarch64-multiplatform.mold.passthru.tests.{wrapped,adapter}`
fail with

```
Testing running the 'hello' binary which should be linked with 'mold'
Hello, world!
Checking for mold in the '.comment' section
No mention of 'mold' detected in the '.comment' section
The command was:
aarch64-unknown-linux-gnu-readelf -p .comment ...bin/hello
The output was:
String dump of section '.comment':
  [     0]  GCC: (GNU) 12.3.0
```
2023-10-13 05:23:32 +03:00
Peter Waller
9fdf395cc7 makeStaticBinaries: Set -DCMAKE_SKIP_INSTALL_RPATH
Without this, you get error messages during the install phase along the
lines of: "file RPATH_CHANGE could not write new RPATH:".

This is unsurprising because the static binaries do not have any dynamic
linker and thus, no runpath to rewrite either.

Tell cmake it doesn't need to do RPATH manipulation by passing
cmakeFlags.

While we're here, I also renamed `finalAttrs` to `args` and fixed the
indentation; this improves consistency with the surrounding code and
eliminates a point of confusion: because it was named `finalAttrs` I
presumed I should be able to influence it with an overrideAttrs setting
dontAddStaticConfigureFlags, but this turns out not to be possible;
adding prevAttrs as well doesn't work because of a limitation of
overrideAttrs whereby it gives an infinite recursion if the set of
attribute keys being returned depends on finalAttrs.

Signed-off-by: Peter Waller <p@pwaller.net>
2023-09-03 18:30:59 +01:00
Artturin
29b4a92458 stdenvAdapters: Remove 6 year old comment
Comment was added in 3c36dcc and hasn't been needed because makeStaticBinaries already adds glibc.static
2023-07-21 00:49:44 +03:00
Artturin
cb29bc6ace stdenvAdapters: Fix condition
Fixes issue 244232
2023-07-21 00:49:40 +03:00
Randy Eckenrode
feb89eed00
darwin.stdenv: fix portable libsystem hook with sandboxing
When sandboxing is enabled, the hook tries to run `install_name_tool`
and fails because the system one is inaccessible. Having it use
`targetPrefix` allows it to find and use the cross-install_name_tool.
2023-07-08 20:49:49 -06:00
figsoda
34181be024 stdenvAdapters: don't use lib.optional with a list 2023-07-03 21:20:17 -04:00
Uri Baghin
fd8e2ca0df stdenv: fix makeStaticDarwin not composing with stdenvNoCC 2023-06-22 15:33:54 +10:00
Artturin
67a84d1428 stdenvAdapters: fix preservation of env.NIX_CFLAGS_COMPILE
we have managed to migrate to NIX_CFLAGS_COMPILE to the env attrset well
enough that we don't need to support having it toplevel. mkDerivation
will throw if there's a attr in both env and toplevel so no need to
worry about that
2023-04-12 21:27:34 +03:00
Artturin
9adf83737f stdenvAdapters: fix preservation of env 2023-04-11 21:25:52 +03:00
github-actions[bot]
3cdd771820
Merge staging-next into staging 2023-02-23 18:01:49 +00:00
Artturin
f9fdf2d402 treewide: move NIX_CFLAGS_COMPILE to the env attrset
with structuredAttrs lists will be bash arrays which cannot be exported
which will be a issue with some patches and some wrappers like cc-wrapper

this makes it clearer that NIX_CFLAGS_COMPILE must be a string as lists
in env cause a eval failure
2023-02-22 21:23:04 +02:00
Artturin
299a7bd35e stdenvAdapters: add useMoldLinker 2023-02-17 06:35:24 +02:00
Alyssa Ross
0ae87d514f treewide: add names to all setup hooks 2023-01-19 15:00:36 +00:00
pennae
abd2e87da1 stdenv: remove deprecated adapters 2022-08-26 16:25:44 +02:00
Robert Hensing
dd770cc211 stdenv/adapters.nix: Fix for overlay style arguments 2022-06-05 13:54:03 +02:00