diff --git a/crates/sui-move-build/src/lib.rs b/crates/sui-move-build/src/lib.rs index 273db6887d739..d7d0c59c1e00a 100644 --- a/crates/sui-move-build/src/lib.rs +++ b/crates/sui-move-build/src/lib.rs @@ -158,23 +158,12 @@ impl BuildConfig { let print_diags_to_stderr = self.print_diags_to_stderr; let run_bytecode_verifier = self.run_bytecode_verifier; let resolution_graph = self.resolution_graph(&path)?; - let result = build_from_resolution_graph( + build_from_resolution_graph( path.clone(), resolution_graph, run_bytecode_verifier, print_diags_to_stderr, - ); - if let Ok(ref compiled) = result { - compiled - .package - .compiled_package_info - .build_flags - .update_lock_file_toolchain_version(&path, env!("CARGO_PKG_VERSION").into()) - .map_err(|e| SuiError::ModuleBuildFailure { - error: format!("Failed to update Move.lock toolchain version: {e}"), - })?; - } - result + ) } pub fn resolution_graph(mut self, path: &Path) -> SuiResult { diff --git a/crates/sui-move/src/build.rs b/crates/sui-move/src/build.rs index 66e50f2b83f7f..717c17362b44d 100644 --- a/crates/sui-move/src/build.rs +++ b/crates/sui-move/src/build.rs @@ -60,7 +60,7 @@ impl Build { run_bytecode_verifier: true, print_diags_to_stderr: true, } - .build(rerooted_path)?; + .build(rerooted_path.clone())?; if dump_bytecode_as_base64 { check_invalid_dependencies(&pkg.dependency_ids.invalid)?; if !with_unpublished_deps { @@ -89,6 +89,11 @@ impl Build { fs::write(layout_filename, layout_str)? } + pkg.package + .compiled_package_info + .build_flags + .update_lock_file_toolchain_version(&rerooted_path, env!("CARGO_PKG_VERSION").into())?; + Ok(()) } } diff --git a/crates/sui/src/client_commands.rs b/crates/sui/src/client_commands.rs index a5d8e4f548e6d..b6a93b6835e19 100644 --- a/crates/sui/src/client_commands.rs +++ b/crates/sui/src/client_commands.rs @@ -1766,7 +1766,7 @@ pub(crate) async fn compile_package( check_unpublished_dependencies(&dependencies.unpublished)?; }; let compiled_package = build_from_resolution_graph( - package_path, + package_path.clone(), resolution_graph, run_bytecode_verifier, print_diags_to_stderr, @@ -1815,6 +1815,16 @@ pub(crate) async fn compile_package( } else { eprintln!("{}", "Skipping dependency verification".bold().yellow()); } + + compiled_package + .package + .compiled_package_info + .build_flags + .update_lock_file_toolchain_version(&package_path, env!("CARGO_PKG_VERSION").into()) + .map_err(|e| SuiError::ModuleBuildFailure { + error: format!("Failed to update Move.lock toolchain version: {e}"), + })?; + Ok((dependencies, compiled_modules, compiled_package, package_id)) } diff --git a/external-crates/move/crates/move-package/src/lib.rs b/external-crates/move/crates/move-package/src/lib.rs index ae7607abe8630..8e59f7ce5519c 100644 --- a/external-crates/move/crates/move-package/src/lib.rs +++ b/external-crates/move/crates/move-package/src/lib.rs @@ -11,7 +11,7 @@ pub mod package_hooks; pub mod resolution; pub mod source_package; -use anyhow::Result; +use anyhow::{anyhow, Result}; use clap::*; use lock_file::LockFile; use move_compiler::{ @@ -22,7 +22,11 @@ use move_core_types::account_address::AccountAddress; use move_model::model::GlobalEnv; use resolution::{dependency_graph::DependencyGraphBuilder, resolution_graph::ResolvedGraph}; use serde::{Deserialize, Serialize}; -use source_package::{layout::SourcePackageLayout, parsed_manifest::DependencyKind}; +use source_package::{ + layout::SourcePackageLayout, + manifest_parser::{parse_move_manifest_string, parse_source_manifest}, + parsed_manifest::DependencyKind, +}; use std::{ collections::BTreeMap, io::{BufRead, Write}, @@ -326,20 +330,34 @@ impl BuildConfig { pub fn update_lock_file_toolchain_version( &self, - path: &PathBuf, + path: &Path, compiler_version: String, ) -> Result<()> { let Some(lock_file) = self.lock_file.as_ref() else { return Ok(()); }; + let path = &SourcePackageLayout::try_find_root(path) + .map_err(|e| anyhow!("Unable to find package root for {}: {e}", path.display()))?; + + // Resolve edition and flavor from `Move.toml` or assign defaults. + let manifest_string = + std::fs::read_to_string(path.join(SourcePackageLayout::Manifest.path()))?; + let toml_manifest = parse_move_manifest_string(manifest_string.clone())?; + let root_manifest = parse_source_manifest(toml_manifest)?; + let edition = root_manifest + .package + .edition + .or(self.default_edition) + .unwrap_or_default(); + let flavor = root_manifest + .package + .flavor + .or(self.default_flavor) + .unwrap_or_default(); + let install_dir = self.install_dir.as_ref().unwrap_or(path).to_owned(); let mut lock = LockFile::from(install_dir, lock_file)?; - update_compiler_toolchain( - &mut lock, - compiler_version, - self.default_edition.unwrap_or_default(), - self.default_flavor.unwrap_or_default(), - )?; + update_compiler_toolchain(&mut lock, compiler_version, edition, flavor)?; let _mutx = PackageLock::lock(); lock.commit(lock_file)?; Ok(()) diff --git a/external-crates/move/crates/move-package/tests/test_lock_file.rs b/external-crates/move/crates/move-package/tests/test_lock_file.rs index dbe8b8bbe4874..0b1ef00f6d67e 100644 --- a/external-crates/move/crates/move-package/tests/test_lock_file.rs +++ b/external-crates/move/crates/move-package/tests/test_lock_file.rs @@ -157,8 +157,19 @@ flavor = "sui" #[test] fn update_lock_file_toolchain_version() { let pkg = create_test_package().unwrap(); - let lock_path = pkg.path().join("Move.lock"); + let move_manifest = pkg.path().join("Move.toml"); + // The 2024.beta in the manifest should override defaults. + fs::write( + &move_manifest, + r#" + [package] + name = "test" + edition = "2024.beta" + "#, + ) + .unwrap(); + let lock_path = pkg.path().join("Move.lock"); let lock = LockFile::new( pkg.path().to_path_buf(), /* manifest_digest */ "42".to_string(), @@ -184,7 +195,7 @@ fn update_lock_file_toolchain_version() { let expected = expect![[r#" compiler-version = "0.0.1" - edition = "2024.alpha" + edition = "2024.beta" flavor = "sui" "#]]; expected.assert_eq(&toml);