mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 06:45:32 +00:00
embed rust sdk version after compiling (#80)
This commit is contained in:
parent
a9494fb780
commit
37c0497914
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -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"
|
||||
|
@ -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<I, O>(
|
||||
in_wasm_module_path: I,
|
||||
out_wasm_module_path: O,
|
||||
version: semver::Version,
|
||||
version: &semver::Version,
|
||||
) -> ModuleInfoResult<()>
|
||||
where
|
||||
I: AsRef<Path>,
|
||||
|
@ -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<P>(path: P) -> Result<()>
|
||||
where
|
||||
P: Into<std::path::PathBuf>,
|
||||
{
|
||||
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)))?;
|
||||
|
@ -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(())
|
||||
|
@ -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),
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user