nixpkgs/pkgs/stdenv/cross/default.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

140 lines
4.2 KiB
Nix

{
lib,
localSystem,
crossSystem,
config,
overlays,
crossOverlays ? [ ],
}:
let
bootStages = import ../. {
inherit lib localSystem overlays;
crossSystem = localSystem;
crossOverlays = [ ];
# Ignore custom stdenvs when cross compiling for compatibility
# Use replaceCrossStdenv instead.
config = builtins.removeAttrs config [ "replaceStdenv" ];
};
in
lib.init bootStages
++ [
# Regular native packages
(
somePrevStage:
lib.last bootStages somePrevStage
// {
# It's OK to change the built-time dependencies
allowCustomOverrides = true;
}
)
# Build tool Packages
(vanillaPackages: {
inherit config overlays;
selfBuild = false;
stdenv =
assert vanillaPackages.stdenv.buildPlatform == localSystem;
assert vanillaPackages.stdenv.hostPlatform == localSystem;
assert vanillaPackages.stdenv.targetPlatform == localSystem;
vanillaPackages.stdenv.override { targetPlatform = crossSystem; };
# It's OK to change the built-time dependencies
allowCustomOverrides = true;
})
# Run Packages
(
buildPackages:
let
adaptStdenv = if crossSystem.isStatic then buildPackages.stdenvAdapters.makeStatic else lib.id;
stdenvNoCC = adaptStdenv (
buildPackages.stdenv.override (old: rec {
buildPlatform = localSystem;
hostPlatform = crossSystem;
targetPlatform = crossSystem;
# Prior overrides are surely not valid as packages built with this run on
# a different platform, and so are disabled.
overrides = _: _: { };
extraBuildInputs = [ ]; # Old ones run on wrong platform
allowedRequisites = null;
cc = null;
hasCC = false;
extraNativeBuildInputs =
old.extraNativeBuildInputs
++ lib.optionals (hostPlatform.isLinux && !buildPlatform.isLinux) [ buildPackages.patchelf ]
++ lib.optional (
let
f =
p:
!p.isx86
|| builtins.elem p.libc [
"musl"
"wasilibc"
"relibc"
]
|| p.isiOS
|| p.isGenode;
in
f hostPlatform && !(f buildPlatform)
) buildPackages.updateAutotoolsGnuConfigScriptsHook;
})
);
in
{
inherit config;
overlays = overlays ++ crossOverlays;
selfBuild = false;
inherit stdenvNoCC;
stdenv =
let
inherit (stdenvNoCC) hostPlatform targetPlatform;
baseStdenv = stdenvNoCC.override {
# Old ones run on wrong platform
extraBuildInputs = lib.optionals hostPlatform.isDarwin [
buildPackages.targetPackages.apple-sdk
];
hasCC = !stdenvNoCC.targetPlatform.isGhcjs;
cc =
if crossSystem.useiOSPrebuilt or false then
buildPackages.darwin.iosSdkPkgs.clang
else if crossSystem.useAndroidPrebuilt or false then
buildPackages."androidndkPkgs_${crossSystem.androidNdkVersion}".clang
else if
targetPlatform.isGhcjs
# Need to use `throw` so tryEval for splicing works, ugh. Using
# `null` or skipping the attribute would cause an eval failure
# `tryEval` wouldn't catch, wrecking accessing previous stages
# when there is a C compiler and everything should be fine.
then
throw "no C compiler provided for this platform"
else if crossSystem.isDarwin then
buildPackages.llvmPackages.libcxxClang
else if crossSystem.useLLVM or false then
buildPackages.llvmPackages.clang
else if crossSystem.useZig or false then
buildPackages.zig.cc
else if crossSystem.useArocc or false then
buildPackages.arocc
else
buildPackages.gcc;
};
in
if config ? replaceCrossStdenv then
config.replaceCrossStdenv { inherit buildPackages baseStdenv; }
else
baseStdenv;
}
)
]