Skip to content

Commit

Permalink
Add support for package.autolib field
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Oct 2, 2024
1 parent aac767c commit f349eca
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<Metadata: for<'a> Deserialize<'a>> Manifest<Metadata> {
// `lib.required-features` has no effect on `[lib]`
// (see https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-required-features-field).
lib.required_features.clear();
} else if src.contains("lib.rs") {
} else if !matches!(package.autolib, Some(false)) && src.contains("lib.rs") {
self.lib = Some(Product {
name: Some(package.name.replace('-', "_")),
path: Some("src/lib.rs".to_string()),
Expand Down Expand Up @@ -1001,6 +1001,9 @@ pub struct Package<Metadata = Value> {
/// The default binary to run by cargo run.
pub default_run: Option<String>,

/// Disables library auto discovery.
#[serde(skip_serializing_if = "Option::is_none")]
pub autolib: Option<bool>,
/// Disables binary auto discovery.
///
/// Use [Manifest::autobins()] to get the effective value.
Expand Down Expand Up @@ -1051,6 +1054,7 @@ impl<Metadata> Package<Metadata> {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
15 changes: 15 additions & 0 deletions tests/autolib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,18 @@ fn test_legacy_lib_with_new_edition() {
let error = Manifest::from_path(tempdir.path().join("Cargo.toml")).unwrap_err();
insta::assert_snapshot!(error, @"can't find library, rename file to `src/lib.rs` or specify lib.path");
}

#[test]
fn test_disabled_autolib() {
let manifest = r#"
[package]
name = "auto-lib"
version = "0.1.0"
edition = "2021"
autolib = false
"#;
let tempdir = utils::prepare(manifest, vec!["src/lib.rs"]);
let m = Manifest::from_path(tempdir.path().join("Cargo.toml")).unwrap();

assert!(m.lib.is_none());
}
1 change: 1 addition & 0 deletions tests/snapshots/autotarget__full_example.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: Some(
false,
),
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__autobuild.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__build_dependencies_casing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__default_features_casing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__dev_dependencies_casing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__legacy-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__legacy.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__metadata.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__opt_level.snap
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__opt_version.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__package_inheritance.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__proc_macro_casing-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__proc_macro_casing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/parse__workspace_dependency-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manifest {
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
Expand Down

0 comments on commit f349eca

Please sign in to comment.