From 70ae2eb77da52eac1dbf56dc844569fd3d84faa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Mon, 26 Feb 2024 11:47:17 +0100 Subject: [PATCH] Added odra-build crate. Bumped version to 0.8.1. --- CHANGELOG.md | 5 +++-- Cargo.toml | 18 ++++++++++-------- examples/Cargo.toml | 5 ++++- examples/build.rs | 6 +----- justfile | 2 +- modules/Cargo.toml | 9 ++++++--- modules/build.rs | 6 +----- odra-build/Cargo.toml | 9 +++++++++ odra-build/src/lib.rs | 6 ++++++ odra-casper/proxy-caller/Cargo.toml | 2 +- templates/blank/_Cargo.toml | 3 +++ templates/blank/build.rs | 8 +++----- templates/full/_Cargo.toml | 3 +++ templates/full/build.rs | 8 +++----- templates/workspace/_Cargo.toml | 1 + templates/workspace/flapper/Cargo.toml | 3 +++ templates/workspace/flapper/build.rs | 8 +++----- templates/workspace/flipper/Cargo.toml | 3 +++ templates/workspace/flipper/build.rs | 8 +++----- 19 files changed, 67 insertions(+), 46 deletions(-) create mode 100644 odra-build/Cargo.toml create mode 100644 odra-build/src/lib.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b6c338c..3958f1a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,15 @@ Changelog for `odra`. -## [0.9.0] - 2024-XX-XX +## [0.8.1] - 2024-XX-XX ### Added - `ContractRef` trait with `new` and `address` functions. All contract references now implement it. +- `odra-build` crate for including the code in contract's build.rs file. ### Changed - Traits implemented by modules are now also implemented by their `ContractRefs` and `HostRefs`. -## [0.8.0] - 2024-XX-XX +## [0.8.0] - 2024-02-06 ### Changed - Replaced `contract_env::` with `self.env()` in the contract context (of type `ContractEnv`). diff --git a/Cargo.toml b/Cargo.toml index 5b900bdc..c12faf08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,24 +8,26 @@ members = [ "odra-casper/livenet-env", "odra-casper/wasm-env", "odra-casper/test-vm", - "odra-test"] + "odra-test", + "odra-build" +] exclude = [ "examples", "modules", "benchmark", "odra-casper/proxy-caller", "templates/blank", "templates/full", "templates/workspace", "tests"] resolver = "2" [workspace.package] -version = "0.8.0" +version = "0.8.1" authors = ["Jakub Płaskonka ", "Krzysztof Pobiarżyn ", "Maciej Zieliński "] license = "MIT" homepage = "https://odra.dev/docs" repository = "https://github.com/odradev/odra" [workspace.dependencies] -odra-core = { path = "core", version = "0.8.0" } -odra-macros = { path = "odra-macros", version = "0.8.0" } -odra-casper-test-vm = { path = "odra-casper/test-vm", version = "0.8.0" } -odra-casper-rpc-client = { path = "odra-casper/rpc-client", version = "0.8.0" } -odra-vm = { path = "odra-vm", version = "0.8.0" } -odra-casper-wasm-env = { path = "odra-casper/wasm-env", version = "0.8.0"} +odra-core = { path = "core", version = "0.8.1" } +odra-macros = { path = "odra-macros", version = "0.8.1" } +odra-casper-test-vm = { path = "odra-casper/test-vm", version = "0.8.1" } +odra-casper-rpc-client = { path = "odra-casper/rpc-client", version = "0.8.1" } +odra-vm = { path = "odra-vm", version = "0.8.1" } +odra-casper-wasm-env = { path = "odra-casper/wasm-env", version = "0.8.1"} casper-contract = { version = "3.0.0", default-features = false } casper-types = { version = "3.0.0", default-features = false } casper-execution-engine = "5.0.0" diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 89b3a247..5eb6bb6a 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odra-examples" -version = "0.8.0" +version = "0.8.1" edition = "2021" [dependencies] @@ -13,6 +13,9 @@ odra-casper-livenet-env = { path = "../odra-casper/livenet-env", optional = true odra-test = { path = "../odra-test" } hex = "0.4.3" +[build-dependencies] +odra-build = { path = "../odra-build" } + [features] default = [] livenet = ["odra-casper-livenet-env"] diff --git a/examples/build.rs b/examples/build.rs index 92df308d..78b6fffa 100644 --- a/examples/build.rs +++ b/examples/build.rs @@ -1,10 +1,6 @@ //! Odra's contracts build script. -use std::env; /// Uses the ENV variable `ODRA_MODULE` to set the `odra_module` cfg flag. pub fn main() { - println!("cargo:rerun-if-env-changed=ODRA_MODULE"); - let module = env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); - let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); - println!("{}", msg); + odra_build::build(); } diff --git a/justfile b/justfile index 780d35fa..e021943e 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,5 @@ CARGO_ODRA_GIT_REPO := "https://github.com/odradev/cargo-odra" -CARGO_ODRA_BRANCH := "release/0.1.0" +CARGO_ODRA_BRANCH := "feature/build-dependency" BINARYEN_VERSION := "version_116" BINARYEN_CHECKSUM := "c55b74f3109cdae97490faf089b0286d3bba926bb6ea5ed00c8c784fc53718fd" diff --git a/modules/Cargo.toml b/modules/Cargo.toml index e66d3e76..26f459bd 100644 --- a/modules/Cargo.toml +++ b/modules/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odra-modules" -version = "0.8.0" +version = "0.8.1" edition = "2021" authors = ["Jakub Płaskonka ", "Krzysztof Pobiarżyn ", "Maciej Zieliński "] license = "MIT" @@ -10,11 +10,14 @@ keywords = ["wasm", "webassembly", "blockchain"] categories = ["wasm"] [dependencies] -odra = { path = "../odra", version = "0.8.0", default-features = false } +odra = { path = "../odra", version = "0.8.1", default-features = false } hex = { version = "0.4.3", default-features = false } [dev-dependencies] -odra-test = { path = "../odra-test", version = "0.8.0" } +odra-test = { path = "../odra-test", version = "0.8.1" } + +[build-dependencies] +odra-build = { path = "../odra-build", version = "0.8.1" } [[bin]] name = "odra_modules_build_contract" diff --git a/modules/build.rs b/modules/build.rs index 92df308d..78b6fffa 100644 --- a/modules/build.rs +++ b/modules/build.rs @@ -1,10 +1,6 @@ //! Odra's contracts build script. -use std::env; /// Uses the ENV variable `ODRA_MODULE` to set the `odra_module` cfg flag. pub fn main() { - println!("cargo:rerun-if-env-changed=ODRA_MODULE"); - let module = env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); - let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); - println!("{}", msg); + odra_build::build(); } diff --git a/odra-build/Cargo.toml b/odra-build/Cargo.toml new file mode 100644 index 00000000..ea9197dd --- /dev/null +++ b/odra-build/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "odra-build" +description = "Function used in build.rs files of Odra projects" +edition = "2021" +version.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true diff --git a/odra-build/src/lib.rs b/odra-build/src/lib.rs new file mode 100644 index 00000000..84b6e356 --- /dev/null +++ b/odra-build/src/lib.rs @@ -0,0 +1,6 @@ +pub fn build() { + println!("cargo:rerun-if-env-changed=ODRA_MODULE"); + let module = std::env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); + let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); + println!("{}", msg); +} diff --git a/odra-casper/proxy-caller/Cargo.toml b/odra-casper/proxy-caller/Cargo.toml index 05fbd92b..194af23b 100644 --- a/odra-casper/proxy-caller/Cargo.toml +++ b/odra-casper/proxy-caller/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "odra-casper-proxy-caller" edition = "2021" -version = "0.8.0" +version = "0.8.1" authors = ["Jakub Płaskonka ", "Krzysztof Pobiarżyn ", "Maciej Zieliński "] license = "MIT" homepage = "https://odra.dev/docs" diff --git a/templates/blank/_Cargo.toml b/templates/blank/_Cargo.toml index 9f2ddfdd..35ea542b 100644 --- a/templates/blank/_Cargo.toml +++ b/templates/blank/_Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" [dev-dependencies] #odra_test_dependency +[build-dependencies] +#odra_build_dependency + [[bin]] name = "{{project-name}}_build_contract" path = "bin/build_contract.rs" diff --git a/templates/blank/build.rs b/templates/blank/build.rs index 7f61e3e8..78b6fffa 100644 --- a/templates/blank/build.rs +++ b/templates/blank/build.rs @@ -1,8 +1,6 @@ -use std::env; +//! Odra's contracts build script. +/// Uses the ENV variable `ODRA_MODULE` to set the `odra_module` cfg flag. pub fn main() { - println!("cargo:rerun-if-env-changed=ODRA_MODULE"); - let module = env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); - let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); - println!("{}", msg); + odra_build::build(); } diff --git a/templates/full/_Cargo.toml b/templates/full/_Cargo.toml index 9f2ddfdd..35ea542b 100644 --- a/templates/full/_Cargo.toml +++ b/templates/full/_Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" [dev-dependencies] #odra_test_dependency +[build-dependencies] +#odra_build_dependency + [[bin]] name = "{{project-name}}_build_contract" path = "bin/build_contract.rs" diff --git a/templates/full/build.rs b/templates/full/build.rs index 7f61e3e8..78b6fffa 100644 --- a/templates/full/build.rs +++ b/templates/full/build.rs @@ -1,8 +1,6 @@ -use std::env; +//! Odra's contracts build script. +/// Uses the ENV variable `ODRA_MODULE` to set the `odra_module` cfg flag. pub fn main() { - println!("cargo:rerun-if-env-changed=ODRA_MODULE"); - let module = env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); - let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); - println!("{}", msg); + odra_build::build(); } diff --git a/templates/workspace/_Cargo.toml b/templates/workspace/_Cargo.toml index adefdfa6..96a4bb5f 100644 --- a/templates/workspace/_Cargo.toml +++ b/templates/workspace/_Cargo.toml @@ -8,6 +8,7 @@ resolver = "2" [workspace.dependencies] #odra_dependency #odra_test_dependency +#odra_build_dependency [profile.release] codegen-units = 1 diff --git a/templates/workspace/flapper/Cargo.toml b/templates/workspace/flapper/Cargo.toml index cd831d46..57c9c78c 100644 --- a/templates/workspace/flapper/Cargo.toml +++ b/templates/workspace/flapper/Cargo.toml @@ -9,6 +9,9 @@ odra = { workspace = true } [dev-dependencies] odra-test = { workspace = true } +[build-dependencies] +odra-build = { workspace = true } + [[bin]] name = "flapper_build_contract" path = "bin/build_contract.rs" diff --git a/templates/workspace/flapper/build.rs b/templates/workspace/flapper/build.rs index 7f61e3e8..78b6fffa 100644 --- a/templates/workspace/flapper/build.rs +++ b/templates/workspace/flapper/build.rs @@ -1,8 +1,6 @@ -use std::env; +//! Odra's contracts build script. +/// Uses the ENV variable `ODRA_MODULE` to set the `odra_module` cfg flag. pub fn main() { - println!("cargo:rerun-if-env-changed=ODRA_MODULE"); - let module = env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); - let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); - println!("{}", msg); + odra_build::build(); } diff --git a/templates/workspace/flipper/Cargo.toml b/templates/workspace/flipper/Cargo.toml index 5d377f9e..5c03d103 100644 --- a/templates/workspace/flipper/Cargo.toml +++ b/templates/workspace/flipper/Cargo.toml @@ -9,6 +9,9 @@ odra = { workspace = true } [dev-dependencies] odra-test = { workspace = true } +[build-dependencies] +odra-build = { workspace = true } + [[bin]] name = "flipper_build_contract" path = "bin/build_contract.rs" diff --git a/templates/workspace/flipper/build.rs b/templates/workspace/flipper/build.rs index 7f61e3e8..78b6fffa 100644 --- a/templates/workspace/flipper/build.rs +++ b/templates/workspace/flipper/build.rs @@ -1,8 +1,6 @@ -use std::env; +//! Odra's contracts build script. +/// Uses the ENV variable `ODRA_MODULE` to set the `odra_module` cfg flag. pub fn main() { - println!("cargo:rerun-if-env-changed=ODRA_MODULE"); - let module = env::var("ODRA_MODULE").unwrap_or_else(|_| "".to_string()); - let msg = format!("cargo:rustc-cfg=odra_module=\"{}\"", module); - println!("{}", msg); + odra_build::build(); }