Skip to content

Commit

Permalink
throwing an error when [lib] not specified in Scarb.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
tomek0123456789 committed Nov 3, 2023
1 parent 1c2ba44 commit be5190f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
16 changes: 15 additions & 1 deletion scarb/src/ops/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::{Seek, SeekFrom, Write};

use anyhow::{bail, ensure, Context, Result};
use camino::Utf8PathBuf;
use indoc::writedoc;
use indoc::{formatdoc, writedoc};

use scarb_ui::components::Status;
use scarb_ui::{HumanBytes, HumanCount};
Expand Down Expand Up @@ -156,6 +156,20 @@ fn list_one_impl(
}

fn prepare_archive_recipe(pkg: &Package) -> Result<ArchiveRecipe> {
ensure!(
pkg.manifest.targets.iter().any(|x| x.is_lib()),
formatdoc! {
r#"
package `{package_name}` does not provide a `[lib]` target.
if a package does not provide a library target, it cannot be used as a dependency.
help: add `[lib]` section to package manifest
--> Scarb.toml
+ [lib]
"#,
package_name=pkg.id.name,
}
);

let mut recipe = source_files(pkg)?;

// Sort the recipe before any checks, to ensure generated errors are reproducible.
Expand Down
28 changes: 28 additions & 0 deletions scarb/tests/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,3 +837,31 @@ fn ignore_whitelist_pattern() {
src/lib.cairo
"#}));
}

#[test]
fn no_lib_target() {
let t = TempDir::new().unwrap();
let name = "foo";
let version = "1.0.0";
ProjectBuilder::start()
.name(name)
.version(version)
.manifest_extra(indoc! {r#"
[[target.starknet-contract]]
"#})
.build(&t);

Scarb::quick_snapbox()
.arg("package")
.current_dir(&t)
.assert()
.failure()
.stdout_matches(formatdoc! {r#"
[..] Packaging {name} v{version} [..]
error: package `{name}` does not provide a `[lib]` target.
if a package does not provide a library target, it cannot be used as a dependency.
help: add `[lib]` section to package manifest
--> Scarb.toml
+ [lib]
"#});
}

0 comments on commit be5190f

Please sign in to comment.