nixpkgs/pkgs/test/stdenv-inputs/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

69 lines
1.7 KiB
Nix

{ lib, stdenv }:
let
foo = stdenv.mkDerivation {
name = "foo-test";
dontUnpack = true;
installPhase = ''
mkdir -p $out/bin $out/include $out/lib
$CC -o $out/bin/foo ${./cc-main.c}
chmod +x $out/bin/foo
cp ${./foo.c} $out/include/foo.h
$CC -shared \
${lib.optionalString stdenv.hostPlatform.isDarwin "-Wl,-install_name,$out/lib/libfoo.dylib"} \
-o $out/lib/libfoo${stdenv.hostPlatform.extensions.sharedLibrary} \
${./foo.c}
'';
};
bar = stdenv.mkDerivation {
name = "bar-test";
outputs = [ "out" "dev" ];
dontUnpack = true;
installPhase = ''
mkdir -p $out/bin $dev/include $dev/lib
$CC -o $out/bin/bar ${./cc-main.c}
chmod +x $out/bin/bar
cp ${./bar.c} $dev/include/bar.h
$CC -shared \
${lib.optionalString stdenv.hostPlatform.isDarwin "-Wl,-install_name,$dev/lib/libbar.dylib"} \
-o $dev/lib/libbar${stdenv.hostPlatform.extensions.sharedLibrary} \
${./bar.c}
'';
};
in
stdenv.mkDerivation {
name = "stdenv-inputs-test";
phases = [ "buildPhase" ];
buildInputs = [ foo bar ];
buildPhase = ''
env
printf "checking whether binaries are available... " >&2
foo && bar
printf "checking whether compiler can find headers... " >&2
$CC -o include-check ${./include-main.c}
./include-check
printf "checking whether compiler can find headers... " >&2
$CC -o include-check ${./include-main.c}
./include-check
printf "checking whether compiler can find libraries... " >&2
$CC -lfoo -lbar -o lib-check ${./lib-main.c}
./lib-check
touch $out
'';
meta.platforms = lib.platforms.all;
}