From 9690064a6c5e7ae70636e9ee3a90b6a234bb687e Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 31 Oct 2023 14:16:22 +0200 Subject: [PATCH 1/2] take lndir from buildPackages This needs to be executed on the building host. --- crate2nix/Cargo.nix | 2 +- crate2nix/templates/nix/crate2nix/default.nix | 2 +- sample_projects/bin_with_git_submodule_dep/Cargo.nix | 2 +- sample_projects/codegen/Cargo.nix | 2 +- sample_projects/sub_dir_crates/Cargo.nix | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crate2nix/Cargo.nix b/crate2nix/Cargo.nix index 5b8b3be4..4c99eac9 100644 --- a/crate2nix/Cargo.nix +++ b/crate2nix/Cargo.nix @@ -2621,7 +2621,7 @@ rec { # recreate a file hierarchy as when running tests with cargo # the source for test data - ${pkgs.xorg.lndir}/bin/lndir ${crate.src} + ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} # build outputs testRoot=target/debug diff --git a/crate2nix/templates/nix/crate2nix/default.nix b/crate2nix/templates/nix/crate2nix/default.nix index 1b859fb2..2b8050c1 100644 --- a/crate2nix/templates/nix/crate2nix/default.nix +++ b/crate2nix/templates/nix/crate2nix/default.nix @@ -135,7 +135,7 @@ rec { # recreate a file hierarchy as when running tests with cargo # the source for test data - ${pkgs.xorg.lndir}/bin/lndir ${crate.src} + ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} # build outputs testRoot=target/debug diff --git a/sample_projects/bin_with_git_submodule_dep/Cargo.nix b/sample_projects/bin_with_git_submodule_dep/Cargo.nix index 228c0e75..4e6e3ec9 100644 --- a/sample_projects/bin_with_git_submodule_dep/Cargo.nix +++ b/sample_projects/bin_with_git_submodule_dep/Cargo.nix @@ -1483,7 +1483,7 @@ rec { # recreate a file hierarchy as when running tests with cargo # the source for test data - ${pkgs.xorg.lndir}/bin/lndir ${crate.src} + ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} # build outputs testRoot=target/debug diff --git a/sample_projects/codegen/Cargo.nix b/sample_projects/codegen/Cargo.nix index a360d413..65fed2bb 100644 --- a/sample_projects/codegen/Cargo.nix +++ b/sample_projects/codegen/Cargo.nix @@ -615,7 +615,7 @@ rec { # recreate a file hierarchy as when running tests with cargo # the source for test data - ${pkgs.xorg.lndir}/bin/lndir ${crate.src} + ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} # build outputs testRoot=target/debug diff --git a/sample_projects/sub_dir_crates/Cargo.nix b/sample_projects/sub_dir_crates/Cargo.nix index 1131e602..592429c1 100644 --- a/sample_projects/sub_dir_crates/Cargo.nix +++ b/sample_projects/sub_dir_crates/Cargo.nix @@ -267,7 +267,7 @@ rec { # recreate a file hierarchy as when running tests with cargo # the source for test data - ${pkgs.xorg.lndir}/bin/lndir ${crate.src} + ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} # build outputs testRoot=target/debug From 95e3997dc9b806090e5f8c7adff80acfee14714a Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 31 Oct 2023 14:18:06 +0200 Subject: [PATCH 2/2] skip running tests when cross-compiling --- crate2nix/Cargo.nix | 10 ++++++---- crate2nix/templates/nix/crate2nix/default.nix | 10 ++++++---- sample_projects/bin_with_git_submodule_dep/Cargo.nix | 10 ++++++---- sample_projects/codegen/Cargo.nix | 10 ++++++---- sample_projects/sub_dir_crates/Cargo.nix | 10 ++++++---- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/crate2nix/Cargo.nix b/crate2nix/Cargo.nix index 4c99eac9..a63e83c7 100644 --- a/crate2nix/Cargo.nix +++ b/crate2nix/Cargo.nix @@ -2651,10 +2651,12 @@ rec { passthru = (crate.passthru or { }) // { inherit test; }; - } '' - echo tested by ${test} - ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} - ''; + } + (lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + echo tested by ${test} + '' + '' + ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} + ''); /* A restricted overridable version of builtRustCratesWithFeatures. */ buildRustCrateWithFeatures = diff --git a/crate2nix/templates/nix/crate2nix/default.nix b/crate2nix/templates/nix/crate2nix/default.nix index 2b8050c1..e4fc2e9c 100644 --- a/crate2nix/templates/nix/crate2nix/default.nix +++ b/crate2nix/templates/nix/crate2nix/default.nix @@ -165,10 +165,12 @@ rec { passthru = (crate.passthru or { }) // { inherit test; }; - } '' - echo tested by ${test} - ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} - ''; + } + (lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + echo tested by ${test} + '' + '' + ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} + ''); /* A restricted overridable version of builtRustCratesWithFeatures. */ buildRustCrateWithFeatures = diff --git a/sample_projects/bin_with_git_submodule_dep/Cargo.nix b/sample_projects/bin_with_git_submodule_dep/Cargo.nix index 4e6e3ec9..a293259c 100644 --- a/sample_projects/bin_with_git_submodule_dep/Cargo.nix +++ b/sample_projects/bin_with_git_submodule_dep/Cargo.nix @@ -1513,10 +1513,12 @@ rec { passthru = (crate.passthru or { }) // { inherit test; }; - } '' - echo tested by ${test} - ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} - ''; + } + (lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + echo tested by ${test} + '' + '' + ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} + ''); /* A restricted overridable version of builtRustCratesWithFeatures. */ buildRustCrateWithFeatures = diff --git a/sample_projects/codegen/Cargo.nix b/sample_projects/codegen/Cargo.nix index 65fed2bb..5c3331b9 100644 --- a/sample_projects/codegen/Cargo.nix +++ b/sample_projects/codegen/Cargo.nix @@ -645,10 +645,12 @@ rec { passthru = (crate.passthru or { }) // { inherit test; }; - } '' - echo tested by ${test} - ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} - ''; + } + (lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + echo tested by ${test} + '' + '' + ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} + ''); /* A restricted overridable version of builtRustCratesWithFeatures. */ buildRustCrateWithFeatures = diff --git a/sample_projects/sub_dir_crates/Cargo.nix b/sample_projects/sub_dir_crates/Cargo.nix index 592429c1..a6386279 100644 --- a/sample_projects/sub_dir_crates/Cargo.nix +++ b/sample_projects/sub_dir_crates/Cargo.nix @@ -297,10 +297,12 @@ rec { passthru = (crate.passthru or { }) // { inherit test; }; - } '' - echo tested by ${test} - ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} - ''; + } + (lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + echo tested by ${test} + '' + '' + ${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs} + ''); /* A restricted overridable version of builtRustCratesWithFeatures. */ buildRustCrateWithFeatures =