Skip to content

Commit a308f26

Browse files
authored
Merge pull request #372 from pnmadelaine/fix-cross-compiling
Fix build-dependencies resolution when cross-compiling
2 parents b2543f1 + c027e46 commit a308f26

File tree

16 files changed

+81
-22
lines changed

16 files changed

+81
-22
lines changed

crate2nix/Cargo.nix

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ rec {
449449
{
450450
name = "libc";
451451
packageId = "libc";
452-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "aarch64-linux-android");
452+
target = { target, features }: (target.name == "aarch64-linux-android");
453453
}
454454
{
455455
name = "libc";
@@ -2691,12 +2691,12 @@ rec {
26912691
{
26922692
name = "winapi-i686-pc-windows-gnu";
26932693
packageId = "winapi-i686-pc-windows-gnu";
2694-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnu");
2694+
target = { target, features }: (target.name == "i686-pc-windows-gnu");
26952695
}
26962696
{
26972697
name = "winapi-x86_64-pc-windows-gnu";
26982698
packageId = "winapi-x86_64-pc-windows-gnu";
2699-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnu");
2699+
target = { target, features }: (target.name == "x86_64-pc-windows-gnu");
27002700
}
27012701
];
27022702
features = {
@@ -3001,7 +3001,7 @@ rec {
30013001
{
30023002
name = "windows_aarch64_gnullvm";
30033003
packageId = "windows_aarch64_gnullvm";
3004-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "aarch64-pc-windows-gnullvm");
3004+
target = { target, features }: (target.name == "aarch64-pc-windows-gnullvm");
30053005
}
30063006
{
30073007
name = "windows_aarch64_msvc";
@@ -3016,7 +3016,7 @@ rec {
30163016
{
30173017
name = "windows_i686_gnullvm";
30183018
packageId = "windows_i686_gnullvm";
3019-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnullvm");
3019+
target = { target, features }: (target.name == "i686-pc-windows-gnullvm");
30203020
}
30213021
{
30223022
name = "windows_i686_msvc";
@@ -3031,7 +3031,7 @@ rec {
30313031
{
30323032
name = "windows_x86_64_gnullvm";
30333033
packageId = "windows_x86_64_gnullvm";
3034-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnullvm");
3034+
target = { target, features }: (target.name == "x86_64-pc-windows-gnullvm");
30353035
}
30363036
{
30373037
name = "windows_x86_64_msvc";
@@ -3154,6 +3154,8 @@ rec {
31543154
This corresponds roughly to what buildRustCrate is setting.
31553155
*/
31563156
makeDefaultTarget = platform: {
3157+
name = platform.rust.rustcTarget;
3158+
31573159
unix = platform.isUnix;
31583160
windows = platform.isWindows;
31593161
fuchsia = true;
@@ -3468,7 +3470,7 @@ rec {
34683470
packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId
34693471
)
34703472
crateConfigs;
3471-
target = makeTarget stdenv.hostPlatform;
3473+
target = makeTarget pkgs.stdenv.hostPlatform;
34723474
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
34733475
};
34743476
in

crate2nix/src/render.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ fn cfg_to_nix_expr_filter(
184184
})?;
185185
Ok(tera::Value::String(cfg_to_nix_expr(&expr)))
186186
} else {
187-
let condition = format!(
188-
"(stdenv.hostPlatform.rust.rustcTarget == {})",
189-
escape_nix_string(key)
190-
);
187+
let condition = format!("(target.name == {})", escape_nix_string(key));
191188
Ok(tera::Value::String(condition))
192189
}
193190
}

crate2nix/templates/Cargo.nix.tera

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ rec {
220220
usesDefaultFeatures = false;
221221
{%- endif -%}
222222
{%- if dependency.target %}
223-
target = { target, features }: {{dependency.target | cfg_to_nix_expr | safe }};
223+
target = { target, features }: {{dependency.target | cfg_to_nix_expr | safe}};
224224
{%- endif %}
225225
{%- if dependency.features %}
226226
features = [ {% for feature in dependency.features %}{{feature}} {% endfor %}];
@@ -246,7 +246,7 @@ rec {
246246
usesDefaultFeatures = false;
247247
{%- endif -%}
248248
{%- if dependency.target %}
249-
target = {target, features}: {{dependency.target | cfg_to_nix_expr | safe }};
249+
target = { target, features }: {{dependency.target | cfg_to_nix_expr | safe}};
250250
{%- endif %}
251251
{%- if dependency.features %}
252252
features = [ {% for feature in dependency.features %}{{feature}} {% endfor %}];
@@ -271,7 +271,7 @@ rec {
271271
usesDefaultFeatures = false;
272272
{%- endif -%}
273273
{%- if dependency.target %}
274-
target = {target, features}: {{dependency.target | cfg_to_nix_expr | safe }};
274+
target = { target, features }: {{dependency.target | cfg_to_nix_expr | safe}};
275275
{%- endif %}
276276
{%- if dependency.features %}
277277
features = [ {% for feature in dependency.features %}{{feature}} {% endfor %}];

crate2nix/templates/nix/crate2nix/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ rec {
2525
This corresponds roughly to what buildRustCrate is setting.
2626
*/
2727
makeDefaultTarget = platform: {
28+
name = platform.rust.rustcTarget;
29+
2830
unix = platform.isUnix;
2931
windows = platform.isWindows;
3032
fuchsia = true;
@@ -339,7 +341,7 @@ rec {
339341
packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId
340342
)
341343
crateConfigs;
342-
target = makeTarget stdenv.hostPlatform;
344+
target = makeTarget pkgs.stdenv.hostPlatform;
343345
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
344346
};
345347
in

sample_projects/bin_with_git_submodule_dep/Cargo.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ rec {
12561256
{
12571257
name = "windows_aarch64_gnullvm";
12581258
packageId = "windows_aarch64_gnullvm";
1259-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "aarch64-pc-windows-gnullvm");
1259+
target = { target, features }: (target.name == "aarch64-pc-windows-gnullvm");
12601260
}
12611261
{
12621262
name = "windows_aarch64_msvc";
@@ -1281,7 +1281,7 @@ rec {
12811281
{
12821282
name = "windows_x86_64_gnullvm";
12831283
packageId = "windows_x86_64_gnullvm";
1284-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnullvm");
1284+
target = { target, features }: (target.name == "x86_64-pc-windows-gnullvm");
12851285
}
12861286
{
12871287
name = "windows_x86_64_msvc";
@@ -1372,6 +1372,8 @@ rec {
13721372
This corresponds roughly to what buildRustCrate is setting.
13731373
*/
13741374
makeDefaultTarget = platform: {
1375+
name = platform.rust.rustcTarget;
1376+
13751377
unix = platform.isUnix;
13761378
windows = platform.isWindows;
13771379
fuchsia = true;
@@ -1686,7 +1688,7 @@ rec {
16861688
packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId
16871689
)
16881690
crateConfigs;
1689-
target = makeTarget stdenv.hostPlatform;
1691+
target = makeTarget pkgs.stdenv.hostPlatform;
16901692
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
16911693
};
16921694
in

sample_projects/codegen/Cargo.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,12 @@ rec {
491491
{
492492
name = "winapi-i686-pc-windows-gnu";
493493
packageId = "winapi-i686-pc-windows-gnu";
494-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "i686-pc-windows-gnu");
494+
target = { target, features }: (target.name == "i686-pc-windows-gnu");
495495
}
496496
{
497497
name = "winapi-x86_64-pc-windows-gnu";
498498
packageId = "winapi-x86_64-pc-windows-gnu";
499-
target = { target, features }: (stdenv.hostPlatform.rust.rustcTarget == "x86_64-pc-windows-gnu");
499+
target = { target, features }: (target.name == "x86_64-pc-windows-gnu");
500500
}
501501
];
502502
features = {
@@ -547,6 +547,8 @@ rec {
547547
This corresponds roughly to what buildRustCrate is setting.
548548
*/
549549
makeDefaultTarget = platform: {
550+
name = platform.rust.rustcTarget;
551+
550552
unix = platform.isUnix;
551553
windows = platform.isWindows;
552554
fuchsia = true;
@@ -861,7 +863,7 @@ rec {
861863
packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId
862864
)
863865
crateConfigs;
864-
target = makeTarget stdenv.hostPlatform;
866+
target = makeTarget pkgs.stdenv.hostPlatform;
865867
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
866868
};
867869
in

sample_projects/cross_compile_build_dependencies/Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "cross_compile_build_dependencies"
3+
version = "1.0.0"
4+
edition = "2021"
5+
6+
[build-dependencies]
7+
alice.path = "./alice"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "alice"
3+
version = "1.0.0"
4+
edition = "2021"
5+
6+
[target.'cfg(unix)'.dependencies]
7+
bob.path = "./bob"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "bob"
3+
version = "1.0.0"
4+
edition = "2021"

0 commit comments

Comments
 (0)