diff --git a/scarb/src/core/manifest/toml_manifest.rs b/scarb/src/core/manifest/toml_manifest.rs index c4287cd00..64485e847 100644 --- a/scarb/src/core/manifest/toml_manifest.rs +++ b/scarb/src/core/manifest/toml_manifest.rs @@ -24,8 +24,8 @@ use crate::core::manifest::{ManifestDependency, ManifestMetadata, Summary, Targe use crate::core::package::PackageId; use crate::core::source::{GitReference, SourceId}; use crate::core::{ - DepKind, DependencyVersionReq, InliningStrategy, ManifestBuilder, ManifestCompilerConfig, - PackageName, TargetKind, TestTargetProps, TestTargetType, + Config, DepKind, DependencyVersionReq, InliningStrategy, ManifestBuilder, + ManifestCompilerConfig, PackageName, TargetKind, TestTargetProps, TestTargetType, }; use crate::internal::fsx; use crate::internal::fsx::PathBufUtf8Ext; @@ -407,6 +407,7 @@ impl TomlManifest { source_id: SourceId, profile: Profile, workspace_manifest: Option<&TomlManifest>, + config: &Config, ) -> Result { let root = manifest_path .parent() @@ -582,7 +583,15 @@ impl TomlManifest { .clone() .map(|edition| edition.resolve("edition", || inheritable_package.edition())) .transpose()? - .unwrap_or_default(); + .unwrap_or_else(|| { + if !targets.iter().any(Target::is_cairo_plugin) { + config.ui().warn(format!( + "`edition` field not set in `[package]` section for package `{}`", + package_id.name + )); + } + Edition::default() + }); // TODO (#1040): add checking for fields that are not present in ExperimentalFeaturesConfig let experimental_features = package.experimental_features.clone(); diff --git a/scarb/src/ops/workspace.rs b/scarb/src/ops/workspace.rs index 2b6aedcf0..c2b7c679e 100644 --- a/scarb/src/ops/workspace.rs +++ b/scarb/src/ops/workspace.rs @@ -86,6 +86,7 @@ fn read_workspace_root<'c>( source_id, config.profile(), Some(&toml_manifest), + config, ) .with_context(|| format!("failed to parse manifest at: {manifest_path}"))?; let manifest = Box::new(manifest); @@ -119,6 +120,7 @@ fn read_workspace_root<'c>( source_id, config.profile(), Some(&toml_manifest), + config, ) .with_context(|| format!("failed to parse manifest at: {manifest_path}"))?; let manifest = Box::new(manifest); diff --git a/scarb/tests/add.rs b/scarb/tests/add.rs index 472460edf..33855d040 100644 --- a/scarb/tests/add.rs +++ b/scarb/tests/add.rs @@ -16,6 +16,7 @@ fn registry_with_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -24,6 +25,7 @@ fn registry_with_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -40,6 +42,7 @@ fn registry_with_caret_version_req() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -48,6 +51,7 @@ fn registry_with_caret_version_req() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -64,6 +68,7 @@ fn registry_without_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .failure() .stdout_matches(indoc! {r#" @@ -80,11 +85,13 @@ fn no_dependencies_section() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "1.0.0" @@ -100,6 +107,7 @@ fn dry_run() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -128,11 +136,13 @@ fn path() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { path = "../dep" } @@ -158,11 +168,13 @@ fn path_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { version = "1.0.0", path = "../dep" } @@ -188,11 +200,13 @@ fn runs_resolver_if_network_is_allowed() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { version = "1.0.0", path = "../dep" } @@ -212,11 +226,13 @@ fn git() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { git = "https://example.com/" } @@ -232,11 +248,13 @@ fn git_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { version = "1.0.0", git = "https://example.com/" } @@ -256,11 +274,13 @@ fn git_spec(what: &str) { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(formatdoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = {{ git = "https://example.com/", {what} = "abcd" }} @@ -276,6 +296,7 @@ fn overwrite_registry_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "1.0.0" @@ -284,6 +305,7 @@ fn overwrite_registry_version() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "2.0.0" @@ -299,6 +321,7 @@ fn overwrite_registry_version_simplifies() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { version = "1.0.0" } @@ -307,6 +330,7 @@ fn overwrite_registry_version_simplifies() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "2.0.0" @@ -338,6 +362,7 @@ fn overwrite_change_source_from_path_to_git() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { version = "1.2.3", path = "../dep" } @@ -346,6 +371,7 @@ fn overwrite_change_source_from_path_to_git() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = { version = "1.2.3", git = "https://example.com/", branch = "abc" } @@ -361,6 +387,7 @@ fn should_sort_if_already_sorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -371,6 +398,7 @@ fn should_sort_if_already_sorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -386,6 +414,7 @@ fn should_sort_if_already_sorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -397,6 +426,7 @@ fn should_sort_if_already_sorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -413,6 +443,7 @@ fn should_sort_if_already_sorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -425,6 +456,7 @@ fn should_sort_if_already_sorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -445,6 +477,7 @@ fn should_not_sort_if_already_unsorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -455,6 +488,7 @@ fn should_not_sort_if_already_unsorted() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -473,11 +507,13 @@ fn add_dev_dep() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .output(indoc! {r#" [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dev-dependencies] foo = "1.0.0" @@ -493,6 +529,7 @@ fn add_git_dep_with_invalid_url() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .failure() .stdout_matches(indoc! {r#" diff --git a/scarb/tests/build.rs b/scarb/tests/build.rs index 4d2407dbc..a6f9a5f0e 100644 --- a/scarb/tests/build.rs +++ b/scarb/tests/build.rs @@ -278,6 +278,7 @@ fn compile_with_incompatible_cairo_version() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" cairo-version = "33.33.0" "#, ) @@ -344,6 +345,27 @@ fn compile_with_invalid_non_numeric_dep_version() { "#}); } +#[test] +fn compile_with_unset_edition() { + let t = TempDir::new().unwrap(); + ProjectBuilder::start() + .name("hello") + .version("0.1.0") + .no_edition() + .build(&t); + + Scarb::quick_snapbox() + .arg("build") + .current_dir(&t) + .assert() + .success() + .stdout_matches(indoc! {r#" + warn: `edition` field not set in `[package]` section for package `hello` + [..] Compiling hello v0.1.0 ([..]Scarb.toml) + [..] Finished `dev` profile target(s) in [..] + "#}); +} + #[test] fn compile_multiple_packages() { let t = TempDir::new().unwrap(); @@ -354,6 +376,7 @@ fn compile_multiple_packages() { [package] name = "fib" version = "1.0.0" + edition = "2023_01" [dependencies] decrement = { path = "decrement" } @@ -386,6 +409,7 @@ fn compile_multiple_packages() { [package] name = "decrement" version = "1.0.0" + edition = "2023_01" "#, ) .unwrap(); @@ -422,6 +446,7 @@ fn compile_with_nested_deps() { [package] name = "x" version = "1.0.0" + edition = "2023_01" [dependencies] y = { path = "y" } @@ -439,6 +464,7 @@ fn compile_with_nested_deps() { [package] name = "y" version = "1.0.0" + edition = "2023_01" [dependencies] q = { path = "../q" } @@ -457,6 +483,7 @@ fn compile_with_nested_deps() { [package] name = "z" version = "1.0.0" + edition = "2023_01" [dependencies] q = { path = "../q" } @@ -474,6 +501,7 @@ fn compile_with_nested_deps() { [package] name = "q" version = "1.0.0" + edition = "2023_01" "#, ) .unwrap(); diff --git a/scarb/tests/build_targets.rs b/scarb/tests/build_targets.rs index 478b1e7c1..630e1547e 100644 --- a/scarb/tests/build_targets.rs +++ b/scarb/tests/build_targets.rs @@ -22,6 +22,7 @@ fn compile_with_duplicate_targets_1() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" [[target.example]] @@ -52,6 +53,7 @@ fn compile_with_duplicate_targets_2() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" [[target.example]] name = "x" @@ -84,6 +86,7 @@ fn compile_with_custom_lib_target() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" [lib] name = "not_hello" @@ -130,6 +133,7 @@ fn compile_with_named_default_lib_target() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" [lib] name = "not_hello" @@ -173,6 +177,7 @@ fn compile_with_lib_target_in_target_array() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" [[target.lib]] name = "not_hello" diff --git a/scarb/tests/features.rs b/scarb/tests/features.rs index 90e96b8cb..5a00ceb0a 100644 --- a/scarb/tests/features.rs +++ b/scarb/tests/features.rs @@ -240,9 +240,9 @@ fn features_fail_incorrect_manifest() { error: failed to parse manifest at: [..]/Scarb.toml Caused by: - TOML parse error at line 8, column 1 + TOML parse error at line 9, column 1 | - 8 | 8x = [] + 9 | 8x = [] | ^^ the name `8x` cannot be used as a package name, names cannot start with a digit "#}) diff --git a/scarb/tests/fmt.rs b/scarb/tests/fmt.rs index 4fe3c8fea..ec87440d3 100644 --- a/scarb/tests/fmt.rs +++ b/scarb/tests/fmt.rs @@ -24,6 +24,7 @@ fn build_temp_dir(data: &str) -> TempDir { [package] name = "hello" version = "0.1.0" + edition = "2023_01" "#, ) .unwrap(); @@ -169,6 +170,7 @@ fn format_with_import_sorting() { [package] name = "hello" version = "0.1.0" + edition = "2023_01" [tool.fmt] sort-module-level-items = true "#, diff --git a/scarb/tests/git_source.rs b/scarb/tests/git_source.rs index 86fe2ef77..d621cc5fe 100644 --- a/scarb/tests/git_source.rs +++ b/scarb/tests/git_source.rs @@ -190,9 +190,9 @@ fn fetch_with_short_ssh_git() { error: failed to parse manifest at: [..] Caused by: - TOML parse error at line 6, column 7 + TOML parse error at line 7, column 7 | - 6 | dep = { git = "git@github.com:a/dep" } + 7 | dep = { git = "git@github.com:a/dep" } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ data did not match any variant of untagged enum TomlDependency "#}); diff --git a/scarb/tests/local_registry.rs b/scarb/tests/local_registry.rs index ba5ca10cc..27b789c45 100644 --- a/scarb/tests/local_registry.rs +++ b/scarb/tests/local_registry.rs @@ -193,7 +193,7 @@ fn publish() { { "v": "1.0.0", "deps": [], - "cksum": "sha256:3771f51595f7df697a822823989714b3c9a83764a67fa517ac6d8df3cfc642bf", + "cksum": "sha256:40c6063030324bfbaf47f23f9b2557428fecf35deb94c2dd756e2cefe89084aa", } ]) ); @@ -206,12 +206,12 @@ fn publish() { { "v": "1.0.0", "deps": [], - "cksum": "sha256:07db55042bb0be41eb957d649960cd16764426ce9df1cd0729d408acdf3c63cb", + "cksum": "sha256:effe1d6260bc79dd77b07a65bf4d5010ce16d88847c0a08b4a74c2dfa065e37c", }, { "v": "1.1.0", "deps": [], - "cksum": "sha256:bd36828fa2134ec3ce9599511404f85958d8ed091fc3b03a3f3d8426d0a0f720", + "cksum": "sha256:88113a5dd5996502a5b0f8dbc6809145d57af1f58ed9438cf7d217d7a73de20e", } ]) ); @@ -271,7 +271,7 @@ fn publish_overwrites_existing() { { "v": "1.0.0", "deps": [], - "cksum": "sha256:b34e1202407e1a9b743f261cdc27723d0344619a6dc3058bdacd9b17f6106027", + "cksum": "sha256:cc09cbd0906f8387f8f02e2ed1378655fa3125eac4df2e9c2c78d2fea09a576f", } ]) ); @@ -299,7 +299,7 @@ fn publish_overwrites_existing() { { "v": "1.0.0", "deps": [], - "cksum": "sha256:4682a7645acf0b342556778a0544e2871ae910efc609d89ab3bedf9491219ab5", + "cksum": "sha256:108fb6aca5303b97e09159eb61d6741ac2d434972a1e789f7e1daaf770faa768", } ]) ); diff --git a/scarb/tests/remove.rs b/scarb/tests/remove.rs index 7e400036f..15396ec16 100644 --- a/scarb/tests/remove.rs +++ b/scarb/tests/remove.rs @@ -10,6 +10,7 @@ fn remove_one() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "1.0.0" @@ -20,6 +21,7 @@ fn remove_one() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "1.0.0" @@ -37,6 +39,7 @@ fn multiple_deps() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "1.0.0" @@ -47,6 +50,7 @@ fn multiple_deps() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] foo = "1.0.0" @@ -63,6 +67,7 @@ fn undefined_dep() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] dep = "1.0.0" @@ -83,6 +88,7 @@ fn no_dependencies_section() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" "#}) .failure() .stdout_matches(indoc! {r#" Removing dep from dependencies @@ -99,6 +105,7 @@ fn dry_run() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -107,6 +114,7 @@ fn dry_run() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dependencies] bar = "1.0.0" @@ -125,6 +133,7 @@ fn remove_dev_dep() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dev-dependencies] dep = "1.0.0" @@ -135,6 +144,7 @@ fn remove_dev_dep() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dev-dependencies] dep = "1.0.0" @@ -152,6 +162,7 @@ fn remove_undefined_dev_dep() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dev-dependencies] dep = "1.0.0" @@ -161,6 +172,7 @@ fn remove_undefined_dev_dep() { [package] name = "hello" version = "1.0.0" + edition = "2023_01" [dev-dependencies] dep = "1.0.0" diff --git a/utils/scarb-test-support/src/project_builder.rs b/utils/scarb-test-support/src/project_builder.rs index 1a76303de..d62d7bdbd 100644 --- a/utils/scarb-test-support/src/project_builder.rs +++ b/utils/scarb-test-support/src/project_builder.rs @@ -37,7 +37,7 @@ impl ProjectBuilder { Self { name: format!("pkg{n}"), version: Version::new(1, n, 0), - edition: None, + edition: "2023_01".to_string().into(), cairo_version: None, src: HashMap::from_iter([( Utf8PathBuf::from("src/lib.cairo"), @@ -65,6 +65,11 @@ impl ProjectBuilder { self } + pub fn no_edition(mut self) -> Self { + self.edition = None; + self + } + pub fn cairo_version(mut self, cairo_version: impl ToVersion) -> Self { self.cairo_version = Some(cairo_version.to_version().unwrap()); self