From 3580e429c320cee0e59d581b2c08eb177d898ce1 Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 8 Apr 2021 12:38:24 +0300 Subject: [PATCH 1/5] initial version of build time support --- Cargo.toml | 1 + crates/main/Cargo.toml | 3 ++- crates/main/src/module_manifest.rs | 9 +++++-- crates/timestamp-macro/Cargo.toml | 18 +++++++++++++ crates/timestamp-macro/src/lib.rs | 41 ++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 crates/timestamp-macro/Cargo.toml create mode 100644 crates/timestamp-macro/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index c36734b..78a194c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "crates/fce-test-macro", "crates/fce-test-macro-impl", "crates/main", + "crates/timestamp-macro", "crates/wit", "fluence", "fluence-test" diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index 0ad43c8..7dad52d 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -19,7 +19,8 @@ crate-type = ["rlib"] doctest = false [dependencies] -fluence-sdk-macro = { path = "../fce-macro", version = "=0.5.0" } +fluence-sdk-macro = { path = "../fce-macro", version = "0.5.0" } +fce-timestamp-macro = { path = "../timestamp-macro", version = "0.5.0" } log = { version = "0.4.8", features = ["std"] } serde = "=1.0.118" diff --git a/crates/main/src/module_manifest.rs b/crates/main/src/module_manifest.rs index 003864e..66458bb 100644 --- a/crates/main/src/module_manifest.rs +++ b/crates/main/src/module_manifest.rs @@ -20,17 +20,21 @@ pub const MANIFEST_SECTION_NAME: &str = "__fluence_wasm_module_manifest"; #[macro_export] macro_rules! module_manifest { ($authors:expr, $version:expr, $description:expr, $repository:expr) => { + fce_timestamp_macro::build_timestamp!(); + const __FCE_SDK_AUTHORS_SIZE: usize = $authors.as_bytes().len(); const __FCE_SDK_VERSION_SIZE: usize = $version.as_bytes().len(); const __FCE_SDK_DESCRIPTION_SIZE: usize = $description.as_bytes().len(); const __FCE_SDK_REPOSITORY_SIZE: usize = $repository.as_bytes().len(); + const __FCE_SDK_BUILD_TIME_SIZE: usize = __FCE_SDK_BUILD_TIME.as_bytes().len(); const __FCE_SDK_FIELD_PREFIX_SIZE: usize = std::mem::size_of::(); const __FCE_MANIFEST_SIZE: usize = __FCE_SDK_AUTHORS_SIZE + __FCE_SDK_VERSION_SIZE + __FCE_SDK_DESCRIPTION_SIZE + __FCE_SDK_REPOSITORY_SIZE - + __FCE_SDK_FIELD_PREFIX_SIZE * 4; + + __FCE_SDK_BUILD_TIME_SIZE + + __FCE_SDK_FIELD_PREFIX_SIZE * 5; const fn __fce_sdk_append_data( mut manifest: [u8; __FCE_MANIFEST_SIZE], @@ -66,7 +70,8 @@ macro_rules! module_manifest { let (manifest, offset) = __fce_sdk_append_data(manifest, $authors, offset); let (manifest, offset) = __fce_sdk_append_data(manifest, $version, offset); let (manifest, offset) = __fce_sdk_append_data(manifest, $description, offset); - let (manifest, _) = __fce_sdk_append_data(manifest, $repository, offset); + let (manifest, offset) = __fce_sdk_append_data(manifest, $repository, offset); + let (manifest, _) = __fce_sdk_append_data(manifest, __FCE_SDK_BUILD_TIME, offset); manifest } diff --git a/crates/timestamp-macro/Cargo.toml b/crates/timestamp-macro/Cargo.toml new file mode 100644 index 0000000..983bf61 --- /dev/null +++ b/crates/timestamp-macro/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "fce-timestamp-macro" +version = "0.5.0" # remember to update html_root_url +edition = "2018" +description = "Implementation of the `#[build_timestamp]` macro" +repository = "https://github.com/fluencelabs/rust-sdk/crates/timestamp-macro" +authors = ["Fluence Labs"] +keywords = ["fluence", "sdk", "webassembly", "procedural_macros"] +categories = ["api-bindings", "wasm"] +license = "Apache-2.0" + +[lib] +proc-macro = true +doctest = false + +[dependencies] +syn = { version = '1.0.64', features = ['full'] } +chrono = "0.4.19" diff --git a/crates/timestamp-macro/src/lib.rs b/crates/timestamp-macro/src/lib.rs new file mode 100644 index 0000000..9beedc6 --- /dev/null +++ b/crates/timestamp-macro/src/lib.rs @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#![deny( + dead_code, + nonstandard_style, + unused_imports, + unused_mut, + unused_variables, + unused_unsafe, + unreachable_patterns +)] +#![warn(rust_2018_idioms)] +#![recursion_limit = "1024"] + +use proc_macro::TokenStream; + +const FORMAT_STRING: &str = "%H:%M:%S / %Y-%m-%d"; + +#[proc_macro] +pub fn build_timestamp(_: TokenStream) -> TokenStream { + let time = chrono::Utc::now(); + let formatted_time = time.format(FORMAT_STRING); + + let out_str = format!(r#"const __FCE_SDK_BUILD_TIME: &str = {}"#, formatted_time); + + out_str.parse().expect("time formatting should be correct") +} From 176b71b4a15af8b36dca68d720c8e1bd986566a1 Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 8 Apr 2021 12:49:53 +0300 Subject: [PATCH 2/5] split on two crates --- Cargo.toml | 1 + crates/timestamp-macro-impl/Cargo.toml | 18 ++++++++++++ crates/timestamp-macro-impl/src/lib.rs | 40 ++++++++++++++++++++++++++ crates/timestamp-macro/Cargo.toml | 5 ++-- crates/timestamp-macro/src/lib.rs | 9 +----- 5 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 crates/timestamp-macro-impl/Cargo.toml create mode 100644 crates/timestamp-macro-impl/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 78a194c..e11d53e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "crates/fce-test-macro-impl", "crates/main", "crates/timestamp-macro", + "crates/timestamp-macro-impl", "crates/wit", "fluence", "fluence-test" diff --git a/crates/timestamp-macro-impl/Cargo.toml b/crates/timestamp-macro-impl/Cargo.toml new file mode 100644 index 0000000..b30dd74 --- /dev/null +++ b/crates/timestamp-macro-impl/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "fce-timestamp-macro-impl" +version = "0.5.0" # remember to update html_root_url +edition = "2018" +description = "Implementation of the `#[build_timestamp]` macro" +repository = "https://github.com/fluencelabs/rust-sdk/crates/timestamp-macro-impl" +authors = ["Fluence Labs"] +keywords = ["fluence", "sdk", "webassembly", "procedural_macros"] +categories = ["api-bindings", "wasm"] +license = "Apache-2.0" + +[lib] +doctest = false + +[dependencies] +proc-macro2 = "1.0.26" +syn = { version = '1.0.64', features = ['full'] } +chrono = "0.4.19" diff --git a/crates/timestamp-macro-impl/src/lib.rs b/crates/timestamp-macro-impl/src/lib.rs new file mode 100644 index 0000000..e8cfae9 --- /dev/null +++ b/crates/timestamp-macro-impl/src/lib.rs @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#![deny( + dead_code, + nonstandard_style, + unused_imports, + unused_mut, + unused_variables, + unused_unsafe, + unreachable_patterns +)] +#![warn(rust_2018_idioms)] +#![recursion_limit = "1024"] + +use proc_macro2::TokenStream; + +pub const FORMAT_STRING: &str = "%H:%M:%S / %Y-%m-%d"; + +pub fn build_timestamp() -> TokenStream { + let time = chrono::Utc::now(); + let formatted_time = time.format(FORMAT_STRING); + + let out_str = format!(r#"const __FCE_SDK_BUILD_TIME: &str = {}"#, formatted_time); + + out_str.parse().expect("time formatting should be correct") +} diff --git a/crates/timestamp-macro/Cargo.toml b/crates/timestamp-macro/Cargo.toml index 983bf61..64eb8f8 100644 --- a/crates/timestamp-macro/Cargo.toml +++ b/crates/timestamp-macro/Cargo.toml @@ -2,7 +2,7 @@ name = "fce-timestamp-macro" version = "0.5.0" # remember to update html_root_url edition = "2018" -description = "Implementation of the `#[build_timestamp]` macro" +description = "Definition of the `#[build_timestamp]` macro" repository = "https://github.com/fluencelabs/rust-sdk/crates/timestamp-macro" authors = ["Fluence Labs"] keywords = ["fluence", "sdk", "webassembly", "procedural_macros"] @@ -14,5 +14,4 @@ proc-macro = true doctest = false [dependencies] -syn = { version = '1.0.64', features = ['full'] } -chrono = "0.4.19" +fce-timestamp-macro-impl = { path = "../timestamp-macro-impl", version = "0.5.0" } diff --git a/crates/timestamp-macro/src/lib.rs b/crates/timestamp-macro/src/lib.rs index 9beedc6..599efeb 100644 --- a/crates/timestamp-macro/src/lib.rs +++ b/crates/timestamp-macro/src/lib.rs @@ -28,14 +28,7 @@ use proc_macro::TokenStream; -const FORMAT_STRING: &str = "%H:%M:%S / %Y-%m-%d"; - #[proc_macro] pub fn build_timestamp(_: TokenStream) -> TokenStream { - let time = chrono::Utc::now(); - let formatted_time = time.format(FORMAT_STRING); - - let out_str = format!(r#"const __FCE_SDK_BUILD_TIME: &str = {}"#, formatted_time); - - out_str.parse().expect("time formatting should be correct") + fce_timestamp_macro_impl::build_timestamp().into() } From 1a5e28957d5e5a15f9598860bfb9bebfb79f17be Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 8 Apr 2021 13:22:51 +0300 Subject: [PATCH 3/5] finalize --- Cargo.toml | 1 - crates/main/Cargo.toml | 1 - crates/main/src/module_manifest.rs | 2 +- crates/timestamp-macro-impl/Cargo.toml | 18 ------------ crates/timestamp-macro-impl/src/lib.rs | 40 -------------------------- crates/timestamp-macro/Cargo.toml | 3 +- crates/timestamp-macro/src/lib.rs | 7 ++++- fluence/Cargo.toml | 6 ++-- fluence/src/lib.rs | 1 + 9 files changed, 14 insertions(+), 65 deletions(-) delete mode 100644 crates/timestamp-macro-impl/Cargo.toml delete mode 100644 crates/timestamp-macro-impl/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index e11d53e..78a194c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ members = [ "crates/fce-test-macro-impl", "crates/main", "crates/timestamp-macro", - "crates/timestamp-macro-impl", "crates/wit", "fluence", "fluence-test" diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index 7dad52d..e33ac9f 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -20,7 +20,6 @@ doctest = false [dependencies] fluence-sdk-macro = { path = "../fce-macro", version = "0.5.0" } -fce-timestamp-macro = { path = "../timestamp-macro", version = "0.5.0" } log = { version = "0.4.8", features = ["std"] } serde = "=1.0.118" diff --git a/crates/main/src/module_manifest.rs b/crates/main/src/module_manifest.rs index 66458bb..0f05512 100644 --- a/crates/main/src/module_manifest.rs +++ b/crates/main/src/module_manifest.rs @@ -20,7 +20,7 @@ pub const MANIFEST_SECTION_NAME: &str = "__fluence_wasm_module_manifest"; #[macro_export] macro_rules! module_manifest { ($authors:expr, $version:expr, $description:expr, $repository:expr) => { - fce_timestamp_macro::build_timestamp!(); + fluence::internal::build_timestamp!(); const __FCE_SDK_AUTHORS_SIZE: usize = $authors.as_bytes().len(); const __FCE_SDK_VERSION_SIZE: usize = $version.as_bytes().len(); diff --git a/crates/timestamp-macro-impl/Cargo.toml b/crates/timestamp-macro-impl/Cargo.toml deleted file mode 100644 index b30dd74..0000000 --- a/crates/timestamp-macro-impl/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "fce-timestamp-macro-impl" -version = "0.5.0" # remember to update html_root_url -edition = "2018" -description = "Implementation of the `#[build_timestamp]` macro" -repository = "https://github.com/fluencelabs/rust-sdk/crates/timestamp-macro-impl" -authors = ["Fluence Labs"] -keywords = ["fluence", "sdk", "webassembly", "procedural_macros"] -categories = ["api-bindings", "wasm"] -license = "Apache-2.0" - -[lib] -doctest = false - -[dependencies] -proc-macro2 = "1.0.26" -syn = { version = '1.0.64', features = ['full'] } -chrono = "0.4.19" diff --git a/crates/timestamp-macro-impl/src/lib.rs b/crates/timestamp-macro-impl/src/lib.rs deleted file mode 100644 index e8cfae9..0000000 --- a/crates/timestamp-macro-impl/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2020 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#![deny( - dead_code, - nonstandard_style, - unused_imports, - unused_mut, - unused_variables, - unused_unsafe, - unreachable_patterns -)] -#![warn(rust_2018_idioms)] -#![recursion_limit = "1024"] - -use proc_macro2::TokenStream; - -pub const FORMAT_STRING: &str = "%H:%M:%S / %Y-%m-%d"; - -pub fn build_timestamp() -> TokenStream { - let time = chrono::Utc::now(); - let formatted_time = time.format(FORMAT_STRING); - - let out_str = format!(r#"const __FCE_SDK_BUILD_TIME: &str = {}"#, formatted_time); - - out_str.parse().expect("time formatting should be correct") -} diff --git a/crates/timestamp-macro/Cargo.toml b/crates/timestamp-macro/Cargo.toml index 64eb8f8..329e972 100644 --- a/crates/timestamp-macro/Cargo.toml +++ b/crates/timestamp-macro/Cargo.toml @@ -14,4 +14,5 @@ proc-macro = true doctest = false [dependencies] -fce-timestamp-macro-impl = { path = "../timestamp-macro-impl", version = "0.5.0" } +chrono = "0.4.19" +quote = "1.0.9" diff --git a/crates/timestamp-macro/src/lib.rs b/crates/timestamp-macro/src/lib.rs index 599efeb..23edfc9 100644 --- a/crates/timestamp-macro/src/lib.rs +++ b/crates/timestamp-macro/src/lib.rs @@ -28,7 +28,12 @@ use proc_macro::TokenStream; + #[proc_macro] pub fn build_timestamp(_: TokenStream) -> TokenStream { - fce_timestamp_macro_impl::build_timestamp().into() + let current_utc_date = chrono::Utc::now(); + let current_utc_date = current_utc_date.to_rfc3339(); + + let glue_code = quote::quote! { const __FCE_SDK_BUILD_TIME: &str = #current_utc_date; }; + glue_code.into() } diff --git a/fluence/Cargo.toml b/fluence/Cargo.toml index a8803f1..459489a 100644 --- a/fluence/Cargo.toml +++ b/fluence/Cargo.toml @@ -19,8 +19,10 @@ path = "src/lib.rs" doctest = false [dependencies] -fluence-sdk-macro = { path = "../crates/fce-macro", version = "=0.5.0" } -fluence-sdk-main = { path = "../crates/main", version = "=0.5.0" } +fluence-sdk-macro = { path = "../crates/fce-macro", version = "0.5.0" } +fluence-sdk-main = { path = "../crates/main", version = "0.5.0" } + +fce-timestamp-macro = { path = "../crates/timestamp-macro", version = "0.5.0" } [dev-dependencies] trybuild = "1.0" diff --git a/fluence/src/lib.rs b/fluence/src/lib.rs index 24d6e59..0e12d3a 100644 --- a/fluence/src/lib.rs +++ b/fluence/src/lib.rs @@ -94,4 +94,5 @@ pub mod internal { pub use fluence_sdk_main::get_result_size; pub use fluence_sdk_main::set_result_ptr; pub use fluence_sdk_main::set_result_size; + pub use fce_timestamp_macro::build_timestamp; } From 22c493b8fd119d9b85e47b0784f5dec4c956663a Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 8 Apr 2021 13:36:45 +0300 Subject: [PATCH 4/5] fmt --- crates/timestamp-macro/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/timestamp-macro/src/lib.rs b/crates/timestamp-macro/src/lib.rs index 23edfc9..4b2740f 100644 --- a/crates/timestamp-macro/src/lib.rs +++ b/crates/timestamp-macro/src/lib.rs @@ -28,11 +28,10 @@ use proc_macro::TokenStream; - #[proc_macro] pub fn build_timestamp(_: TokenStream) -> TokenStream { let current_utc_date = chrono::Utc::now(); - let current_utc_date = current_utc_date.to_rfc3339(); + let current_utc_date = current_utc_date.to_rfc3339(); let glue_code = quote::quote! { const __FCE_SDK_BUILD_TIME: &str = #current_utc_date; }; glue_code.into() From 23aae3cae628efd9505132edf50114641a0f82cf Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 9 Apr 2021 11:53:29 +0300 Subject: [PATCH 5/5] update --- crates/fce-macro/Cargo.toml | 2 +- crates/fce-test-macro/Cargo.toml | 2 +- fluence-test/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fce-macro/Cargo.toml b/crates/fce-macro/Cargo.toml index 9c78807..33faf04 100644 --- a/crates/fce-macro/Cargo.toml +++ b/crates/fce-macro/Cargo.toml @@ -18,4 +18,4 @@ proc-macro = true doctest = false [dependencies] -fluence-sdk-wit = { path = "../wit", version = "=0.5.0" } +fluence-sdk-wit = { path = "../wit", version = "0.5.0" } diff --git a/crates/fce-test-macro/Cargo.toml b/crates/fce-test-macro/Cargo.toml index c8578ca..856971d 100644 --- a/crates/fce-test-macro/Cargo.toml +++ b/crates/fce-test-macro/Cargo.toml @@ -17,7 +17,7 @@ proc-macro = true doctest = false [dependencies] -fluence-sdk-test-macro-impl = { path = "../fce-test-macro-impl", version = "=0.5.0" } +fluence-sdk-test-macro-impl = { path = "../fce-test-macro-impl", version = "0.5.0" } quote = "1.0.9" proc-macro2 = "1.0.24" diff --git a/fluence-test/Cargo.toml b/fluence-test/Cargo.toml index 76c4596..937f040 100644 --- a/fluence-test/Cargo.toml +++ b/fluence-test/Cargo.toml @@ -19,7 +19,7 @@ path = "src/lib.rs" doctest = false [dependencies] -fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "=0.5.0" } +fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "0.5.0" } fluence-app-service = { version = "0.5.2", features = ["raw-module-api"] } serde = { version = "1.0.118", features = ["derive"] }