Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta-lib split from meta #1653

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"framework/base",
"framework/derive",
"framework/meta",
"framework/meta-lib",
"framework/scenario",
"framework/snippets",
"framework/wasm-adapter",
Expand Down
4 changes: 2 additions & 2 deletions contracts/feature-tests/abi-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ features = ["alloc"]
version = "0.50.3"
path = "../../../framework/scenario"

[dev-dependencies.multiversx-sc-meta]
[dev-dependencies.multiversx-sc-meta-lib]
version = "0.50.3"
path = "../../../framework/meta"
path = "../../../framework/meta-lib"
16 changes: 8 additions & 8 deletions contracts/feature-tests/abi-tester/tests/abi_tester_abi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use multiversx_sc::{
abi::{EnumVariantDescription, TypeContents, TypeNames},
contract_base::ContractAbiProvider,
};
use multiversx_sc_meta::{
use multiversx_sc_meta_lib::{
abi_json::{self, EsdtAttributeAbiJson},
esdt_attr_file_json::serialize_esdt_attribute_json,
};
Expand All @@ -15,9 +15,9 @@ fn abi_tester_abi_generated_ok() {
let blockchain = ScenarioWorld::new();

// generate ABI
let multi_contract_config = multiversx_sc_meta::multi_contract_config::<abi_tester::AbiProvider>(
blockchain.current_dir().as_path(),
);
let multi_contract_config = multiversx_sc_meta_lib::multi_contract_config::<
abi_tester::AbiProvider,
>(blockchain.current_dir().as_path());

let main_contract = multi_contract_config.find_contract("abi-tester");
assert!(!main_contract.settings.external_view);
Expand Down Expand Up @@ -72,9 +72,9 @@ fn abi_tester_esdt_attr_abi_generated_ok() {
fn check_multi_contract_config() {
let blockchain = ScenarioWorld::new();

let multi_contract_config = multiversx_sc_meta::multi_contract_config::<abi_tester::AbiProvider>(
blockchain.current_dir().as_path(),
);
let multi_contract_config = multiversx_sc_meta_lib::multi_contract_config::<
abi_tester::AbiProvider,
>(blockchain.current_dir().as_path());

let ev_contract = multi_contract_config.find_contract("abi-tester-ev");
assert!(ev_contract.settings.external_view);
Expand All @@ -87,7 +87,7 @@ fn check_multi_contract_config() {
#[test]
fn abi_deserialization_check() {
let main_json = fs::read_to_string("./abi_tester_expected_main.abi.json").unwrap();
let main_abi = multiversx_sc_meta::abi_json::deserialize_abi_from_json(&main_json).unwrap();
let main_abi = multiversx_sc_meta_lib::abi_json::deserialize_abi_from_json(&main_json).unwrap();
let abi_enum_type = main_abi
.types
.get("AbiEnum")
Expand Down
36 changes: 36 additions & 0 deletions framework/meta-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "multiversx-sc-meta-lib"
version = "0.50.3"
edition = "2021"

authors = [
"Andrei Marinica <andrei.marinica@multiversx.com>",
"MultiversX <contact@multiversx.com>",
]
license = "GPL-3.0-only"
readme = "README.md"
repository = "https://github.com/multiversx/mx-sdk-rs"
homepage = "https://multiversx.com/"
documentation = "https://docs.multiversx.com/"
description = "MultiversX smart contract meta-programming tools and build system"
keywords = ["multiversx", "blockchain", "contract", "debug"]
categories = ["cryptography::cryptocurrencies", "development-tools::debugging"]

[dependencies]
clap = { version = "4.4.7", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rustc_version = "0.4"
toml = { version = "0.8.6", features = ["preserve_order"] }
colored = "2.0"
lazy_static = "1.4.0"
convert_case = "0.6.0"
hex = "0.4"
wasmparser = "0.208"
wasmprinter = "0.208"
semver = "1.0.20"

[dependencies.multiversx-sc]
version = "=0.50.3"
path = "../base"
features = ["alloc", "num-bigint"]
14 changes: 14 additions & 0 deletions framework/meta-lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Smart contract `meta` crate support

[![crates.io](https://img.shields.io/crates/v/multiversx-sc-meta.svg)](https://crates.io/crates/multiversx-sc-meta)

The library that provides all the functionality of the individual contracts `meta` crates.

The purpose of the contract `meta` crates is to produce the contract ABI. Because of their access to the ABI, they have other ABI-based responsibilities, such as:
- generatinc the `wasm` crates,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

- building the contracts,
- performing validations not possible otherwise,
- generating snippets,
- etc.

For more about the build process, see https://docs.multiversx.com/developers/developer-reference/sc-build-reference/
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use toml::{value::Table, Value};

use crate::cmd::contract::sc_config::ContractVariantProfile;
use crate::contract::sc_config::ContractVariantProfile;

pub const CARGO_TOML_DEPENDENCIES: &str = "dependencies";
pub const CARGO_TOML_DEV_DEPENDENCIES: &str = "dev-dependencies";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod cli_args_build;
mod cli_args_contract;
mod cli_args_standalone;
mod cli_contract_main;

pub use cli_args_build::*;
pub use cli_args_contract::*;
pub use cli_args_standalone::*;
pub use cli_contract_main::*;

pub trait CliArgsToRaw {
/// Converts to a list of raw arguments, as they would be called in a command.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
mod generate_proxy;
mod generate_snippets;
mod meta_abi;
mod meta_config;
pub mod sc_config;
pub mod wasm_cargo_toml_data;
pub mod wasm_cargo_toml_generate;

use std::path::Path;

use crate::cli_args::{ContractCliAction, ContractCliArgs};
use crate::{
cli::{ContractCliAction, ContractCliArgs},
contract::{meta_config::MetaConfig, sc_config::ScConfig},
};
use clap::Parser;
use meta_config::MetaConfig;
use multiversx_sc::contract_base::ContractAbiProvider;
use sc_config::ScConfig;

/// Entry point in the program from the contract meta crates.
pub fn cli_main<AbiObj: ContractAbiProvider>() {
Expand Down
7 changes: 7 additions & 0 deletions framework/meta-lib/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod generate_proxy;
pub mod generate_snippets;
pub mod meta_abi;
pub mod meta_config;
pub mod sc_config;
pub mod wasm_cargo_toml_data;
pub mod wasm_cargo_toml_generate;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs;

use multiversx_sc::abi::ContractAbi;

use crate::cmd::contract::sc_config::ProxyConfigSerde;
use crate::contract::sc_config::ProxyConfigSerde;

use super::{
super::meta_config::MetaConfig, proxy_crate_gen::create_file, proxy_generator::ProxyGenerator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use multiversx_sc::abi::{
TypeContents, TypeDescription,
};

use crate::cmd::contract::{meta_config::MetaConfig, sc_config::ProxyConfigSerde};
use crate::contract::{meta_config::MetaConfig, sc_config::ProxyConfigSerde};

use super::proxy_process_type_name::{
extract_paths, extract_struct_crate, process_rust_type, proxy_methods_type_name,
Expand Down Expand Up @@ -625,7 +625,7 @@ where
pub mod tests {
use multiversx_sc::abi::{BuildInfoAbi, ContractAbi, ContractCrateBuildAbi, FrameworkBuildAbi};

use crate::cmd::contract::{meta_config::MetaConfig, sc_config::ProxyConfigSerde};
use crate::contract::{meta_config::MetaConfig, sc_config::ProxyConfigSerde};

use super::ProxyGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs::File;

use multiversx_sc::abi::ContractAbi;

use crate::cli_args::GenerateSnippetsArgs;
use crate::cli::GenerateSnippetsArgs;

use super::{
super::meta_config::MetaConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::fs;
use multiversx_sc::abi::ContractAbi;

use crate::{
cli_args::BuildArgs, find_workspace::find_current_workspace,
print_util::print_workspace_target_dir, tools::check_tools_installed, CargoTomlContents,
cargo_toml_contents::CargoTomlContents, cli::BuildArgs, print_util::print_workspace_target_dir,
tools::check_tools_installed, tools::find_current_workspace,
};

use super::{
Expand Down Expand Up @@ -179,7 +179,7 @@ fn copy_to_wasm_unmanaged_ei() {

#[cfg(test)]
mod tests {
use crate::cmd::contract::sc_config::ContractVariantProfile;
use crate::contract::sc_config::ContractVariantProfile;

const EXPECTED_CARGO_TOML_CONTENTS: &str =
"# Code generated by the multiversx-sc build system. DO NOT EDIT.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use super::{contract_variant_builder::default_wasm_crate_name, ContractVariantSettings};
use crate::cli_args::BuildArgs;
use crate::cli::BuildArgs;
use multiversx_sc::abi::ContractAbi;

/// Represents a contract created by the framework when building.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{ffi::OsStr, fs, process::Command};
use super::ContractVariant;
use crate::{
abi_json::ContractAbiJson,
cli_args::BuildArgs,
cli::BuildArgs,
ei::EIVersion,
ei_check_json::EiCheckJson,
mxsc_file_json::{save_mxsc_file_json, MxscFileJson},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::wasm_cargo_toml_data::WasmCargoTomlData;
use crate::{cargo_toml_contents::change_from_base_to_adapter_path, CargoTomlContents};
use crate::{
cargo_toml_contents::change_from_base_to_adapter_path, cargo_toml_contents::CargoTomlContents,
};

const WASM_ADAPTER: &str = "multiversx-sc-wasm-adapter";
const CDYLIB_CRATE_TYPE: &str = "cdylib";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions framework/meta-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub mod abi_json;
pub mod cargo_toml_contents;
pub mod cli;
pub mod contract;
pub mod ei;
pub mod ei_check_json;
pub mod esdt_attr_file_json;
mod mxsc_file_json;
pub mod print_util;
mod report_info_json;
pub mod tools;
pub mod version;
pub mod version_history;

#[macro_use]
extern crate lazy_static;

pub use cli::{cli_main, multi_contract_config};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
pub mod find_workspace;
mod find_workspace;
mod git_describe;
pub mod twiggy;
mod wasm_extractor;
mod wasm_opt;
mod wasm_to_wat;

pub use find_workspace::{find_current_workspace, find_workspace};
pub use git_describe::git_describe;
pub use wasm_extractor::WasmInfo;
pub use wasm_opt::run_wasm_opt;
pub use wasm_to_wat::wasm_to_wat;

use crate::cli_args::BuildArgs;
use crate::cli::BuildArgs;

pub fn check_tools_installed(build_args: &mut BuildArgs) {
if build_args.wasm_opt && !wasm_opt::is_wasm_opt_installed() {
Expand Down
File renamed without changes.
Loading
Loading