diff --git a/Cargo.lock b/Cargo.lock index d3c1aa43..06031c23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1487,9 +1487,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "local_storage" diff --git a/crates/module-info-parser/src/sdk_version/version_embedder.rs b/crates/module-info-parser/src/sdk_version/version_embedder.rs index 2c1e846b..97516b37 100644 --- a/crates/module-info-parser/src/sdk_version/version_embedder.rs +++ b/crates/module-info-parser/src/sdk_version/version_embedder.rs @@ -41,7 +41,7 @@ impl CustomSection for VersionCustomSection { /// Embed provided WIT to a Wasm module. pub fn embed_from_module( mut wasm_module: walrus::Module, - version: semver::Version, + version: &semver::Version, ) -> walrus::Module { delete_version_sections(&mut wasm_module); @@ -54,7 +54,7 @@ pub fn embed_from_module( pub fn embed_from_path( in_wasm_module_path: I, out_wasm_module_path: O, - version: semver::Version, + version: &semver::Version, ) -> ModuleInfoResult<()> where I: AsRef, diff --git a/crates/wit-generator/src/interface_generator.rs b/crates/wit-generator/src/interface_generator.rs index c76b0ca7..494793ec 100644 --- a/crates/wit-generator/src/interface_generator.rs +++ b/crates/wit-generator/src/interface_generator.rs @@ -26,7 +26,12 @@ use wasmer_wit::IRecordType; use wasmer_wit::IType; /// Parse generated by rust-sdk AST types, generate instructions and embed them to Wasm file. -pub fn embed_wit(path: std::path::PathBuf) -> Result<()> { +pub fn embed_wit

(path: P) -> Result<()> +where + P: Into, +{ + let path = path.into(); + let wasm_module = walrus::ModuleConfig::new() .parse_file(path.clone()) .map_err(|e| WITGeneratorError::IOError(format!("{:?} can't be parsed: {:?}", path, e)))?; diff --git a/tools/cli/src/build.rs b/tools/cli/src/build.rs index e102e822..2a179f81 100644 --- a/tools/cli/src/build.rs +++ b/tools/cli/src/build.rs @@ -19,6 +19,8 @@ use crate::errors::CLIError; use std::process::Command; +const RUST_SDK_VERSION: &str = "0.6.0"; + #[derive(serde::Deserialize)] #[serde(tag = "reason", rename_all = "kebab-case")] enum DiagnosticMessage { @@ -30,6 +32,7 @@ enum DiagnosticMessage { pub(crate) fn build(trailing_args: Vec<&str>) -> CLIResult<()> { use std::io::Read; + use std::str::FromStr; let mut cargo = Command::new("cargo"); cargo.arg("build").arg("--target").arg("wasm32-wasi"); @@ -70,9 +73,11 @@ pub(crate) fn build(trailing_args: Vec<&str>) -> CLIResult<()> { return Ok(()); } + let version = semver::Version::from_str(RUST_SDK_VERSION).unwrap(); for wasm in wasms { let wasm_path = std::path::PathBuf::from(wasm); - fce_wit_generator::embed_wit(wasm_path)?; + fce_wit_generator::embed_wit(&wasm_path)?; + fce_module_info_parser::sdk_version::embed_from_path(&wasm_path, &wasm_path, &version)?; } Ok(()) diff --git a/tools/cli/src/errors.rs b/tools/cli/src/errors.rs index 3b98a812..59e55821 100644 --- a/tools/cli/src/errors.rs +++ b/tools/cli/src/errors.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use fce_module_info_parser::ModuleInfoError; use fce_wit_generator::WITGeneratorError; use fce_wit_parser::WITParserError; @@ -22,9 +23,13 @@ use thiserror::Error as ThisError; #[derive(Debug, ThisError)] pub enum CLIError { /// Unknown command was entered by user. - #[error("{0} is unknown command")] + #[error("{0} is an unknown command")] NoSuchCommand(String), + /// A error occurred while embedding rust sdk version. + #[error("{0}")] + VersionEmbeddingError(#[from] ModuleInfoError), + /// An error occurred while generating interface types. #[error("{0}")] WITGeneratorError(#[from] WITGeneratorError), diff --git a/tools/cli/src/main.rs b/tools/cli/src/main.rs index e960754a..da970461 100644 --- a/tools/cli/src/main.rs +++ b/tools/cli/src/main.rs @@ -121,7 +121,7 @@ fn set_version(args: &clap::ArgMatches<'_>) -> Result<(), anyhow::Error> { }; let version = semver::Version::from_str(version)?; - sdk_version::embed_from_path(in_wasm_path, out_wasm_path, version)?; + sdk_version::embed_from_path(in_wasm_path, out_wasm_path, &version)?; println!("the version was successfully embedded");