stdenv: Introduce hasCC attribute
Before, we'd always use `cc = null`, and check for that. The problem is this breaks for cross compilation to platforms that don't support a C compiler. It's a very subtle issue. One might think there is no problem because we have `stdenvNoCC`, and presumably one would only build derivations that use that. The problem is that one still wants to use tools at build-time that are themselves built with a C compiler, and those are gotten via "splicing". The runtime version of those deps will explode, but the build time / `buildPackages` versions of those deps will be fine, and splicing attempts to work this by using `builtins.tryEval` to filter out any broken "higher priority" packages (runtime is the default and highest priority) so that both `foo` and `foo.nativeDrv` works. However, `tryEval` only catches certain evaluation failures (e.g. exceptions), and not arbitrary failures (such as `cc.attr` when `cc` is null). This means `tryEval` fails to let us use our build time deps, and everything comes apart. The right solution is, as usually, to get rid of splicing. Or, baring that, to make it so `foo` never works and one has to explicitly do `foo.*`. But that is a much larger change, and certaily one unsuitable to be backported to stable. Given that, we instead make an exception-throwing `cc` attribute, and create a `hasCC` attribute for those derivations which wish to condtionally use a C compiler: instead of doing `stdenv.cc or null == null` or something similar, one does `stdenv.hasCC`. This allows quering without "tripping" the exception, while also allowing `tryEval` to work. No platform without a C compiler is yet wired up by default. That will be done in a following commit.
This commit is contained in:
parent
5858d7229a
commit
63bd851e95
4 changed files with 16 additions and 6 deletions
|
@ -66,7 +66,7 @@ let
|
|||
else null;
|
||||
|
||||
expand-response-params =
|
||||
if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
|
||||
if buildPackages ? stdenv && buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
|
||||
then import ../expand-response-params { inherit (buildPackages) stdenv; }
|
||||
else "";
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ let
|
|||
infixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
|
||||
|
||||
expand-response-params =
|
||||
if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
|
||||
if buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
|
||||
then import ../expand-response-params { inherit (buildPackages) stdenv; }
|
||||
else "";
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ let
|
|||
substituteInPlace "$out"/lib/perl5/*/*/Config_heavy.pl \
|
||||
--replace "${libcInc}" /no-such-path \
|
||||
--replace "${
|
||||
if stdenv.cc.cc or null != null then stdenv.cc.cc else "/no-such-path"
|
||||
if stdenv.hasCC then stdenv.cc.cc else "/no-such-path"
|
||||
}" /no-such-path \
|
||||
--replace "${stdenv.cc}" /no-such-path \
|
||||
--replace "$man" /no-such-path
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
let lib = import ../../../lib; in lib.makeOverridable (
|
||||
|
||||
{ name ? "stdenv", preHook ? "", initialPath, cc, shell
|
||||
{ name ? "stdenv", preHook ? "", initialPath
|
||||
|
||||
, # If we don't have a C compiler, we might either have `cc = null` or `cc =
|
||||
# throw ...`, but if we do have a C compiler we should definiely have `cc !=
|
||||
# null`.
|
||||
#
|
||||
# TODO(@Ericson2314): Add assert without creating infinite recursion
|
||||
hasCC ? cc != null, cc
|
||||
|
||||
, shell
|
||||
, allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
|
||||
|
||||
, # The `fetchurl' to use for downloading curl and its dependencies
|
||||
|
@ -57,7 +66,8 @@ let
|
|||
../../build-support/setup-hooks/move-sbin.sh
|
||||
../../build-support/setup-hooks/move-lib64.sh
|
||||
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
|
||||
cc
|
||||
# TODO use lib.optional instead
|
||||
(if hasCC then cc else null)
|
||||
];
|
||||
|
||||
defaultBuildInputs = extraBuildInputs;
|
||||
|
@ -145,7 +155,7 @@ let
|
|||
|
||||
inherit overrides;
|
||||
|
||||
inherit cc;
|
||||
inherit cc hasCC;
|
||||
}
|
||||
|
||||
# Propagate any extra attributes. For instance, we use this to
|
||||
|
|
Loading…
Reference in a new issue