diff --git a/doc/release-notes/rl-2511.section.md b/doc/release-notes/rl-2511.section.md index c50ae7739abdb..4fec7971c26fb 100644 --- a/doc/release-notes/rl-2511.section.md +++ b/doc/release-notes/rl-2511.section.md @@ -9,6 +9,9 @@ and newer series. However, embedded chips without LSX (Loongson SIMD eXtension), such as 2K0300 SoC, are not supported. `pkgsCross.loongarch64-linux-embedded` can be used to build software and systems for these platforms. +- Added `cc` as a path towards providing a C compiler without inheriting it inside the standard environment. + Packages which wish to pick a compiler can explicitly do it or utilize the new `ccChooser`. + ## Backward Incompatibilities {#sec-nixpkgs-release-25.11-incompatibilities} diff --git a/pkgs/by-name/ma/makeBinaryWrapper/package.nix b/pkgs/by-name/ma/makeBinaryWrapper/package.nix index 749851d547e2c..50f649d9cb71f 100644 --- a/pkgs/by-name/ma/makeBinaryWrapper/package.nix +++ b/pkgs/by-name/ma/makeBinaryWrapper/package.nix @@ -5,7 +5,7 @@ dieHook, writeShellScript, tests, - cc ? targetPackages.stdenv.cc, + cc, sanitizers ? [ ], }: diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index 69ea14be5c83d..940085e80d4cd 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -103,30 +103,7 @@ lib.init bootStages 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; - + cc = buildPackages.ccChooser crossSystem buildPackages null; }; in if config ? replaceCrossStdenv then diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index d7f4145ed3b95..dba776d69418c 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -594,6 +594,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check overrides = self: super: { inherit (prevStage) ccWrapperStdenv cctools ld64; + # TODO: change this when CC is no longer provided by the stdenv + inherit (self.stdenv) cc; + binutils-unwrapped = builtins.throw "nothing in the Darwin bootstrap should depend on GNU binutils"; curl = builtins.throw "nothing in the Darwin bootstrap can depend on curl"; @@ -735,6 +738,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check { inherit (prevStage) ccWrapperStdenv; + # TODO: change this when CC is no longer provided by the stdenv + inherit (self.stdenv) cc; + # Disable ld64’s install check phase because the required LTO libraries are not built yet. ld64 = super.ld64.overrideAttrs { doInstallCheck = false; }; @@ -800,6 +806,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check { inherit (prevStage) ccWrapperStdenv; + # TODO: change this when CC is no longer provided by the stdenv + inherit (self.stdenv) cc; + # Avoid an infinite recursion due to the SDK’s including ncurses, which depends on bash in its `dev` output. bashNonInteractive = super.bashNonInteractive.override { stdenv = self.darwin.bootstrapStdenv; }; @@ -884,6 +893,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check { inherit (prevStage) ccWrapperStdenv; + # TODO: change this when CC is no longer provided by the stdenv + inherit (self.stdenv) cc; + # Disable tests because they use dejagnu, which fails to run. libffi = super.libffi.override { doCheck = false; }; @@ -965,6 +977,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check { inherit (prevStage) ccWrapperStdenv; + # TODO: change this when CC is no longer provided by the stdenv + inherit (self.stdenv) cc; + # Rebuild locales and sigtool with the new clang. darwin = super.darwin.overrideScope ( _: superDarwin: @@ -1204,6 +1219,8 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check patch ; + inherit cc; + "apple-sdk_${sdkMajorVersion}" = self.apple-sdk; darwin = super.darwin.overrideScope ( diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 899a667a781ec..e6076468931ee 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8197,6 +8197,44 @@ with pkgs; null; # We can choose: + ccChooser = + platform: pkgs: fallback: + let + # TODO: use cc when https://github.com/NixOS/nixpkgs/pull/365057 is merged + inherit (platform) useLLVM isDarwin isGhcjs; + useArocc = platform.useArocc or false; + useZig = platform.useZig or false; + useiOSPrebuilt = platform.useiOSPrebuilt or false; + useAndroidPrebuilt = platform.useAndroidPrebuilt or false; + in + if useiOSPrebuilt then + pkgs.darwin.iosSdkPkgs.clang or fallback + else if useAndroidPrebuilt then + pkgs."androidndkPkgs_${platform.androidNdkVersion}".clang or fallback + else if isGhcjs then + # 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. + # NOTE: maybe we remove this and return null instead? + throw "no C compiler provided for this platform" + else if isDarwin then + pkgs.llvmPackages.libcxxClang or fallback + else if useArocc then + pkgs.arocc or fallback + else if useZig then + pkgs.zig.cc or fallback + else if useLLVM then + pkgs.llvmPackages.clang or fallback + else + # NOTE: we shouldn't imply GCC, ideally we should either fallback, null, or error. + pkgs.gcc or fallback; + + # The default C compiler to use, this has been provided by the stdenv for a long time. + # However, we're working to move it out of the stdenv. It is recommended to switch to + # this attribute and using an "stdenvNoCC" as soon as possible. + cc = ccChooser stdenv.targetPlatform pkgs null; + libc = let inherit (stdenv.hostPlatform) libc; diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index 22cc2ce290e86..679ca56b7fa44 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -72,12 +72,14 @@ let buildPackages.binutils = nativePlatforms; buildPackages.gcc = nativePlatforms; libc = nativePlatforms; + cc = nativePlatforms; }; common = { buildPackages.binutils = nativePlatforms; gmp = nativePlatforms; libc = nativePlatforms; + cc = nativePlatforms; nix = nativePlatforms; nixVersions.git = nativePlatforms; mesa = nativePlatforms;