mkDummySrc: fix handling of bin targets

* First, bin targets go into `src/bin` not `bin`
* Second, the path fallback name needs a `rs` suffix
This commit is contained in:
Ivan Petkov 2021-12-31 19:03:06 -08:00
parent b4a1445590
commit 55ba19ec1c
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6
12 changed files with 62 additions and 2 deletions

View File

@ -53,7 +53,7 @@ let
safeStubList = attr: defaultPath: safeStubList = attr: defaultPath:
let let
targetList = trimmedCargoToml.${attr} or [ ]; targetList = trimmedCargoToml.${attr} or [ ];
paths = map (t: t.path or "${defaultPath}/${t.name}") targetList; paths = map (t: t.path or "${defaultPath}/${t.name}.rs") targetList;
commands = map cpDummy paths; commands = map cpDummy paths;
in in
concatStringsSep "\n" commands; concatStringsSep "\n" commands;
@ -73,7 +73,7 @@ runCommand name { } ''
# Stub all other targets in case they have particular feature combinations # Stub all other targets in case they have particular feature combinations
${safeStubLib} ${safeStubLib}
${safeStubList "bench" "benches"} ${safeStubList "bench" "benches"}
${safeStubList "bin" "bin"} ${safeStubList "bin" "src/bin"}
${safeStubList "example" "examples"} ${safeStubList "example" "examples"}
${safeStubList "test" "tests"} ${safeStubList "test" "tests"}
'' ''

View File

@ -41,6 +41,10 @@ pkgs.lib.makeScope myLib.newScope (self:
touch $out touch $out
''; '';
depsOnlyVariousTargets = myLib.buildDepsOnly {
src = ./various-targets;
};
simple = myLib.buildWithCargo { simple = myLib.buildWithCargo {
doCopyTargetToOutput = false; doCopyTargetToOutput = false;
src = ./simple; src = ./simple;

7
tests/various-targets/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "various-targets"
version = "0.1.0"

View File

@ -0,0 +1,28 @@
[package]
name = "various-targets"
version = "0.1.0"
edition = "2021"
[[bench]]
name = "foo"
[[bench]]
name = "bar"
[[bin]]
name = "baz"
[[bin]]
name = "qux"
[[example]]
name = "zuul"
[[example]]
name = "corge"
[[test]]
name = "grault"
[[test]]
name = "garply"

View File

@ -0,0 +1,4 @@
#[test]
fn foo() {
}

View File

@ -0,0 +1,4 @@
#[test]
fn foo() {
}

View File

@ -0,0 +1,4 @@
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1,4 @@
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1,2 @@
pub fn main() {
}

View File

@ -0,0 +1,3 @@
pub fn main() {
println!("hello world");
}

View File

View File