diff --git a/checks/mkDummySrcTests/multibin/expected/Cargo.toml b/checks/mkDummySrcTests/multibin/expected/Cargo.toml index dfc92361..05820ffd 100644 --- a/checks/mkDummySrcTests/multibin/expected/Cargo.toml +++ b/checks/mkDummySrcTests/multibin/expected/Cargo.toml @@ -5,6 +5,9 @@ path = "src/bin/hello.rs" [[bin]] name = "bye" +[[bin]] +name = "multibin" + [features] default = ["some"] some = [] diff --git a/checks/mkDummySrcTests/multibin/expected/src/main.rs b/checks/mkDummySrcTests/multibin/expected/src/main.rs new file mode 100644 index 00000000..b6a90ffb --- /dev/null +++ b/checks/mkDummySrcTests/multibin/expected/src/main.rs @@ -0,0 +1,14 @@ +#![allow(clippy::all)] +#![allow(dead_code)] +#![cfg_attr(any(target_os = "none", target_os = "uefi"), no_std)] +#![cfg_attr(any(target_os = "none", target_os = "uefi"), no_main)] + +#[allow(unused_extern_crates)] +extern crate core; + +#[cfg_attr(any(target_os = "none", target_os = "uefi"), panic_handler)] +fn panic(_info: &::core::panic::PanicInfo<'_>) -> ! { + loop {} +} + +pub fn main() {} diff --git a/checks/mkDummySrcTests/multibin/input/Cargo.toml b/checks/mkDummySrcTests/multibin/input/Cargo.toml index 1b3ebe94..41d5e162 100644 --- a/checks/mkDummySrcTests/multibin/input/Cargo.toml +++ b/checks/mkDummySrcTests/multibin/input/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "multibin" +name = "multibin" # Loadbearing name matching bin version = "0.1.0" edition = "2021" @@ -14,3 +14,6 @@ path = "src/bin/hello.rs" [[bin]] name = "bye" required-features = ["some"] + +[[bin]] +name = "multibin" # Name of the package diff --git a/lib/mkDummySrc.nix b/lib/mkDummySrc.nix index f45e3081..08b64668 100644 --- a/lib/mkDummySrc.nix +++ b/lib/mkDummySrc.nix @@ -199,6 +199,7 @@ let autobins = trimmedCargoToml.package.autobins or true; hasMainrs = autobins && hasFile srcDir "main.rs"; srcBinDir = lib.optionalAttrs (autobins && hasDir srcDir "bin") (builtins.readDir (shallowJoinPath "src/bin")); + srcMainrs = "src/main.rs"; candidatePathsForBin = name: rec { short = "src/bin/${name}"; @@ -231,9 +232,12 @@ let inherit (candidates) long; short = "${candidates.short}.rs"; in - if lib.any (i: i == short || i == long) discoveredBins - then null - else short + if t.name == trimmedCargoToml.package.name + then (if hasMainrs then null else srcMainrs) + else + if lib.any (i: i == short || i == long) discoveredBins + then null + else short )); allBins = concatStringsSep " " (discoveredBins ++ declaredBins); @@ -261,7 +265,7 @@ let cp ${writeTOML "Cargo.toml" trimmedCargoToml} $out/${cargoTomlDest} '' + optionalString (trimmedCargoToml ? package) '' # To build regular and dev dependencies (cargo build + cargo test) - ${lib.optionalString hasMainrs (cpDummy parentDir "src/main.rs")} + ${lib.optionalString hasMainrs (cpDummy parentDir srcMainrs)} ${stubBins} # Stub all other targets in case they have particular feature combinations