Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkDummySrc: also consider main.rs when deduping bins #758

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions checks/mkDummySrcTests/multibin/expected/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ path = "src/bin/hello.rs"
[[bin]]
name = "bye"

[[bin]]
name = "multibin"

[features]
default = ["some"]
some = []
Expand Down
14 changes: 14 additions & 0 deletions checks/mkDummySrcTests/multibin/expected/src/main.rs
Original file line number Diff line number Diff line change
@@ -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() {}
5 changes: 4 additions & 1 deletion checks/mkDummySrcTests/multibin/input/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "multibin"
name = "multibin" # Loadbearing name matching bin
version = "0.1.0"
edition = "2021"

Expand All @@ -14,3 +14,6 @@ path = "src/bin/hello.rs"
[[bin]]
name = "bye"
required-features = ["some"]

[[bin]]
name = "multibin" # Name of the package
12 changes: 8 additions & 4 deletions lib/mkDummySrc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Loading