mkDummySrc: drop dummy lib.rs by default, not main.rs

* There are some edge cases where cargo will allow a lib.rs file to be
  present but not a main.rs (e.g. a binary cannot be called "examples",
  which will happen if the crate is called that and a main.rs file is
  present)
This commit is contained in:
Ivan Petkov 2022-01-07 20:42:24 -08:00
parent bcec95e215
commit abc2c8c418
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6
10 changed files with 45 additions and 7 deletions

View File

@ -47,6 +47,12 @@ onlyDrvs (lib.makeScope myLib.newScope (self:
features = callPackage ./features { };
illegalBin = myLib.buildPackage {
pname = "illegalBin";
version = "0.0.1";
src = ./illegal-bin;
};
manyLibs = myLib.buildPackage {
src = ./with-libs;
pname = "my-libs";
@ -72,6 +78,11 @@ onlyDrvs (lib.makeScope myLib.newScope (self:
src = ./simple;
};
# Test building a real world example
ripgrep = myLib.buildPackage {
inherit (pkgs.ripgrep) pname src version;
};
smoke = callPackage ./smoke.nix { };
smokeSimple = self.smoke [ "simple" ] self.simple;

7
checks/illegal-bin/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 = "examples"
version = "0.0.0"

View File

@ -0,0 +1,15 @@
# This cargo workspace contains a member called "examples"
# If we drop a dummy file in `src/main.rs` cargo will complain with:
#
# error: failed to load manifest for workspace member `/build/dummy-src/examples`
# Caused by:
# failed to parse manifest at `/build/dummy-src/examples/Cargo.toml`
# Caused by:
# the binary target name `examples` is forbidden, it conflicts with with cargo's build directory names
#
# Instead we need to drop a dummy file at `src/lib.rs`, and this is a
# regression test for that case.
[workspace]
members = [
"examples",
]

View File

@ -0,0 +1,9 @@
[package]
name = "examples"
version = "0.0.0"
publish = false
edition = "2021"
[[example]]
name = "foo"
path = "foo.rs"

View File

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

View File

@ -1,2 +0,0 @@
#![allow(dead_code)]
pub fn main() {}

View File

@ -1,2 +0,0 @@
#![allow(dead_code)]
pub fn main() {}

View File

@ -1,2 +0,0 @@
#![allow(dead_code)]
pub fn main() {}

View File

@ -96,7 +96,7 @@ let
# To build build-dependencies
${cpDummy parentDir "build.rs"}
# To build regular and dev dependencies (cargo build + cargo test)
${cpDummy parentDir "src/main.rs"}
${cpDummy parentDir "src/lib.rs"}
# Stub all other targets in case they have particular feature combinations
${safeStubLib}