Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv: throw from ghcjs.cc.outputs rather than ghcjs.cc #208993

Closed
wants to merge 1 commit into from
Closed

stdenv: throw from ghcjs.cc.outputs rather than ghcjs.cc #208993

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 4, 2023

Description of changes

pkgsCross.ghcjs.stdenv.cc currently throws, and it is (a good) part of the Nix semantics that exceptions transmit no information to an enclosing tryEval. This makes it impossible to express the fact that the answer to "is the C compiler from GNU?" should be false when no compiler exists.

The reason why pkgsCross.ghcjs.stdenv.cc is a throw is explained here:

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"

which refers to this check in splice.nix:

tryGetOutputs = value0: let
inherit (builtins.tryEval value0) success value;
in getOutputs (lib.optionalAttrs success value);
getOutputs = value: lib.genAttrs
(value.outputs or (lib.optional (value ? out) "out"))
(output: value.${output});

Since the result of that check is always passed to getOutputs, which is strict in its argument's outputs attribute, we can simply move the throw deeper into the stdenv.cc attrset. This leaves room to provide a useful value for attributes like isGNU and isClang when the compiler is "none".

Hopefully this removes the need for 1ee0f4c from #208947.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@ghost ghost requested review from sternenseemann and removed request for matthewbauer and Ericson2314 January 4, 2023 10:32
@Ericson2314
Copy link
Member

This might still be a good idea, but note both of you that I made a stdenv.hasCC which can be used to guard accesses to e.g. stdenv.cc.isClang.

@ghost
Copy link
Author

ghost commented Jan 4, 2023

This might still be a good idea, but note both of you that I made a stdenv.hasCC which can be used to guard accesses to e.g. stdenv.cc.isClang.

Yeah, I used that in an earlier revision of this PR, but it really uglifies the caller because (for some reason I didn't track down) stdenv is sometimes missing the hasCC attribute. I think only cross-compiling stdenvs have that attribute. So callers need to do (stdenv.hasCC or true) && stdenv.cc.isGNU.

And of course, callers have to remember to do that. Which I'm sure they won't, unless they are using ghcjs.

So I went looking for a more automatic way to accomplish the goal and came up with this.

@ghost
Copy link
Author

ghost commented Jan 4, 2023

@ofborg eval

The Darwin builders appear to be stuck.

`pkgsCross.ghcjs.stdenv.cc` currently `throw`s, and it is (a good)
part of the Nix semantics that exceptions transmit no information to
an enclosing `tryEval`.  This makes it impossible to express the
fact that the answer to "is the C compiler from GNU?" should be
`false` when no compiler exists.

The reason why `pkgsCross.ghcjs.stdenv.cc` is a `throw` is explained
here:

  https://github.com/NixOS/nixpkgs/blob/aa371581dd110352b217e214867dd2a83660fa3c/pkgs/stdenv/cross/default.nix#L67

which refers to this check in `splice.nix`:

  https://github.com/NixOS/nixpkgs/blob/aa371581dd110352b217e214867dd2a83660fa3c/pkgs/top-level/splice.nix#L59

Since the result of that check is always passed to `getOutputs`,
which is strict in its argument's `outputs` attribtue, we can simply
move the `throw` deeper into the `stdenv.cc` attrset.  This leaves
room to provide a useful value for attributes like `isGNU` and
`isClang` when the compiler is "none".

Hopefully this removes the need for the change in
b6ac11d8a69ad2a04bbbdbaa287da8ba5f7596d8 from #208947.
@ghost ghost closed this Oct 22, 2023
@ghost ghost deleted the pr/ghcjs/less-hacky-stdenv-cc branch October 22, 2023 05:34
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants