mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
cleanup
This commit is contained in:
parent
287090ae5a
commit
e4c7ed319b
38
Cargo.toml
38
Cargo.toml
@ -1,43 +1,9 @@
|
||||
[package]
|
||||
name = "fluence"
|
||||
version = "0.5.0" # remember to update html_root_url
|
||||
description = "Fluence backend SDK for developing backend applications for the Fluence network"
|
||||
documentation = "https://docs.rs/fluence/"
|
||||
repository = "https://github.com/fluencelabs/rust-sdk"
|
||||
authors = ["Fluence Labs"]
|
||||
readme = "README.md"
|
||||
keywords = ["fluence", "sdk", "webassembly"]
|
||||
categories = ["api-bindings", "wasm"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata.docs.rs] # https://docs.rs/about
|
||||
all-features = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-macro = { path = "crates/fce-macro", version = "=0.5.0" }
|
||||
fluence-sdk-test-macro = { path = "crates/fce-test-macro", version = "=0.5.0", optional = true }
|
||||
fluence-sdk-main = { path = "crates/main", version = "=0.5.0" }
|
||||
|
||||
fluence-app-service= { version = "0.5.2", features = ["raw-module-api"], optional = true }
|
||||
|
||||
[features]
|
||||
# Print some internal logs by log_utf8_string
|
||||
debug = ["fluence-sdk-main/debug"]
|
||||
|
||||
# Enable logger (this will cause log_utf8_string to appear in imports)
|
||||
logger = ["fluence-sdk-main/logger"]
|
||||
|
||||
# Enable the fce-test features (it'll bring fluence-app-service as a dependency)
|
||||
fce-test = ["fluence-sdk-test-macro", "fluence-app-service"]
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/fce-macro",
|
||||
"crates/fce-test-macro",
|
||||
"crates/main",
|
||||
"crates/wit",
|
||||
"fluence",
|
||||
"fluence-test"
|
||||
]
|
||||
|
@ -18,7 +18,6 @@ proc-macro = true
|
||||
[dependencies]
|
||||
quote = "1.0.9"
|
||||
proc-macro2 = "1.0.24"
|
||||
serde = { version = "=1.0.118", features = ["derive"] }
|
||||
serde_json = "1.0.56"
|
||||
syn = { version = '1.0.64', features = ['full'] }
|
||||
uuid = { version = "0.8.2", features = ["v4"] }
|
||||
darling = "0.12.2"
|
||||
|
@ -14,48 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use syn::parse::Parse;
|
||||
use syn::parse::ParseStream;
|
||||
use darling::FromMeta;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[derive(Debug, Default, Clone, FromMeta)]
|
||||
pub(crate) struct FCETestAttributes {
|
||||
pub(crate) config_path: String,
|
||||
}
|
||||
|
||||
impl Parse for FCETestAttributes {
|
||||
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
||||
let config_file_path = parse_config_file_path(input)?;
|
||||
let attributes = FCETestAttributes {
|
||||
config_path: config_file_path,
|
||||
};
|
||||
|
||||
Ok(attributes)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_config_file_path(token_stream: ParseStream<'_>) -> syn::Result<String> {
|
||||
let attr_name = token_stream.step(|cursor| match cursor.ident() {
|
||||
Some((ident, rem)) => Ok((ident, rem)),
|
||||
None => Err(cursor.error("Expected a valid identifier")),
|
||||
})?;
|
||||
|
||||
match attr_name.to_string().as_str() {
|
||||
"config" => {
|
||||
// trying to parse `=`
|
||||
token_stream.parse::<syn::token::Eq>()?;
|
||||
|
||||
match token_stream.parse::<syn::Ident>() {
|
||||
Ok(config_file_path) => Ok(config_file_path.to_string()),
|
||||
Err(e) => Err(syn::Error::new(
|
||||
attr_name.span(),
|
||||
format!("failed to parse a config file path: {}", e),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
attr => Err(syn::Error::new(
|
||||
attr_name.span(),
|
||||
format!("Expected 'config' identifier, but {} found", attr),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
@ -14,22 +14,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use crate::attributes::FCETestAttributes;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
|
||||
pub(super) fn fce_test_impl(
|
||||
attr: TokenStream,
|
||||
func_input: syn::ItemFn,
|
||||
) -> Result<TokenStream, TokenStream> {
|
||||
use crate::attributes::FCETestAttributes;
|
||||
pub(super) fn fce_test_impl(attrs: TokenStream, func_input: syn::ItemFn) -> TokenStream {
|
||||
use darling::FromMeta;
|
||||
|
||||
let attrs = syn::parse2::<FCETestAttributes>(attr).map_err(|e| e.into_compile_error())?;
|
||||
let generated_test = generate_test_glue_code(func_input, &attrs.config_path);
|
||||
let attrs = syn::parse_macro_input!(attrs as syn::AttributeArgs);
|
||||
let attrs = match FCETestAttributes::from_list(&attrs) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
return TokenStream::from(e.write_errors());
|
||||
}
|
||||
};
|
||||
|
||||
Ok(generated_test)
|
||||
generate_test_glue_code(func_input, &attrs.config_path).into()
|
||||
}
|
||||
|
||||
fn generate_test_glue_code(func: syn::ItemFn, config_path: &str) -> TokenStream {
|
||||
fn generate_test_glue_code(func: syn::ItemFn, config_path: &str) -> TokenStream2 {
|
||||
let fce_ctor = generate_fce_ctor(config_path);
|
||||
let original_block = func.block;
|
||||
let signature = func.sig;
|
||||
@ -44,27 +49,23 @@ fn generate_test_glue_code(func: syn::ItemFn, config_path: &str) -> TokenStream
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_fce_ctor(config_path: &str) -> TokenStream {
|
||||
let config_path = new_ident(config_path);
|
||||
fn generate_fce_ctor(config_path: &str) -> TokenStream2 {
|
||||
let config_path = quote! { #config_path };
|
||||
|
||||
let tmp_file_path = std::env::temp_dir();
|
||||
let random_uuid = uuid::Uuid::new_v4().to_string();
|
||||
let service_id = new_ident(&random_uuid);
|
||||
let service_id = quote! { #random_uuid };
|
||||
|
||||
let tmp_file_path = tmp_file_path.join(random_uuid);
|
||||
let tmp_file_path = tmp_file_path.to_string_lossy().to_string();
|
||||
let tmp_file_path = new_ident(&tmp_file_path);
|
||||
let tmp_file_path = quote! { #tmp_file_path };
|
||||
|
||||
quote! {
|
||||
let mut __fce__generated_fce_config = fluence::internal::test::TomlAppServiceConfig::load(#config_path)
|
||||
let mut __fce__generated_fce_config = fluence_test::internal::TomlAppServiceConfig::load(#config_path.to_string())
|
||||
.unwrap_or_else(|e| panic!("app service located at `{}` config can't be loaded: {}", #config_path, e));
|
||||
__fce__generated_fce_config.service_base_dir = Some(#tmp_file_path);
|
||||
__fce__generated_fce_config.service_base_dir = Some(#tmp_file_path.to_string());
|
||||
|
||||
let fce = fluence::internal::test::AppService::new_with_empty_facade(__fce__generated_fce_config, #service_id, std::collections::HashMap::new())
|
||||
let mut fce = fluence_test::internal::AppService::new_with_empty_facade(__fce__generated_fce_config, #service_id, std::collections::HashMap::new())
|
||||
.unwrap_or_else(|e| panic!("app service can't be created: {}", e));
|
||||
}
|
||||
}
|
||||
|
||||
fn new_ident(name: &str) -> syn::Ident {
|
||||
syn::Ident::new(name, proc_macro2::Span::call_site())
|
||||
}
|
||||
|
@ -15,16 +15,15 @@
|
||||
*/
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/fluence-sdk-macro/0.4.2")]
|
||||
/*
|
||||
#![deny(
|
||||
dead_code,
|
||||
nonstandard_style,
|
||||
unused_imports,
|
||||
unused_mut,
|
||||
unused_variables,
|
||||
unused_unsafe,
|
||||
unreachable_patterns
|
||||
)]
|
||||
*/
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![recursion_limit = "1024"]
|
||||
|
||||
@ -56,7 +55,5 @@ use proc_macro::TokenStream;
|
||||
#[proc_macro_attribute]
|
||||
pub fn fce_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let func_input = syn::parse_macro_input!(input as syn::ItemFn);
|
||||
let result = fce_test_impl(attrs.into(), func_input).unwrap_or_else(std::convert::identity);
|
||||
|
||||
result.into()
|
||||
fce_test_impl(attrs.into(), func_input)
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ macro_rules! module_manifest {
|
||||
+ __FCE_SDK_REPOSITORY_SIZE
|
||||
+ __FCE_SDK_FIELD_PREFIX_SIZE * 4;
|
||||
|
||||
const fn append_data(
|
||||
const fn __fce_sdk_append_data(
|
||||
mut manifest: [u8; __FCE_MANIFEST_SIZE],
|
||||
data: &'static str,
|
||||
offset: usize,
|
||||
@ -63,10 +63,10 @@ macro_rules! module_manifest {
|
||||
let manifest: [u8; __FCE_MANIFEST_SIZE] = [0; __FCE_MANIFEST_SIZE];
|
||||
|
||||
let offset = 0;
|
||||
let (manifest, offset) = append_data(manifest, $authors, offset);
|
||||
let (manifest, offset) = append_data(manifest, $version, offset);
|
||||
let (manifest, offset) = append_data(manifest, $description, offset);
|
||||
let (manifest, _) = append_data(manifest, $repository, offset);
|
||||
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);
|
||||
|
||||
manifest
|
||||
}
|
||||
|
22
fluence-test/Cargo.toml
Normal file
22
fluence-test/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "fluence-test"
|
||||
version = "0.5.0" # remember to update html_root_url
|
||||
description = "Fluence backend SDK for testing"
|
||||
documentation = "https://docs.rs/fluence/"
|
||||
repository = "https://github.com/fluencelabs/rust-sdk"
|
||||
authors = ["Fluence Labs"]
|
||||
readme = "README.md"
|
||||
keywords = ["fluence", "sdk", "webassembly"]
|
||||
categories = ["api-bindings", "wasm"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata.docs.rs] # https://docs.rs/about
|
||||
all-features = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "=0.5.0" }
|
||||
fluence-app-service= { version = "0.5.2", features = ["raw-module-api"] }
|
36
fluence-test/src/lib.rs
Normal file
36
fluence-test/src/lib.rs
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/fluence/0.5.0")]
|
||||
#![deny(
|
||||
dead_code,
|
||||
nonstandard_style,
|
||||
unused_imports,
|
||||
unused_mut,
|
||||
unused_variables,
|
||||
unused_unsafe,
|
||||
unreachable_patterns
|
||||
)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
pub use fluence_sdk_test_macro::fce_test;
|
||||
|
||||
/// These API functions are intended for internal usage in generated code.
|
||||
/// Normally, you shouldn't use them.
|
||||
pub mod internal {
|
||||
pub use fluence_app_service::AppService;
|
||||
pub use fluence_app_service::TomlAppServiceConfig;
|
||||
}
|
29
fluence/Cargo.toml
Normal file
29
fluence/Cargo.toml
Normal file
@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "fluence"
|
||||
version = "0.5.0" # remember to update html_root_url
|
||||
description = "Fluence backend SDK for developing backend applications for the Fluence network"
|
||||
documentation = "https://docs.rs/fluence/"
|
||||
repository = "https://github.com/fluencelabs/rust-sdk"
|
||||
authors = ["Fluence Labs"]
|
||||
readme = "README.md"
|
||||
keywords = ["fluence", "sdk", "webassembly"]
|
||||
categories = ["api-bindings", "wasm"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata.docs.rs] # https://docs.rs/about
|
||||
all-features = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-macro = { path = "../crates/fce-macro", version = "=0.5.0" }
|
||||
fluence-sdk-main = { path = "../crates/main", version = "=0.5.0" }
|
||||
|
||||
[features]
|
||||
# Print some internal logs by log_utf8_string
|
||||
debug = ["fluence-sdk-main/debug"]
|
||||
|
||||
# Enable logger (this will cause log_utf8_string to appear in imports)
|
||||
logger = ["fluence-sdk-main/logger"]
|
@ -94,10 +94,4 @@ 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;
|
||||
|
||||
#[cfg(feature = "fce-test")]
|
||||
pub mod test {
|
||||
pub use fluence_app_service::AppService;
|
||||
pub use fluence_app_service::AppServiceConfig;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user