Skip to content

Commit 4fcd1d9

Browse files
authored
Merge pull request #352 from Kranzes/improvements
Get rid of no longer needed workarounds, improve cross compilation support, filter src for all nix versions
2 parents b4de66a + 4381f1e commit 4fcd1d9

File tree

9 files changed

+46
-99
lines changed

9 files changed

+46
-99
lines changed

crate2nix/Cargo.nix

Lines changed: 10 additions & 19 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";
@@ -470,11 +470,7 @@ rec {
470470
requiredFeatures = [ ];
471471
}
472472
];
473-
# We can't filter paths with references in Nix 2.4
474-
# See https://github.com/NixOS/nix/issues/5410
475-
src = if ((lib.versionOlder builtins.nixVersion "2.4pre20211007") || (lib.versionOlder "2.5" builtins.nixVersion ))
476-
then lib.cleanSourceWith { filter = sourceFilter; src = ./.; }
477-
else ./.;
473+
src = lib.cleanSourceWith { filter = sourceFilter; src = ./.; };
478474
authors = [
479475
"Peter Kolloch <[email protected]>"
480476
];
@@ -2695,12 +2691,12 @@ rec {
26952691
{
26962692
name = "winapi-i686-pc-windows-gnu";
26972693
packageId = "winapi-i686-pc-windows-gnu";
2698-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "i686-pc-windows-gnu");
2694+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnu");
26992695
}
27002696
{
27012697
name = "winapi-x86_64-pc-windows-gnu";
27022698
packageId = "winapi-x86_64-pc-windows-gnu";
2703-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "x86_64-pc-windows-gnu");
2699+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnu");
27042700
}
27052701
];
27062702
features = {
@@ -2783,14 +2779,11 @@ rec {
27832779
fuchsia = true;
27842780
test = false;
27852781

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;
2782+
inherit (platform.rust.platform)
2783+
arch
2784+
os
2785+
vendor;
2786+
family = platform.rust.platform.target-family;
27942787
env = "gnu";
27952788
endian =
27962789
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -3033,7 +3026,7 @@ rec {
30333026
let
30343027
self = {
30353028
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
3036-
target = makeTarget pkgs.stdenv.hostPlatform;
3029+
target = makeTarget stdenv.hostPlatform;
30373030
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
30383031
};
30393032
in
@@ -3108,8 +3101,6 @@ rec {
31083101
buildRustCrateForPkgsFunc pkgs
31093102
(
31103103
crateConfig // {
3111-
# https://github.com/NixOS/nixpkgs/issues/218712
3112-
dontStrip = stdenv.hostPlatform.isDarwin;
31133104
src = crateConfig.src or (
31143105
pkgs.fetchurl rec {
31153106
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";

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/Cargo.nix.tera

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ rec {
128128
{%- elif crate.source.Nix.file.package %}
129129
src = pkgs.callPackage {{crate.source.Nix.file.package | safe}} {};
130130
{%- elif crate.source.LocalDirectory.path %}
131-
# We can't filter paths with references in Nix 2.4
132-
# See https://github.com/NixOS/nix/issues/5410
133-
src = if ((lib.versionOlder builtins.nixVersion "2.4pre20211007") || (lib.versionOlder "2.5" builtins.nixVersion ))
134-
then lib.cleanSourceWith { filter = sourceFilter; src = {{crate.source.LocalDirectory.path | safe}}; }
135-
else {{crate.source.LocalDirectory.path | safe}};
131+
src = lib.cleanSourceWith { filter = sourceFilter; src = {{crate.source.LocalDirectory.path | safe}}; };
136132
{%- elif crate.source.Git %}
137133
workspace_member = null;
138134
src = pkgs.fetchgit {

crate2nix/templates/crate2nix-sources.nix.tera

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
, crate2nixJson ? ./crate2nix.json
1919
}:
2020

21-
# unsafeDiscardStringContext is a workaround for https://github.com/NixOS/nix/issues/6647
22-
let config = builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile crate2nixJson));
21+
let config = lib.importJSON crate2nixJson;
2322
sources = config.sources or (builtins.throw "no sources in ${crate2nixJson}");
2423
in
2524
rec {
@@ -108,4 +107,4 @@ rec {
108107
tar -xzf ${archive} --strip-components=1 -C $out
109108
'';
110109
};
111-
}
110+
}

crate2nix/templates/nix/crate2nix/default.nix

Lines changed: 6 additions & 11 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
@@ -352,8 +349,6 @@ rec {
352349
buildRustCrateForPkgsFunc pkgs
353350
(
354351
crateConfig // {
355-
# https://github.com/NixOS/nixpkgs/issues/218712
356-
dontStrip = stdenv.hostPlatform.isDarwin;
357352
src = crateConfig.src or (
358353
pkgs.fetchurl rec {
359354
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";

sample_projects/bin_with_git_submodule_dep/Cargo.nix

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ rec {
121121
requiredFeatures = [ ];
122122
}
123123
];
124-
# We can't filter paths with references in Nix 2.4
125-
# See https://github.com/NixOS/nix/issues/5410
126-
src = if ((lib.versionOlder builtins.nixVersion "2.4pre20211007") || (lib.versionOlder "2.5" builtins.nixVersion ))
127-
then lib.cleanSourceWith { filter = sourceFilter; src = ./.; }
128-
else ./.;
124+
src = lib.cleanSourceWith { filter = sourceFilter; src = ./.; };
129125
authors = [
130126
"Phillip Cloud <[email protected]>"
131127
];
@@ -1257,7 +1253,7 @@ rec {
12571253
{
12581254
name = "windows_aarch64_gnullvm";
12591255
packageId = "windows_aarch64_gnullvm";
1260-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "aarch64-pc-windows-gnullvm");
1256+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "aarch64-pc-windows-gnullvm");
12611257
}
12621258
{
12631259
name = "windows_aarch64_msvc";
@@ -1282,7 +1278,7 @@ rec {
12821278
{
12831279
name = "windows_x86_64_gnullvm";
12841280
packageId = "windows_x86_64_gnullvm";
1285-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "x86_64-pc-windows-gnullvm");
1281+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnullvm");
12861282
}
12871283
{
12881284
name = "windows_x86_64_msvc";
@@ -1377,14 +1373,11 @@ rec {
13771373
fuchsia = true;
13781374
test = false;
13791375

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;
1376+
inherit (platform.rust.platform)
1377+
arch
1378+
os
1379+
vendor;
1380+
family = platform.rust.platform.target-family;
13881381
env = "gnu";
13891382
endian =
13901383
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -1627,7 +1620,7 @@ rec {
16271620
let
16281621
self = {
16291622
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
1630-
target = makeTarget pkgs.stdenv.hostPlatform;
1623+
target = makeTarget stdenv.hostPlatform;
16311624
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
16321625
};
16331626
in
@@ -1702,8 +1695,6 @@ rec {
17021695
buildRustCrateForPkgsFunc pkgs
17031696
(
17041697
crateConfig // {
1705-
# https://github.com/NixOS/nixpkgs/issues/218712
1706-
dontStrip = stdenv.hostPlatform.isDarwin;
17071698
src = crateConfig.src or (
17081699
pkgs.fetchurl rec {
17091700
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";

sample_projects/codegen/Cargo.nix

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,7 @@ rec {
223223
requiredFeatures = [ ];
224224
}
225225
];
226-
# We can't filter paths with references in Nix 2.4
227-
# See https://github.com/NixOS/nix/issues/5410
228-
src = if ((lib.versionOlder builtins.nixVersion "2.4pre20211007") || (lib.versionOlder "2.5" builtins.nixVersion ))
229-
then lib.cleanSourceWith { filter = sourceFilter; src = ./.; }
230-
else ./.;
226+
src = lib.cleanSourceWith { filter = sourceFilter; src = ./.; };
231227
authors = [
232228
"Peter Kolloch <[email protected]>"
233229
];
@@ -492,12 +488,12 @@ rec {
492488
{
493489
name = "winapi-i686-pc-windows-gnu";
494490
packageId = "winapi-i686-pc-windows-gnu";
495-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "i686-pc-windows-gnu");
491+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnu");
496492
}
497493
{
498494
name = "winapi-x86_64-pc-windows-gnu";
499495
packageId = "winapi-x86_64-pc-windows-gnu";
500-
target = { target, features }: (pkgs.rust.lib.toRustTarget stdenv.hostPlatform == "x86_64-pc-windows-gnu");
496+
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnu");
501497
}
502498
];
503499
features = {
@@ -552,14 +548,11 @@ rec {
552548
fuchsia = true;
553549
test = false;
554550

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;
551+
inherit (platform.rust.platform)
552+
arch
553+
os
554+
vendor;
555+
family = platform.rust.platform.target-family;
563556
env = "gnu";
564557
endian =
565558
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -802,7 +795,7 @@ rec {
802795
let
803796
self = {
804797
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
805-
target = makeTarget pkgs.stdenv.hostPlatform;
798+
target = makeTarget stdenv.hostPlatform;
806799
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
807800
};
808801
in
@@ -877,8 +870,6 @@ rec {
877870
buildRustCrateForPkgsFunc pkgs
878871
(
879872
crateConfig // {
880-
# https://github.com/NixOS/nixpkgs/issues/218712
881-
dontStrip = stdenv.hostPlatform.isDarwin;
882873
src = crateConfig.src or (
883874
pkgs.fetchurl rec {
884875
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";

sample_projects/sub_dir_crates/Cargo.nix

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ rec {
126126
requiredFeatures = [ ];
127127
}
128128
];
129-
# We can't filter paths with references in Nix 2.4
130-
# See https://github.com/NixOS/nix/issues/5410
131-
src = if ((lib.versionOlder builtins.nixVersion "2.4pre20211007") || (lib.versionOlder "2.5" builtins.nixVersion ))
132-
then lib.cleanSourceWith { filter = sourceFilter; src = ./.; }
133-
else ./.;
129+
src = lib.cleanSourceWith { filter = sourceFilter; src = ./.; };
134130
authors = [
135131
"Peter Kolloch <[email protected]>"
136132
];
@@ -161,14 +157,11 @@ rec {
161157
fuchsia = true;
162158
test = false;
163159

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;
160+
inherit (platform.rust.platform)
161+
arch
162+
os
163+
vendor;
164+
family = platform.rust.platform.target-family;
172165
env = "gnu";
173166
endian =
174167
if platform.parsed.cpu.significantByte.name == "littleEndian"
@@ -411,7 +404,7 @@ rec {
411404
let
412405
self = {
413406
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
414-
target = makeTarget pkgs.stdenv.hostPlatform;
407+
target = makeTarget stdenv.hostPlatform;
415408
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
416409
};
417410
in
@@ -486,8 +479,6 @@ rec {
486479
buildRustCrateForPkgsFunc pkgs
487480
(
488481
crateConfig // {
489-
# https://github.com/NixOS/nixpkgs/issues/218712
490-
dontStrip = stdenv.hostPlatform.isDarwin;
491482
src = crateConfig.src or (
492483
pkgs.fetchurl rec {
493484
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";

tools.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ rec {
249249

250250
locked =
251251
let
252-
# unsafeDiscardStringContext is a workaround for https://github.com/NixOS/nix/issues/6647
253-
parseFile = cargoLock: builtins.fromTOML (builtins.unsafeDiscardStringContext (builtins.readFile cargoLock));
252+
parseFile = cargoLock: lib.importTOML cargoLock;
254253
allParsedFiles = builtins.map parseFile lockFiles;
255254
merge = merged: lock:
256255
{

0 commit comments

Comments
 (0)