diff --git a/Cargo.lock b/Cargo.lock index 5467adcb..a91f4dd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -711,6 +711,7 @@ name = "fce-module-info-parser" version = "0.1.0" dependencies = [ "anyhow", + "chrono", "fluence-sdk-main 0.5.0", "semver 0.11.0", "serde", @@ -1148,7 +1149,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] @@ -2715,11 +2716,12 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi 0.3.9", ] @@ -3096,9 +3098,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" diff --git a/crates/module-info-parser/Cargo.toml b/crates/module-info-parser/Cargo.toml index 8cf0c2fe..2bc61d4a 100644 --- a/crates/module-info-parser/Cargo.toml +++ b/crates/module-info-parser/Cargo.toml @@ -16,6 +16,7 @@ fluence-sdk-main = "0.5.0" wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0" } anyhow = "1.0.31" +chrono = "0.4.19" walrus = "0.18.0" semver = "0.11.0" diff --git a/crates/module-info-parser/src/manifest/errors.rs b/crates/module-info-parser/src/manifest/errors.rs index 71203e3b..05a3e5d9 100644 --- a/crates/module-info-parser/src/manifest/errors.rs +++ b/crates/module-info-parser/src/manifest/errors.rs @@ -47,4 +47,8 @@ pub enum ManifestError { /// Manifest contains some trailing characters. #[error("embedded manifest is corrupted: there are some trailing characters")] ManifestRemainderNotEmpty, + + /// Error occurred while parsing embedded build time. + #[error("build time can't be parsed: {0}")] + DateTimeParseError(#[from] chrono::ParseError), } diff --git a/crates/module-info-parser/src/manifest/module_manifest.rs b/crates/module-info-parser/src/manifest/module_manifest.rs index 0e802e92..f225ad8d 100644 --- a/crates/module-info-parser/src/manifest/module_manifest.rs +++ b/crates/module-info-parser/src/manifest/module_manifest.rs @@ -21,6 +21,7 @@ pub struct ModuleManifest { pub version: semver::Version, pub description: String, pub repository: String, + pub build_time: chrono::DateTime, } use super::ManifestError; @@ -39,16 +40,20 @@ impl TryFrom<&[u8]> for ModuleManifest { let (version, next_offset) = try_extract_field_as_version(value, next_offset, "version")?; let (description, next_offset) = try_extract_field_as_string(value, next_offset, "description")?; let (repository, next_offset) = try_extract_field_as_string(value, next_offset, "repository")?; + let (build_time, next_offset) = try_extract_field_as_string(value, next_offset, "build time")?; if next_offset != value.len() { return Err(ManifestError::ManifestRemainderNotEmpty) } + let build_time = chrono::DateTime::parse_from_rfc3339(&build_time)?; + let manifest = ModuleManifest { authors, version, description, repository, + build_time }; Ok(manifest) @@ -140,6 +145,7 @@ impl fmt::Display for ModuleManifest { writeln!(f, "authors: {}", self.authors)?; writeln!(f, "version: {}", self.version)?; writeln!(f, "description: {}", self.description)?; - write!(f, "repository: {}", self.repository) + writeln!(f, "repository: {}", self.repository)?; + write!(f, "build time: {} UTC", self.build_time) } } diff --git a/crates/module-info-parser/src/manifest/tests.rs b/crates/module-info-parser/src/manifest/tests.rs index f56829cf..09aa299c 100644 --- a/crates/module-info-parser/src/manifest/tests.rs +++ b/crates/module-info-parser/src/manifest/tests.rs @@ -71,6 +71,7 @@ fn test_reading_simple_config() { let version = semver::Version::from_str("0.1.0").unwrap(); let description = "description".to_string(); let repository = "repository".to_string(); + let build_time = chrono::Utc::now(); let mut array = ByteEncoder::new(); @@ -78,6 +79,7 @@ fn test_reading_simple_config() { array.add_utf8_field(&version.to_string()); array.add_utf8_field(&description); array.add_utf8_field(&repository); + array.add_utf8_field(&build_time.to_rfc3339()); let actual: ModuleManifest = array .as_bytes() @@ -89,6 +91,7 @@ fn test_reading_simple_config() { version, description, repository, + build_time: build_time.into(), }; assert_eq!(actual, expected);