Skip to content

Commit e6797b9

Browse files
committed
rust.lib -> stdenv.hostPlatform.rust
context: NixOS/nixpkgs@e3e57b8 NixOS/nixpkgs#271707
1 parent b4de66a commit e6797b9

File tree

6 files changed

+38
-59
lines changed

6 files changed

+38
-59
lines changed

crate2nix/Cargo.nix

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ rec {
439439
{
440440
name = "libc";
441441
packageId = "libc";
442-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "aarch64-linux-android");
442+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "aarch64-linux-android");
443443
}
444444
{
445445
name = "libc";
@@ -2695,12 +2695,12 @@ rec {
26952695
{
26962696
name = "winapi-i686-pc-windows-gnu";
26972697
packageId = "winapi-i686-pc-windows-gnu";
2698-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "i686-pc-windows-gnu");
2698+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnu");
26992699
}
27002700
{
27012701
name = "winapi-x86_64-pc-windows-gnu";
27022702
packageId = "winapi-x86_64-pc-windows-gnu";
2703-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "x86_64-pc-windows-gnu");
2703+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnu");
27042704
}
27052705
];
27062706
features = {
@@ -2783,14 +2783,11 @@ rec {
27832783
fuchsia = true;
27842784
test = false;
27852785

2786-
/* We are choosing an arbitrary rust version to grab `lib` from,
2787-
which is unfortunate, but `lib` has been version-agnostic the
2788-
whole time so this is good enough for now.
2789-
*/
2790-
os = pkgs.rust.lib.toTargetOs platform;
2791-
arch = pkgs.rust.lib.toTargetArch platform;
2792-
family = pkgs.rust.lib.toTargetFamily platform;
2793-
vendor = pkgs.rust.lib.toTargetVendor platform;
2786+
inherit (platform.rust.platform)
2787+
arch
2788+
os
2789+
vendor;
2790+
family = platform.rust.platform.target-family;
27942791
env = "gnu";
27952792
endian =
27962793
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -3033,7 +3030,7 @@ rec {
30333030
let
30343031
self = {
30353032
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
3036-
target = makeTarget pkgs.stdenv.hostPlatform;
3033+
target = makeTarget stdenv.hostPlatform;
30373034
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
30383035
};
30393036
in

crate2nix/src/render.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,8 @@ fn cfg_to_nix_expr_filter(
184184
})?;
185185
Ok(tera::Value::String(cfg_to_nix_expr(&expr)))
186186
} else {
187-
// `lib.toRustTarget` has existed since Nixpkgs 21.05. That is
188-
// hopefully good enough.
189-
//
190-
// We are choosing an arbitrary rust version to grab `lib` from,
191-
// which is unfortunate, but `lib` has been version-agnostic the
192-
// whole time so this is good enough for now.
193187
let condition = format!(
194-
"(pkgs.rust.lib.toRustTarget stdenv.hostPlatform == {})",
188+
"(stdenv.hostPlatform.rust.rustcTarget == {})",
195189
escape_nix_string(key)
196190
);
197191
Ok(tera::Value::String(condition))

crate2nix/templates/nix/crate2nix/default.nix

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ rec {
2727
fuchsia = true;
2828
test = false;
2929

30-
/* We are choosing an arbitrary rust version to grab `lib` from,
31-
which is unfortunate, but `lib` has been version-agnostic the
32-
whole time so this is good enough for now.
33-
*/
34-
os = pkgs.rust.lib.toTargetOs platform;
35-
arch = pkgs.rust.lib.toTargetArch platform;
36-
family = pkgs.rust.lib.toTargetFamily platform;
37-
vendor = pkgs.rust.lib.toTargetVendor platform;
30+
inherit (platform.rust.platform)
31+
arch
32+
os
33+
vendor;
34+
family = platform.rust.platform.target-family;
3835
env = "gnu";
3936
endian =
4037
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -277,7 +274,7 @@ rec {
277274
let
278275
self = {
279276
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
280-
target = makeTarget pkgs.stdenv.hostPlatform;
277+
target = makeTarget stdenv.hostPlatform;
281278
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
282279
};
283280
in

sample_projects/bin_with_git_submodule_dep/Cargo.nix

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ rec {
12571257
{
12581258
name = "windows_aarch64_gnullvm";
12591259
packageId = "windows_aarch64_gnullvm";
1260-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "aarch64-pc-windows-gnullvm");
1260+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "aarch64-pc-windows-gnullvm");
12611261
}
12621262
{
12631263
name = "windows_aarch64_msvc";
@@ -1282,7 +1282,7 @@ rec {
12821282
{
12831283
name = "windows_x86_64_gnullvm";
12841284
packageId = "windows_x86_64_gnullvm";
1285-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "x86_64-pc-windows-gnullvm");
1285+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnullvm");
12861286
}
12871287
{
12881288
name = "windows_x86_64_msvc";
@@ -1377,14 +1377,11 @@ rec {
13771377
fuchsia = true;
13781378
test = false;
13791379

1380-
/* We are choosing an arbitrary rust version to grab `lib` from,
1381-
which is unfortunate, but `lib` has been version-agnostic the
1382-
whole time so this is good enough for now.
1383-
*/
1384-
os = pkgs.rust.lib.toTargetOs platform;
1385-
arch = pkgs.rust.lib.toTargetArch platform;
1386-
family = pkgs.rust.lib.toTargetFamily platform;
1387-
vendor = pkgs.rust.lib.toTargetVendor platform;
1380+
inherit (platform.rust.platform)
1381+
arch
1382+
os
1383+
vendor;
1384+
family = platform.rust.platform.target-family;
13881385
env = "gnu";
13891386
endian =
13901387
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -1627,7 +1624,7 @@ rec {
16271624
let
16281625
self = {
16291626
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
1630-
target = makeTarget pkgs.stdenv.hostPlatform;
1627+
target = makeTarget stdenv.hostPlatform;
16311628
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
16321629
};
16331630
in

sample_projects/codegen/Cargo.nix

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,12 @@ rec {
492492
{
493493
name = "winapi-i686-pc-windows-gnu";
494494
packageId = "winapi-i686-pc-windows-gnu";
495-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "i686-pc-windows-gnu");
495+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnu");
496496
}
497497
{
498498
name = "winapi-x86_64-pc-windows-gnu";
499499
packageId = "winapi-x86_64-pc-windows-gnu";
500-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "x86_64-pc-windows-gnu");
500+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnu");
501501
}
502502
];
503503
features = {
@@ -552,14 +552,11 @@ rec {
552552
fuchsia = true;
553553
test = false;
554554

555-
/* We are choosing an arbitrary rust version to grab `lib` from,
556-
which is unfortunate, but `lib` has been version-agnostic the
557-
whole time so this is good enough for now.
558-
*/
559-
os = pkgs.rust.lib.toTargetOs platform;
560-
arch = pkgs.rust.lib.toTargetArch platform;
561-
family = pkgs.rust.lib.toTargetFamily platform;
562-
vendor = pkgs.rust.lib.toTargetVendor platform;
555+
inherit (platform.rust.platform)
556+
arch
557+
os
558+
vendor;
559+
family = platform.rust.platform.target-family;
563560
env = "gnu";
564561
endian =
565562
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -802,7 +799,7 @@ rec {
802799
let
803800
self = {
804801
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
805-
target = makeTarget pkgs.stdenv.hostPlatform;
802+
target = makeTarget stdenv.hostPlatform;
806803
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
807804
};
808805
in

sample_projects/sub_dir_crates/Cargo.nix

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,11 @@ rec {
161161
fuchsia = true;
162162
test = false;
163163

164-
/* We are choosing an arbitrary rust version to grab `lib` from,
165-
which is unfortunate, but `lib` has been version-agnostic the
166-
whole time so this is good enough for now.
167-
*/
168-
os = pkgs.rust.lib.toTargetOs platform;
169-
arch = pkgs.rust.lib.toTargetArch platform;
170-
family = pkgs.rust.lib.toTargetFamily platform;
171-
vendor = pkgs.rust.lib.toTargetVendor platform;
164+
inherit (platform.rust.platform)
165+
arch
166+
os
167+
vendor;
168+
family = platform.rust.platform.target-family;
172169
env = "gnu";
173170
endian =
174171
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -411,7 +408,7 @@ rec {
411408
let
412409
self = {
413410
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
414-
target = makeTarget pkgs.stdenv.hostPlatform;
411+
target = makeTarget stdenv.hostPlatform;
415412
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
416413
};
417414
in

0 commit comments

Comments
 (0)