diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000000..34b2668b71f --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +rustflags = ["-C", "link-arg=--import-memory", "-C", "linker-plugin-lto"] diff --git a/Cargo.lock b/Cargo.lock index 7fafa6ec81a..bf47e4bbe74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,9 +104,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.4" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -763,9 +763,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.6.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" dependencies = [ "memchr", "serde", @@ -1827,9 +1827,9 @@ dependencies = [ name = "demo-async" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -1837,19 +1837,19 @@ name = "demo-async-critical" version = "0.1.0" dependencies = [ "futures", - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-async-custom-entry" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -1857,9 +1857,9 @@ name = "demo-async-init" version = "0.1.0" dependencies = [ "futures", - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -1867,27 +1867,27 @@ name = "demo-async-recursion" version = "0.1.0" dependencies = [ "async-recursion", - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-async-signal-entry" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-async-tester" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -1904,7 +1904,6 @@ dependencies = [ name = "demo-calc-hash" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", "sha2 0.10.8", @@ -1915,9 +1914,9 @@ name = "demo-calc-hash-in-one-block" version = "0.1.0" dependencies = [ "demo-calc-hash", - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -1925,28 +1924,36 @@ name = "demo-calc-hash-over-blocks" version = "0.1.0" dependencies = [ "demo-calc-hash", - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-compose" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "hex", + "wasm-dep-builder", ] [[package]] name = "demo-constructor" version = "0.1.0" dependencies = [ - "gcore", - "gear-wasm-builder", + "demo-constructor-io", "gstd", "hex", + "wasm-dep-builder", +] + +[[package]] +name = "demo-constructor-io" +version = "0.1.0" +dependencies = [ + "gcore", + "gstd", "parity-scale-codec", ] @@ -1954,37 +1961,42 @@ dependencies = [ name = "demo-custom" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gsys", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-delayed-reservation-sender" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-delayed-sender" version = "0.1.0" dependencies = [ - "gear-wasm-builder", + "demo-delayed-sender-io", "gstd", + "wasm-dep-builder", ] +[[package]] +name = "demo-delayed-sender-io" +version = "0.1.0" + [[package]] name = "demo-distributor" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -2009,52 +2021,52 @@ name = "demo-futures-unordered" version = "0.1.0" dependencies = [ "futures", - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-gas-burned" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "log", + "wasm-dep-builder", ] [[package]] name = "demo-incomplete-async-payloads" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-init-fail-sender" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-init-wait" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-init-wait-reply-exit" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] @@ -2110,9 +2122,9 @@ dependencies = [ name = "demo-mul-by-const" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "hex", + "wasm-dep-builder", ] [[package]] @@ -2142,92 +2154,99 @@ dependencies = [ name = "demo-node" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-out-of-memory" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-piggy-bank" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-ping" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-program-factory" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "hex-literal", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-program-generator" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "hex-literal", + "wasm-dep-builder", ] [[package]] name = "demo-proxy" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", "scale-info", + "wasm-dep-builder", ] [[package]] name = "demo-proxy-relay" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", "scale-info", + "wasm-dep-builder", ] [[package]] name = "demo-proxy-reservation-with-gas" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", "scale-info", + "wasm-dep-builder", ] [[package]] name = "demo-read-big-state" version = "0.1.0" dependencies = [ - "gear-wasm-builder", + "demo-read-big-state-io", "gstd", + "wasm-dep-builder", +] + +[[package]] +name = "demo-read-big-state-io" +version = "0.1.0" +dependencies = [ "parity-scale-codec", ] @@ -2235,19 +2254,26 @@ dependencies = [ name = "demo-reservation-manager" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-reserve-gas" version = "0.1.0" dependencies = [ - "gear-wasm-builder", + "demo-reserve-gas-io", "gstd", "gtest", + "wasm-dep-builder", +] + +[[package]] +name = "demo-reserve-gas-io" +version = "0.1.0" +dependencies = [ "parity-scale-codec", ] @@ -2255,30 +2281,37 @@ dependencies = [ name = "demo-rwlock" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-send-from-reservation" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-signal-entry" version = "0.1.0" dependencies = [ - "gcore", + "demo-signal-entry-io", "gear-core", - "gear-wasm-builder", "gstd", "gtest", + "wasm-dep-builder", +] + +[[package]] +name = "demo-signal-entry-io" +version = "0.1.0" +dependencies = [ + "gcore", "parity-scale-codec", ] @@ -2298,16 +2331,16 @@ dependencies = [ name = "demo-state-rollback" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] name = "demo-sync-duplicate" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] @@ -2334,8 +2367,8 @@ name = "demo-wait" version = "0.1.0" dependencies = [ "gcore", - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] @@ -2343,19 +2376,19 @@ name = "demo-wait-timeout" version = "0.1.0" dependencies = [ "futures", - "gear-wasm-builder", "gstd", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] name = "demo-wait-wake" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "gtest", "parity-scale-codec", + "wasm-dep-builder", ] [[package]] @@ -2363,12 +2396,19 @@ name = "demo-waiter" version = "0.1.0" dependencies = [ "demo-waiter", + "demo-waiter-io", "futures", - "gcore", "gear-core", - "gear-wasm-builder", "gstd", "gtest", + "wasm-dep-builder", +] + +[[package]] +name = "demo-waiter-io" +version = "0.1.0" +dependencies = [ + "gcore", "parity-scale-codec", ] @@ -2376,8 +2416,8 @@ dependencies = [ name = "demo-waiting-proxy" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", + "wasm-dep-builder", ] [[package]] @@ -3055,14 +3095,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.22" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", - "windows-sys 0.48.0", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", ] [[package]] @@ -3517,6 +3557,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "fs4" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29f9df8a11882c4e3335eb2d18a0137c505d9ca927470b0cac9c6f0ae07d28f7" +dependencies = [ + "rustix 0.38.28", + "windows-sys 0.48.0", +] + [[package]] name = "ft-io" version = "0.1.4" @@ -3716,23 +3766,13 @@ version = "1.1.0" dependencies = [ "anyhow", "async-trait", - "demo-async-tester", "demo-calc-hash", - "demo-calc-hash-in-one-block", - "demo-constructor", - "demo-custom", - "demo-distributor", "demo-meta-io", - "demo-mul-by-const", "demo-new-meta", - "demo-node", - "demo-program-factory", - "demo-proxy", - "demo-proxy-relay", - "demo-reserve-gas", "demo-wat", "env_logger", "futures", + "gclient-binaries", "gear-core", "gear-core-errors", "gear-utils", @@ -3751,6 +3791,24 @@ dependencies = [ "wat", ] +[[package]] +name = "gclient-binaries" +version = "1.1.0" +dependencies = [ + "demo-async-tester", + "demo-calc-hash-in-one-block", + "demo-constructor", + "demo-custom", + "demo-distributor", + "demo-mul-by-const", + "demo-node", + "demo-program-factory", + "demo-proxy", + "demo-proxy-relay", + "demo-reserve-gas", + "wasm-dep-builder", +] + [[package]] name = "gcore" version = "1.1.0" @@ -3767,12 +3825,12 @@ dependencies = [ name = "gear-authorship" version = "1.1.0" dependencies = [ - "demo-constructor", "env_logger", "frame-support", "frame-system", "futures", "futures-timer", + "gear-authorship-binaries", "gear-common", "gear-core", "gear-node-testing", @@ -3809,6 +3867,14 @@ dependencies = [ "vara-runtime", ] +[[package]] +name = "gear-authorship-binaries" +version = "1.1.0" +dependencies = [ + "demo-constructor", + "wasm-dep-builder", +] + [[package]] name = "gear-bags-thresholds" version = "1.0.0" @@ -4173,6 +4239,7 @@ dependencies = [ "gear-core", "gear-lazy-pages", "gear-lazy-pages-common", + "gear-runtime-interface-binaries", "gear-sandbox-host", "log", "parity-scale-codec", @@ -4183,6 +4250,20 @@ dependencies = [ "winapi", ] +[[package]] +name = "gear-runtime-interface-binaries" +version = "1.1.0" +dependencies = [ + "demo-constructor", + "demo-delayed-sender", + "demo-read-big-state", + "demo-reserve-gas", + "demo-signal-entry", + "demo-waiter", + "test-syscalls", + "wasm-dep-builder", +] + [[package]] name = "gear-runtime-primitives" version = "1.1.0" @@ -4545,15 +4626,16 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" dependencies = [ "aho-corasick", "bstr", - "fnv", "log", - "regex", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", + "serde", ] [[package]] @@ -4631,6 +4713,7 @@ dependencies = [ "gear-core", "gear-core-errors", "gsdk", + "gsdk-binaries", "gsdk-codegen", "hex", "indexmap 2.1.0", @@ -4670,6 +4753,14 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "gsdk-binaries" +version = "1.1.0" +dependencies = [ + "demo-waiter", + "wasm-dep-builder", +] + [[package]] name = "gsdk-codegen" version = "1.1.0" @@ -4719,11 +4810,7 @@ name = "gtest" version = "1.1.0" dependencies = [ "colored", - "demo-custom", - "demo-futures-unordered", "demo-meta-io", - "demo-piggy-bank", - "demo-ping", "derive_more", "env_logger", "gear-core", @@ -4734,6 +4821,7 @@ dependencies = [ "gear-utils", "gear-wasm-instrument", "gsys", + "gtest-binaries", "hex", "log", "parity-scale-codec", @@ -4741,6 +4829,17 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "gtest-binaries" +version = "1.1.0" +dependencies = [ + "demo-custom", + "demo-futures-unordered", + "demo-piggy-bank", + "demo-ping", + "wasm-dep-builder", +] + [[package]] name = "gwasm-instrument" version = "0.3.0" @@ -6377,9 +6476,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memfd" @@ -7349,50 +7448,13 @@ name = "pallet-gear" version = "1.1.0" dependencies = [ "blake2-rfc", - "demo-async", - "demo-async-critical", - "demo-async-custom-entry", - "demo-async-init", - "demo-async-recursion", - "demo-async-signal-entry", - "demo-async-tester", "demo-calc-hash", - "demo-calc-hash-in-one-block", - "demo-calc-hash-over-blocks", - "demo-compose", - "demo-constructor", - "demo-custom", - "demo-delayed-reservation-sender", - "demo-delayed-sender", - "demo-distributor", - "demo-futures-unordered", - "demo-gas-burned", - "demo-incomplete-async-payloads", - "demo-init-fail-sender", - "demo-init-wait", - "demo-init-wait-reply-exit", - "demo-mul-by-const", + "demo-constructor-io", "demo-new-meta", - "demo-out-of-memory", - "demo-ping", - "demo-program-factory", - "demo-program-generator", - "demo-proxy", - "demo-proxy-relay", - "demo-proxy-reservation-with-gas", - "demo-read-big-state", - "demo-reservation-manager", - "demo-reserve-gas", - "demo-rwlock", - "demo-send-from-reservation", - "demo-signal-entry", - "demo-state-rollback", - "demo-sync-duplicate", - "demo-wait", - "demo-wait-timeout", - "demo-wait-wake", - "demo-waiter", - "demo-waiting-proxy", + "demo-read-big-state-io", + "demo-reserve-gas-io", + "demo-signal-entry-io", + "demo-waiter-io", "derive_more", "env_logger", "frame-benchmarking", @@ -7418,6 +7480,7 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-gear-bank", + "pallet-gear-binaries", "pallet-gear-gas", "pallet-gear-messenger", "pallet-gear-proc-macro", @@ -7439,7 +7502,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std 8.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1.0.0-canary)", - "test-syscalls", + "test-syscalls-io", "wabt", ] @@ -7461,6 +7524,56 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-gear-binaries" +version = "1.1.0" +dependencies = [ + "demo-async", + "demo-async-critical", + "demo-async-custom-entry", + "demo-async-init", + "demo-async-recursion", + "demo-async-signal-entry", + "demo-async-tester", + "demo-calc-hash-in-one-block", + "demo-calc-hash-over-blocks", + "demo-compose", + "demo-constructor", + "demo-custom", + "demo-delayed-reservation-sender", + "demo-delayed-sender", + "demo-distributor", + "demo-futures-unordered", + "demo-gas-burned", + "demo-incomplete-async-payloads", + "demo-init-fail-sender", + "demo-init-wait", + "demo-init-wait-reply-exit", + "demo-mul-by-const", + "demo-out-of-memory", + "demo-ping", + "demo-program-factory", + "demo-program-generator", + "demo-proxy", + "demo-proxy-relay", + "demo-proxy-reservation-with-gas", + "demo-read-big-state", + "demo-reservation-manager", + "demo-reserve-gas", + "demo-rwlock", + "demo-send-from-reservation", + "demo-signal-entry", + "demo-state-rollback", + "demo-sync-duplicate", + "demo-wait", + "demo-wait-timeout", + "demo-wait-wake", + "demo-waiter", + "demo-waiting-proxy", + "test-syscalls", + "wasm-dep-builder", +] + [[package]] name = "pallet-gear-debug" version = "1.1.0" @@ -7493,7 +7606,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std 8.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1.0.0-canary)", - "test-syscalls", "wabt", ] @@ -9142,6 +9254,17 @@ dependencies = [ "regex-syntax 0.7.5", ] +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.2", +] + [[package]] name = "regex-syntax" version = "0.6.29" @@ -12494,9 +12617,17 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" name = "test-syscalls" version = "0.1.0" dependencies = [ - "gear-wasm-builder", "gstd", "parity-scale-codec", + "test-syscalls-io", + "wasm-dep-builder", +] + +[[package]] +name = "test-syscalls-io" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", ] [[package]] @@ -13483,6 +13614,22 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wasm-dep-builder" +version = "1.1.0" +dependencies = [ + "anyhow", + "cargo_metadata 0.18.1", + "derive_more", + "dirs", + "filetime", + "fs4", + "gear-wasm-builder", + "globset", + "serde", + "serde_json", +] + [[package]] name = "wasm-encoder" version = "0.35.0" diff --git a/Cargo.toml b/Cargo.toml index 95707c5ea72..7dcf078425a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,6 +213,7 @@ gear-service = { path = "node/service", default-features = false } gear-stack-buffer = { path = "stack-buffer" } gear-utils = { path = "utils/utils" } gear-wasm-builder = { path = "utils/wasm-builder", default-features = false } +wasm-dep-builder = { path = "utils/wasm-dep-builder" } gear-wasm-gen = { path = "utils/wasm-gen" } gear-wasm-instrument = { path = "utils/wasm-instrument", default-features = false } junit-common = { path = "utils/junit-common" } @@ -367,6 +368,7 @@ try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/gear-tech/ # Examples test-syscalls = { path = "examples/syscalls", default-features = false } +test-syscalls-io = { path = "examples/syscalls/io", default-features = false } demo-async = { path = "examples/async" } demo-async-critical = { path = "examples/async-critical" } demo-async-custom-entry = { path = "examples/async-custom-entry" } @@ -381,6 +383,7 @@ demo-custom = { path = "examples/custom" } demo-delayed-reservation-sender = { path = "examples/delayed-reservation-sender" } demo-compose = { path = "examples/compose" } demo-constructor = { path = "examples/constructor", default-features = false } +demo-constructor-io = { path = "examples/constructor/io", default-features = false } demo-delayed-sender = { path = "examples/delayed-sender" } demo-distributor = { path = "examples/distributor" } demo-futures-unordered = { path = "examples/futures-unordered", features = ["debug"] } @@ -404,16 +407,20 @@ demo-proxy = { path = "examples/proxy", default-features = false } demo-proxy-relay = { path = "examples/proxy-relay" } demo-proxy-reservation-with-gas = { path = "examples/proxy-reservation-with-gas" } demo-read-big-state = { path = "examples/read-big-state", default-features = false } +demo-read-big-state-io = { path = "examples/read-big-state/io", default-features = false } demo-reservation-manager = { path = "examples/reservation-manager" } demo-reserve-gas = { path = "examples/reserve-gas", default-features = false } +demo-reserve-gas-io = { path = "examples/reserve-gas/io", default-features = false } demo-rwlock = { path = "examples/rwlock" } demo-send-from-reservation = { path = "examples/send-from-reservation" } demo-signal-entry = { path = "examples/signal-entry", default-features = false } +demo-signal-entry-io = { path = "examples/signal-entry/io", default-features = false } demo-state-rollback = { path = "examples/state-rollback" } demo-sync-duplicate = { path = "examples/sync-duplicate" } demo-vec = { path = "examples/vec" } demo-wait = { path = "examples/wait" } demo-waiter = { path = "examples/waiter", default-features = false } +demo-waiter-io = { path = "examples/waiter/io", default-features = false } demo-wait-timeout = { path = "examples/wait-timeout" } demo-wait-wake = { path = "examples/wait_wake" } demo-waiting-proxy = { path = "examples/waiting-proxy" } diff --git a/core/src/pages.rs b/core/src/pages.rs index 49fde6d11a7..a2c2802cc91 100644 --- a/core/src/pages.rs +++ b/core/src/pages.rs @@ -18,6 +18,8 @@ //! Module for memory pages. +#![allow(clippy::assertions_on_constants)] + use core::num::NonZeroU32; use scale_info::{ scale::{Decode, Encode}, diff --git a/examples/async-critical/Cargo.toml b/examples/async-critical/Cargo.toml index 83b971f56aa..66a0c1104ac 100644 --- a/examples/async-critical/Cargo.toml +++ b/examples/async-critical/Cargo.toml @@ -7,15 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true futures.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] -default = ["std"] -std = [] diff --git a/examples/async-critical/build.rs b/examples/async-critical/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async-critical/build.rs +++ b/examples/async-critical/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async-critical/src/lib.rs b/examples/async-critical/src/lib.rs index d6c631e9461..ea1654c0368 100644 --- a/examples/async-critical/src/lib.rs +++ b/examples/async-critical/src/lib.rs @@ -18,14 +18,6 @@ #![no_std] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - use gstd::{Decode, Encode}; #[derive(Debug, Encode, Decode)] diff --git a/examples/async-custom-entry/Cargo.toml b/examples/async-custom-entry/Cargo.toml index ce820c11930..937e9b344d6 100644 --- a/examples/async-custom-entry/Cargo.toml +++ b/examples/async-custom-entry/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/async-custom-entry/build.rs b/examples/async-custom-entry/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async-custom-entry/build.rs +++ b/examples/async-custom-entry/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async-custom-entry/src/lib.rs b/examples/async-custom-entry/src/lib.rs index bc6163a1546..a5d28abf05d 100644 --- a/examples/async-custom-entry/src/lib.rs +++ b/examples/async-custom-entry/src/lib.rs @@ -18,13 +18,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/async-init/Cargo.toml b/examples/async-init/Cargo.toml index eb2eb78d4b6..a4e9e4cbbbd 100644 --- a/examples/async-init/Cargo.toml +++ b/examples/async-init/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true futures.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/async-init/build.rs b/examples/async-init/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async-init/build.rs +++ b/examples/async-init/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async-init/src/lib.rs b/examples/async-init/src/lib.rs index 57170ba527f..d9f78fba49b 100644 --- a/examples/async-init/src/lib.rs +++ b/examples/async-init/src/lib.rs @@ -22,14 +22,6 @@ use core::array::IntoIter; use gstd::ActorId; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Decode, Encode)] pub struct InputArgs { pub approver_first: ActorId, diff --git a/examples/async-recursion/Cargo.toml b/examples/async-recursion/Cargo.toml index 99fc3c4f579..9d5da65d57a 100644 --- a/examples/async-recursion/Cargo.toml +++ b/examples/async-recursion/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true async-recursion.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/async-recursion/build.rs b/examples/async-recursion/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async-recursion/build.rs +++ b/examples/async-recursion/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async-recursion/src/lib.rs b/examples/async-recursion/src/lib.rs index e96c8269a56..287eac316f8 100644 --- a/examples/async-recursion/src/lib.rs +++ b/examples/async-recursion/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/async-signal-entry/Cargo.toml b/examples/async-signal-entry/Cargo.toml index 66067c35b43..38ceec4f621 100644 --- a/examples/async-signal-entry/Cargo.toml +++ b/examples/async-signal-entry/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/async-signal-entry/build.rs b/examples/async-signal-entry/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async-signal-entry/build.rs +++ b/examples/async-signal-entry/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async-signal-entry/src/lib.rs b/examples/async-signal-entry/src/lib.rs index 93adeaab735..7472e40f6cc 100644 --- a/examples/async-signal-entry/src/lib.rs +++ b/examples/async-signal-entry/src/lib.rs @@ -18,14 +18,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - use parity_scale_codec::{Decode, Encode}; #[derive(Debug, Encode, Decode)] diff --git a/examples/async-tester/Cargo.toml b/examples/async-tester/Cargo.toml index 4e75128315a..b3f3420ff9e 100644 --- a/examples/async-tester/Cargo.toml +++ b/examples/async-tester/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/async-tester/build.rs b/examples/async-tester/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async-tester/build.rs +++ b/examples/async-tester/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async-tester/src/lib.rs b/examples/async-tester/src/lib.rs index d752d462007..74aedb7952a 100644 --- a/examples/async-tester/src/lib.rs +++ b/examples/async-tester/src/lib.rs @@ -1,14 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std)] use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/async/Cargo.toml b/examples/async/Cargo.toml index 45a6b2ddb94..5a1442306d7 100644 --- a/examples/async/Cargo.toml +++ b/examples/async/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/async/build.rs b/examples/async/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/async/build.rs +++ b/examples/async/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/async/src/lib.rs b/examples/async/src/lib.rs index 334be6c2d6e..10d109eccae 100644 --- a/examples/async/src/lib.rs +++ b/examples/async/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Decode, Encode)] pub enum Command { Common, diff --git a/examples/calc-hash/Cargo.toml b/examples/calc-hash/Cargo.toml index 3a68890fbf5..af6abecb60a 100644 --- a/examples/calc-hash/Cargo.toml +++ b/examples/calc-hash/Cargo.toml @@ -11,6 +11,3 @@ repository.workspace = true gstd.workspace = true parity-scale-codec.workspace = true sha2 = { version = "0.10.8", default-features = false } - -[build-dependencies] -gear-wasm-builder.workspace = true diff --git a/examples/calc-hash/in-one-block/Cargo.toml b/examples/calc-hash/in-one-block/Cargo.toml index 7192e5baca9..ac72cc33867 100644 --- a/examples/calc-hash/in-one-block/Cargo.toml +++ b/examples/calc-hash/in-one-block/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true shared = { path = "..", package = "demo-calc-hash" } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/calc-hash/in-one-block/build.rs b/examples/calc-hash/in-one-block/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/calc-hash/in-one-block/build.rs +++ b/examples/calc-hash/in-one-block/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/calc-hash/in-one-block/src/lib.rs b/examples/calc-hash/in-one-block/src/lib.rs index da0ce2b739e..86fe70fcc04 100644 --- a/examples/calc-hash/in-one-block/src/lib.rs +++ b/examples/calc-hash/in-one-block/src/lib.rs @@ -15,16 +15,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] -use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} +#![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +use parity_scale_codec::{Decode, Encode}; #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/calc-hash/over-blocks/Cargo.toml b/examples/calc-hash/over-blocks/Cargo.toml index 5d93098fe37..a55b09ac6ba 100644 --- a/examples/calc-hash/over-blocks/Cargo.toml +++ b/examples/calc-hash/over-blocks/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true shared = { path = "../", package = "demo-calc-hash" } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/calc-hash/over-blocks/build.rs b/examples/calc-hash/over-blocks/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/calc-hash/over-blocks/build.rs +++ b/examples/calc-hash/over-blocks/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/calc-hash/over-blocks/src/lib.rs b/examples/calc-hash/over-blocks/src/lib.rs index 4289b403945..cecae14ae50 100644 --- a/examples/calc-hash/over-blocks/src/lib.rs +++ b/examples/calc-hash/over-blocks/src/lib.rs @@ -15,19 +15,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] + +#![cfg_attr(not(feature = "std"), no_std)] use parity_scale_codec::{Decode, Encode}; use shared::PackageId; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/compose/Cargo.toml b/examples/compose/Cargo.toml index bd4a1891822..1a1645a7618 100644 --- a/examples/compose/Cargo.toml +++ b/examples/compose/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true hex.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/compose/build.rs b/examples/compose/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/compose/build.rs +++ b/examples/compose/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/compose/src/lib.rs b/examples/compose/src/lib.rs index 62761ccf165..30e69a08bca 100644 --- a/examples/compose/src/lib.rs +++ b/examples/compose/src/lib.rs @@ -25,13 +25,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/constructor/Cargo.toml b/examples/constructor/Cargo.toml index 093e3a2b005..82a0a74005f 100644 --- a/examples/constructor/Cargo.toml +++ b/examples/constructor/Cargo.toml @@ -7,17 +7,22 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] -gcore.workspace = true gstd.workspace = true hex.workspace = true -parity-scale-codec.workspace = true +io = { package = "demo-constructor-io", path = "io" } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] -debug = ["gstd/debug"] -wasm-wrapper = [] +debug = ["gstd/debug", "io/debug"] +wasm-wrapper = ["io/wasm-wrapper"] std = ["wasm-wrapper"] default = ["std"] diff --git a/examples/constructor/build.rs b/examples/constructor/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/constructor/build.rs +++ b/examples/constructor/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/constructor/io/Cargo.toml b/examples/constructor/io/Cargo.toml new file mode 100644 index 00000000000..a864943ab48 --- /dev/null +++ b/examples/constructor/io/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "demo-constructor-io" +version = "0.1.0" +edition = "2021" + +[dependencies] +gcore.workspace = true +parity-scale-codec.workspace = true +gstd = { workspace = true } + +[features] +debug = ["gstd/debug"] +wasm-wrapper = [] diff --git a/examples/constructor/src/arg.rs b/examples/constructor/io/src/arg.rs similarity index 75% rename from examples/constructor/src/arg.rs rename to examples/constructor/io/src/arg.rs index b749bbc03b7..82e4fef4b55 100644 --- a/examples/constructor/src/arg.rs +++ b/examples/constructor/io/src/arg.rs @@ -1,3 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + use alloc::{ string::{String, ToString}, vec::Vec, diff --git a/examples/constructor/src/builder.rs b/examples/constructor/io/src/builder.rs similarity index 100% rename from examples/constructor/src/builder.rs rename to examples/constructor/io/src/builder.rs diff --git a/examples/constructor/src/call.rs b/examples/constructor/io/src/call.rs similarity index 92% rename from examples/constructor/src/call.rs rename to examples/constructor/io/src/call.rs index 467a6094d8a..5184561272a 100644 --- a/examples/constructor/src/call.rs +++ b/examples/constructor/io/src/call.rs @@ -1,3 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + use crate::Arg; use alloc::{string::String, vec::Vec}; use parity_scale_codec::{Decode, Encode}; @@ -345,7 +363,7 @@ mod wasm { None } - pub(crate) fn process(self, previous: Option) -> CallResult { + pub fn process(self, previous: Option) -> CallResult { debug!("\t[CONSTRUCTOR] >> Processing {self:?}"); let call = self.clone(); diff --git a/examples/constructor/io/src/lib.rs b/examples/constructor/io/src/lib.rs new file mode 100644 index 00000000000..ad5823e6168 --- /dev/null +++ b/examples/constructor/io/src/lib.rs @@ -0,0 +1,37 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +extern crate alloc; + +mod arg; +mod builder; +mod call; +mod scheme; + +pub use arg::Arg; +pub use builder::Calls; +pub use call::Call; +pub use scheme::*; + +#[cfg(not(feature = "wasm-wrapper"))] +pub(crate) static mut DATA: alloc::collections::BTreeMap< + alloc::string::String, + alloc::vec::Vec, +> = alloc::collections::BTreeMap::new(); diff --git a/examples/constructor/src/scheme/demo_exit_handle.rs b/examples/constructor/io/src/scheme/demo_exit_handle.rs similarity index 100% rename from examples/constructor/src/scheme/demo_exit_handle.rs rename to examples/constructor/io/src/scheme/demo_exit_handle.rs diff --git a/examples/constructor/src/scheme/demo_exit_init.rs b/examples/constructor/io/src/scheme/demo_exit_init.rs similarity index 100% rename from examples/constructor/src/scheme/demo_exit_init.rs rename to examples/constructor/io/src/scheme/demo_exit_init.rs diff --git a/examples/constructor/src/scheme/demo_ping.rs b/examples/constructor/io/src/scheme/demo_ping.rs similarity index 100% rename from examples/constructor/src/scheme/demo_ping.rs rename to examples/constructor/io/src/scheme/demo_ping.rs diff --git a/examples/constructor/src/scheme/demo_proxy_with_gas.rs b/examples/constructor/io/src/scheme/demo_proxy_with_gas.rs similarity index 100% rename from examples/constructor/src/scheme/demo_proxy_with_gas.rs rename to examples/constructor/io/src/scheme/demo_proxy_with_gas.rs diff --git a/examples/constructor/src/scheme/demo_reply_deposit.rs b/examples/constructor/io/src/scheme/demo_reply_deposit.rs similarity index 100% rename from examples/constructor/src/scheme/demo_reply_deposit.rs rename to examples/constructor/io/src/scheme/demo_reply_deposit.rs diff --git a/examples/constructor/src/scheme/demo_value_sender.rs b/examples/constructor/io/src/scheme/demo_value_sender.rs similarity index 100% rename from examples/constructor/src/scheme/demo_value_sender.rs rename to examples/constructor/io/src/scheme/demo_value_sender.rs diff --git a/examples/constructor/src/scheme/demo_wait_init_exit_reply.rs b/examples/constructor/io/src/scheme/demo_wait_init_exit_reply.rs similarity index 100% rename from examples/constructor/src/scheme/demo_wait_init_exit_reply.rs rename to examples/constructor/io/src/scheme/demo_wait_init_exit_reply.rs diff --git a/examples/constructor/src/scheme/mod.rs b/examples/constructor/io/src/scheme/mod.rs similarity index 100% rename from examples/constructor/src/scheme/mod.rs rename to examples/constructor/io/src/scheme/mod.rs diff --git a/examples/constructor/src/lib.rs b/examples/constructor/src/lib.rs index f9ee1a34e4a..6c3c752eb95 100644 --- a/examples/constructor/src/lib.rs +++ b/examples/constructor/src/lib.rs @@ -20,26 +20,7 @@ extern crate alloc; -#[cfg(not(feature = "wasm-wrapper"))] -mod wasm; +pub use io::*; #[cfg(not(feature = "wasm-wrapper"))] -pub(crate) use wasm::DATA; - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -mod arg; -mod builder; -mod call; -mod scheme; - -pub use arg::Arg; -pub use builder::Calls; -pub use call::Call; -pub use scheme::*; +mod wasm; diff --git a/examples/constructor/src/wasm.rs b/examples/constructor/src/wasm.rs index 6377f1bd13b..eeeefce1126 100644 --- a/examples/constructor/src/wasm.rs +++ b/examples/constructor/src/wasm.rs @@ -1,7 +1,6 @@ -use crate::{Call, Scheme}; -use gstd::{collections::BTreeMap, msg, String, Vec}; +use gstd::{msg, Vec}; +use io::{Call, Scheme}; -pub(crate) static mut DATA: BTreeMap> = BTreeMap::new(); static mut SCHEME: Option = None; fn process_fn<'a>(f: impl Fn(&'a Scheme) -> Option<&'a Vec>) { diff --git a/examples/custom/Cargo.toml b/examples/custom/Cargo.toml index bcf618a3c63..2d10027ba1b 100644 --- a/examples/custom/Cargo.toml +++ b/examples/custom/Cargo.toml @@ -7,6 +7,9 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true gsys.workspace = true @@ -16,7 +19,7 @@ parity-scale-codec.workspace = true gtest.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/custom/build.rs b/examples/custom/build.rs index 44f0f822521..2f3db0a44f5 100644 --- a/examples/custom/build.rs +++ b/examples/custom/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/custom/src/lib.rs b/examples/custom/src/lib.rs index a09c52a69db..05317c03c0a 100644 --- a/examples/custom/src/lib.rs +++ b/examples/custom/src/lib.rs @@ -34,14 +34,6 @@ use alloc::string::String; use gstd::ActorId; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Decode, Encode)] pub enum InitMessage { Capacitor(String), diff --git a/examples/delayed-reservation-sender/Cargo.toml b/examples/delayed-reservation-sender/Cargo.toml index e313b5080da..c9b3dcc7198 100644 --- a/examples/delayed-reservation-sender/Cargo.toml +++ b/examples/delayed-reservation-sender/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/delayed-reservation-sender/build.rs b/examples/delayed-reservation-sender/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/delayed-reservation-sender/build.rs +++ b/examples/delayed-reservation-sender/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/delayed-reservation-sender/src/lib.rs b/examples/delayed-reservation-sender/src/lib.rs index 6acefafa63a..4cba6073157 100644 --- a/examples/delayed-reservation-sender/src/lib.rs +++ b/examples/delayed-reservation-sender/src/lib.rs @@ -20,14 +20,6 @@ use gstd::codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - pub const SENDING_EXPECT: &str = "Failed to send delayed message from reservation"; #[derive(Encode, Decode, Debug, Clone, Copy)] diff --git a/examples/delayed-sender/Cargo.toml b/examples/delayed-sender/Cargo.toml index 199aaa4efa4..fd5a3822e7c 100644 --- a/examples/delayed-sender/Cargo.toml +++ b/examples/delayed-sender/Cargo.toml @@ -7,11 +7,18 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true +io = { package = "demo-delayed-sender-io", path = "io", default-features = false } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/delayed-sender/build.rs b/examples/delayed-sender/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/delayed-sender/build.rs +++ b/examples/delayed-sender/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/delayed-sender/io/Cargo.toml b/examples/delayed-sender/io/Cargo.toml new file mode 100644 index 00000000000..2b1765c228b --- /dev/null +++ b/examples/delayed-sender/io/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "demo-delayed-sender-io" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/examples/delayed-sender/io/src/lib.rs b/examples/delayed-sender/io/src/lib.rs new file mode 100644 index 00000000000..89bc687fa64 --- /dev/null +++ b/examples/delayed-sender/io/src/lib.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +pub const DELAY: u32 = 100; diff --git a/examples/delayed-sender/src/lib.rs b/examples/delayed-sender/src/lib.rs index 7908756e8ad..c3c011b40e5 100644 --- a/examples/delayed-sender/src/lib.rs +++ b/examples/delayed-sender/src/lib.rs @@ -16,17 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -pub const DELAY: u32 = 100; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "wasm-wrapper"))] mod wasm; + +pub use io::*; diff --git a/examples/delayed-sender/src/wasm.rs b/examples/delayed-sender/src/wasm.rs index 16e8a6a1b66..3ae253f9a46 100644 --- a/examples/delayed-sender/src/wasm.rs +++ b/examples/delayed-sender/src/wasm.rs @@ -16,8 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::DELAY; use gstd::{exec, msg, MessageId}; +use io::DELAY; static mut MID: Option = None; static mut DONE: bool = false; diff --git a/examples/distributor/Cargo.toml b/examples/distributor/Cargo.toml index 73887d6fd87..e04f9c5ad26 100644 --- a/examples/distributor/Cargo.toml +++ b/examples/distributor/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gstd = { workspace = true, features = ["debug"] } diff --git a/examples/distributor/build.rs b/examples/distributor/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/distributor/build.rs +++ b/examples/distributor/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/distributor/src/lib.rs b/examples/distributor/src/lib.rs index 34d7856df48..94a0cc2c3df 100644 --- a/examples/distributor/src/lib.rs +++ b/examples/distributor/src/lib.rs @@ -23,14 +23,6 @@ extern crate alloc; use gstd::{prelude::*, ActorId}; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Encode, Debug, Decode, PartialEq, Eq)] pub enum Request { Receive(u64), diff --git a/examples/futures-unordered/Cargo.toml b/examples/futures-unordered/Cargo.toml index b20a78af317..b6ddf7d32b6 100644 --- a/examples/futures-unordered/Cargo.toml +++ b/examples/futures-unordered/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true futures = { workspace = true, features = ["async-await"] } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/futures-unordered/build.rs b/examples/futures-unordered/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/futures-unordered/build.rs +++ b/examples/futures-unordered/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/futures-unordered/src/lib.rs b/examples/futures-unordered/src/lib.rs index 5c9c09c4072..ac8d2a806b9 100644 --- a/examples/futures-unordered/src/lib.rs +++ b/examples/futures-unordered/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Decode, Encode)] pub enum Command { Unordered, diff --git a/examples/gas-burned/Cargo.toml b/examples/gas-burned/Cargo.toml index 9ad1445febf..c62c30f0e4b 100644 --- a/examples/gas-burned/Cargo.toml +++ b/examples/gas-burned/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/gas-burned/build.rs b/examples/gas-burned/build.rs index 6836d02c06d..82e50afd7c8 100644 --- a/examples/gas-burned/build.rs +++ b/examples/gas-burned/build.rs @@ -1,3 +1,3 @@ fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/gas-burned/src/lib.rs b/examples/gas-burned/src/lib.rs index 45e628fea74..c75c444747f 100644 --- a/examples/gas-burned/src/lib.rs +++ b/examples/gas-burned/src/lib.rs @@ -1,13 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/gas-burned/src/wasm.rs b/examples/gas-burned/src/wasm.rs index 9e4fcf19f35..88c11568d5a 100644 --- a/examples/gas-burned/src/wasm.rs +++ b/examples/gas-burned/src/wasm.rs @@ -7,7 +7,9 @@ const LONG: usize = 10000; extern "C" fn init() { let mut v = vec![0; SHORT]; for (i, item) in v.iter_mut().enumerate() { - *item = i * i; + unsafe { + ptr::write_volatile(item, i * i); + } } msg::reply_bytes(format!("init: {}", v.into_iter().sum::()), 0).unwrap(); } @@ -16,6 +18,8 @@ extern "C" fn init() { extern "C" fn handle() { let mut v = vec![0; LONG]; for (i, item) in v.iter_mut().enumerate() { - *item = i * i; + unsafe { + ptr::write_volatile(item, i * i); + } } } diff --git a/examples/incomplete-async-payloads/Cargo.toml b/examples/incomplete-async-payloads/Cargo.toml index 1c4ef56a519..2e3b0ec9e1f 100644 --- a/examples/incomplete-async-payloads/Cargo.toml +++ b/examples/incomplete-async-payloads/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/incomplete-async-payloads/build.rs b/examples/incomplete-async-payloads/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/incomplete-async-payloads/build.rs +++ b/examples/incomplete-async-payloads/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/incomplete-async-payloads/src/lib.rs b/examples/incomplete-async-payloads/src/lib.rs index 6a86aaaffee..f8f0656aa49 100644 --- a/examples/incomplete-async-payloads/src/lib.rs +++ b/examples/incomplete-async-payloads/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Encode, Decode, Debug)] pub enum Command { HandleStore, diff --git a/examples/init-fail-sender/Cargo.toml b/examples/init-fail-sender/Cargo.toml index 34611c8f1fb..e73ad80694c 100644 --- a/examples/init-fail-sender/Cargo.toml +++ b/examples/init-fail-sender/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/init-fail-sender/build.rs b/examples/init-fail-sender/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/init-fail-sender/build.rs +++ b/examples/init-fail-sender/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/init-fail-sender/src/lib.rs b/examples/init-fail-sender/src/lib.rs index a9c048cd09d..8cd47057848 100644 --- a/examples/init-fail-sender/src/lib.rs +++ b/examples/init-fail-sender/src/lib.rs @@ -1,13 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - pub fn system_reserve() -> u64 { gstd::Config::system_reserve() } diff --git a/examples/init-wait-reply-exit/Cargo.toml b/examples/init-wait-reply-exit/Cargo.toml index 71b6321fe47..02f96776f5b 100644 --- a/examples/init-wait-reply-exit/Cargo.toml +++ b/examples/init-wait-reply-exit/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/init-wait-reply-exit/build.rs b/examples/init-wait-reply-exit/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/init-wait-reply-exit/build.rs +++ b/examples/init-wait-reply-exit/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/init-wait-reply-exit/src/lib.rs b/examples/init-wait-reply-exit/src/lib.rs index 813a4f3ed30..63ac781a734 100644 --- a/examples/init-wait-reply-exit/src/lib.rs +++ b/examples/init-wait-reply-exit/src/lib.rs @@ -1,12 +1,4 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/init-wait/Cargo.toml b/examples/init-wait/Cargo.toml index de95cd060ee..af470e15dc1 100644 --- a/examples/init-wait/Cargo.toml +++ b/examples/init-wait/Cargo.toml @@ -7,11 +7,17 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/init-wait/build.rs b/examples/init-wait/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/init-wait/build.rs +++ b/examples/init-wait/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/init-wait/src/lib.rs b/examples/init-wait/src/lib.rs index 7cdc61e769f..c760a91b449 100644 --- a/examples/init-wait/src/lib.rs +++ b/examples/init-wait/src/lib.rs @@ -18,13 +18,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "wasm-wrapper"))] mod wasm; diff --git a/examples/mul-by-const/Cargo.toml b/examples/mul-by-const/Cargo.toml index 64e2f97f889..026cd2e162f 100644 --- a/examples/mul-by-const/Cargo.toml +++ b/examples/mul-by-const/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true hex.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/mul-by-const/build.rs b/examples/mul-by-const/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/mul-by-const/build.rs +++ b/examples/mul-by-const/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/mul-by-const/src/lib.rs b/examples/mul-by-const/src/lib.rs index 62761ccf165..30e69a08bca 100644 --- a/examples/mul-by-const/src/lib.rs +++ b/examples/mul-by-const/src/lib.rs @@ -25,13 +25,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/new-meta/Cargo.toml b/examples/new-meta/Cargo.toml index f78115c3251..bc467a889d1 100644 --- a/examples/new-meta/Cargo.toml +++ b/examples/new-meta/Cargo.toml @@ -17,6 +17,7 @@ demo-meta-state-v3 = { path = "state-v3", default-features = false, optional = t [build-dependencies] demo-meta-io = { path = "io" } +# TODO: how to compile metadata??? gear-wasm-builder.workspace = true [dev-dependencies] diff --git a/examples/node/Cargo.toml b/examples/node/Cargo.toml index d0e5078b4f4..fe8ab68285b 100644 --- a/examples/node/Cargo.toml +++ b/examples/node/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gstd = { workspace = true, features = ["debug"] } diff --git a/examples/node/build.rs b/examples/node/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/node/build.rs +++ b/examples/node/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/node/src/lib.rs b/examples/node/src/lib.rs index 87cd998e099..a3f10349428 100644 --- a/examples/node/src/lib.rs +++ b/examples/node/src/lib.rs @@ -23,11 +23,6 @@ extern crate alloc; use gstd::ActorId; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - #[derive(Encode, Debug, Decode, PartialEq, Eq)] pub struct Operation { to_status: u32, diff --git a/examples/out-of-memory/Cargo.toml b/examples/out-of-memory/Cargo.toml index c075c8d99e3..0bfffe5e088 100644 --- a/examples/out-of-memory/Cargo.toml +++ b/examples/out-of-memory/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd = { workspace = true, features = ["oom-handler"] } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/out-of-memory/build.rs b/examples/out-of-memory/build.rs index dfebd15e251..b04603c81a3 100644 --- a/examples/out-of-memory/build.rs +++ b/examples/out-of-memory/build.rs @@ -16,14 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - // We are forcing recommended nightly toolchain due to the need to compile this - // program with `oom-handler` feature. The WASM binary of this program is then - // used by the `oom_handler_works` pallet test. - WasmBuilder::new() - .exclude_features(vec!["std"]) - .with_forced_recommended_toolchain() // NOTE: Don't use this in production programs! - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/out-of-memory/src/lib.rs b/examples/out-of-memory/src/lib.rs index cd17f270609..26bfb695caa 100644 --- a/examples/out-of-memory/src/lib.rs +++ b/examples/out-of-memory/src/lib.rs @@ -21,13 +21,5 @@ extern crate alloc; extern crate gstd; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/piggy-bank/Cargo.toml b/examples/piggy-bank/Cargo.toml index 12e17ebc57b..e9e090c4c85 100644 --- a/examples/piggy-bank/Cargo.toml +++ b/examples/piggy-bank/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/piggy-bank/build.rs b/examples/piggy-bank/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/piggy-bank/build.rs +++ b/examples/piggy-bank/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/piggy-bank/src/lib.rs b/examples/piggy-bank/src/lib.rs index e96c8269a56..287eac316f8 100644 --- a/examples/piggy-bank/src/lib.rs +++ b/examples/piggy-bank/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index 50dd1ce8605..15320101fed 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/ping/build.rs b/examples/ping/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/ping/build.rs +++ b/examples/ping/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/ping/src/lib.rs b/examples/ping/src/lib.rs index e96c8269a56..287eac316f8 100644 --- a/examples/ping/src/lib.rs +++ b/examples/ping/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/program-factory/Cargo.toml b/examples/program-factory/Cargo.toml index 104d6b64ff3..129d6380051 100644 --- a/examples/program-factory/Cargo.toml +++ b/examples/program-factory/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true hex-literal.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/program-factory/build.rs b/examples/program-factory/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/program-factory/build.rs +++ b/examples/program-factory/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/program-factory/src/lib.rs b/examples/program-factory/src/lib.rs index 2ce8dcf6aa2..6af4adf33d7 100644 --- a/examples/program-factory/src/lib.rs +++ b/examples/program-factory/src/lib.rs @@ -28,14 +28,6 @@ use gstd::prelude::*; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)] pub enum CreateProgram { Default, diff --git a/examples/program-generator/Cargo.toml b/examples/program-generator/Cargo.toml index 9782f2a468f..7855b028e91 100644 --- a/examples/program-generator/Cargo.toml +++ b/examples/program-generator/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true hex-literal.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/program-generator/build.rs b/examples/program-generator/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/program-generator/build.rs +++ b/examples/program-generator/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/program-generator/src/lib.rs b/examples/program-generator/src/lib.rs index 8d5913b370e..14cf72efc3b 100644 --- a/examples/program-generator/src/lib.rs +++ b/examples/program-generator/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] pub const CHILD_WAT: &str = r#" (module diff --git a/examples/proxy-relay/Cargo.toml b/examples/proxy-relay/Cargo.toml index 4378c75e4e3..49e50166abf 100644 --- a/examples/proxy-relay/Cargo.toml +++ b/examples/proxy-relay/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true scale-info.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/proxy-relay/build.rs b/examples/proxy-relay/build.rs index 374613a2d14..96b5e8e9ae3 100644 --- a/examples/proxy-relay/build.rs +++ b/examples/proxy-relay/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/proxy-relay/src/lib.rs b/examples/proxy-relay/src/lib.rs index 0f40ae92019..47b00e96803 100644 --- a/examples/proxy-relay/src/lib.rs +++ b/examples/proxy-relay/src/lib.rs @@ -22,14 +22,6 @@ use gstd::Vec; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Decode, Encode, TypeInfo)] pub struct ResendPushData { pub destination: gstd::ActorId, diff --git a/examples/proxy-reservation-with-gas/Cargo.toml b/examples/proxy-reservation-with-gas/Cargo.toml index c8e775cdf43..a2860ff2781 100644 --- a/examples/proxy-reservation-with-gas/Cargo.toml +++ b/examples/proxy-reservation-with-gas/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true scale-info.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/proxy-reservation-with-gas/build.rs b/examples/proxy-reservation-with-gas/build.rs index 374613a2d14..96b5e8e9ae3 100644 --- a/examples/proxy-reservation-with-gas/build.rs +++ b/examples/proxy-reservation-with-gas/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/proxy-reservation-with-gas/src/lib.rs b/examples/proxy-reservation-with-gas/src/lib.rs index 9fc67f9982d..4695762584b 100644 --- a/examples/proxy-reservation-with-gas/src/lib.rs +++ b/examples/proxy-reservation-with-gas/src/lib.rs @@ -21,14 +21,6 @@ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Decode, Encode, TypeInfo)] pub struct InputArgs { pub destination: gstd::ActorId, diff --git a/examples/proxy/Cargo.toml b/examples/proxy/Cargo.toml index f679ca89cd5..ad2a6e67c1a 100644 --- a/examples/proxy/Cargo.toml +++ b/examples/proxy/Cargo.toml @@ -7,13 +7,19 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true scale-info.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/proxy/build.rs b/examples/proxy/build.rs index 8ee80924046..96b5e8e9ae3 100644 --- a/examples/proxy/build.rs +++ b/examples/proxy/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/proxy/src/lib.rs b/examples/proxy/src/lib.rs index cdfdd810906..0267d3f5d03 100644 --- a/examples/proxy/src/lib.rs +++ b/examples/proxy/src/lib.rs @@ -21,14 +21,6 @@ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Decode, Encode, TypeInfo)] pub struct InputArgs { pub destination: [u8; 32], diff --git a/examples/read-big-state/Cargo.toml b/examples/read-big-state/Cargo.toml index c20badfe83a..7f1147b32a1 100644 --- a/examples/read-big-state/Cargo.toml +++ b/examples/read-big-state/Cargo.toml @@ -7,15 +7,21 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true -parity-scale-codec.workspace = true +io = { package = "demo-read-big-state-io", path = "io", default-features = false } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] wasm-wrapper = [] -std = ["wasm-wrapper", "parity-scale-codec/std"] +std = ["wasm-wrapper", "io/std"] default = ["std"] diff --git a/examples/read-big-state/build.rs b/examples/read-big-state/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/read-big-state/build.rs +++ b/examples/read-big-state/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/read-big-state/io/Cargo.toml b/examples/read-big-state/io/Cargo.toml new file mode 100644 index 00000000000..59f844e97e1 --- /dev/null +++ b/examples/read-big-state/io/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "demo-read-big-state-io" +version = "0.1.0" +edition = "2021" + +[dependencies] +parity-scale-codec.workspace = true + +[features] +default = ["std"] +std = ["parity-scale-codec/std"] diff --git a/examples/read-big-state/io/src/lib.rs b/examples/read-big-state/io/src/lib.rs new file mode 100644 index 00000000000..842b4dad30e --- /dev/null +++ b/examples/read-big-state/io/src/lib.rs @@ -0,0 +1,52 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +extern crate alloc; + +use alloc::{collections::BTreeMap, string::String, vec, vec::Vec}; +use parity_scale_codec::{Decode, Encode}; + +#[derive(Encode, Decode, Default, Debug, Clone)] +pub struct Strings(pub Vec); + +impl Strings { + pub const LEN: usize = 16; + + pub fn new(string: String) -> Self { + Self(vec![string; Self::LEN]) + } +} + +#[derive(Encode, Decode, Default, Debug, Clone)] +pub struct State(pub Vec>); + +impl State { + pub const LEN: usize = 16; + + pub fn new() -> Self { + Self(vec![Default::default(); Self::LEN]) + } + + pub fn insert(&mut self, strings: Strings) { + for map in &mut self.0 { + map.insert(map.keys().count() as u64, strings.clone()); + } + } +} diff --git a/examples/read-big-state/src/lib.rs b/examples/read-big-state/src/lib.rs index 63bbe221675..c3c011b40e5 100644 --- a/examples/read-big-state/src/lib.rs +++ b/examples/read-big-state/src/lib.rs @@ -18,46 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -extern crate alloc; - -use alloc::{collections::BTreeMap, string::String, vec, vec::Vec}; -use parity_scale_codec::{Decode, Encode}; - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -#[derive(Encode, Decode, Default, Debug, Clone)] -pub struct Strings(pub Vec); - -impl Strings { - pub const LEN: usize = 16; - - pub fn new(string: String) -> Self { - Self(vec![string; Self::LEN]) - } -} - -#[derive(Encode, Decode, Default, Debug, Clone)] -pub struct State(pub Vec>); - -impl State { - pub const LEN: usize = 16; - - pub fn new() -> Self { - Self(vec![Default::default(); Self::LEN]) - } - - pub fn insert(&mut self, strings: Strings) { - for map in &mut self.0 { - map.insert(map.keys().count() as u64, strings.clone()); - } - } -} - #[cfg(not(feature = "wasm-wrapper"))] mod wasm; + +pub use io::*; diff --git a/examples/read-big-state/src/wasm.rs b/examples/read-big-state/src/wasm.rs index 569b810a49b..9d4893cf17e 100644 --- a/examples/read-big-state/src/wasm.rs +++ b/examples/read-big-state/src/wasm.rs @@ -16,8 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::State; use gstd::{msg, prelude::*}; +use io::State; static mut STATE: Option = None; diff --git a/examples/reservation-manager/Cargo.toml b/examples/reservation-manager/Cargo.toml index 372ecdbd5aa..7b9fc027831 100644 --- a/examples/reservation-manager/Cargo.toml +++ b/examples/reservation-manager/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/reservation-manager/build.rs b/examples/reservation-manager/build.rs index 44f0f822521..2f3db0a44f5 100644 --- a/examples/reservation-manager/build.rs +++ b/examples/reservation-manager/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/reservation-manager/src/lib.rs b/examples/reservation-manager/src/lib.rs index 2c8b487a2e9..0cf16d37387 100644 --- a/examples/reservation-manager/src/lib.rs +++ b/examples/reservation-manager/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Encode, Decode)] pub enum Action { Reserve { amount: u64, duration: u32 }, diff --git a/examples/reserve-gas/Cargo.toml b/examples/reserve-gas/Cargo.toml index 896a36a5d0b..a2224741a14 100644 --- a/examples/reserve-gas/Cargo.toml +++ b/examples/reserve-gas/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true -parity-scale-codec.workspace = true +io = { package = "demo-reserve-gas-io", path = "io", default-features = false } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true @@ -20,5 +23,5 @@ gtest.workspace = true [features] debug = ["gstd/debug"] wasm-wrapper = [] -std = ["wasm-wrapper", "parity-scale-codec/std"] +std = ["wasm-wrapper", "io/std"] default = ["std"] diff --git a/examples/reserve-gas/build.rs b/examples/reserve-gas/build.rs index 3c78830980f..d28451f1bbd 100644 --- a/examples/reserve-gas/build.rs +++ b/examples/reserve-gas/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program() } diff --git a/examples/reserve-gas/io/Cargo.toml b/examples/reserve-gas/io/Cargo.toml new file mode 100644 index 00000000000..b80c821b4ce --- /dev/null +++ b/examples/reserve-gas/io/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "demo-reserve-gas-io" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +parity-scale-codec.workspace = true + +[features] +default = ["std"] +std = ["parity-scale-codec/std"] diff --git a/examples/reserve-gas/io/src/lib.rs b/examples/reserve-gas/io/src/lib.rs new file mode 100644 index 00000000000..54f746c4d03 --- /dev/null +++ b/examples/reserve-gas/io/src/lib.rs @@ -0,0 +1,55 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +extern crate alloc; + +use alloc::vec::Vec; +use parity_scale_codec::{Decode, Encode}; + +pub const RESERVATION_AMOUNT: u64 = 50_000_000; +pub const REPLY_FROM_RESERVATION_PAYLOAD: &[u8; 5] = b"Hello"; + +#[derive(Debug, Encode, Decode)] +pub enum InitAction { + Normal(Vec<(u64, u32)>), + Wait, + CheckArgs { mailbox_threshold: u64 }, + FreshReserveUnreserve, +} + +#[derive(Debug, Encode, Decode)] +pub enum HandleAction { + Unreserve, + Exit, + ReplyFromReservation, + AddReservationToList(GasAmount, BlockCount), + ConsumeReservationsFromList, + RunInifitely, + SendFromReservationAndUnreserve, +} + +#[derive(Debug, Encode, Decode)] +pub enum ReplyAction { + Panic, + Exit, +} + +pub type GasAmount = u64; +pub type BlockCount = u32; diff --git a/examples/reserve-gas/src/lib.rs b/examples/reserve-gas/src/lib.rs index 85c616371bf..c8f2f33e28a 100644 --- a/examples/reserve-gas/src/lib.rs +++ b/examples/reserve-gas/src/lib.rs @@ -20,51 +20,11 @@ extern crate alloc; -use alloc::vec::Vec; -use parity_scale_codec::{Decode, Encode}; - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -pub const RESERVATION_AMOUNT: u64 = 50_000_000; -pub const REPLY_FROM_RESERVATION_PAYLOAD: &[u8; 5] = b"Hello"; - -#[derive(Debug, Encode, Decode)] -pub enum InitAction { - Normal(Vec<(u64, u32)>), - Wait, - CheckArgs { mailbox_threshold: u64 }, - FreshReserveUnreserve, -} - -#[derive(Debug, Encode, Decode)] -pub enum HandleAction { - Unreserve, - Exit, - ReplyFromReservation, - AddReservationToList(GasAmount, BlockCount), - ConsumeReservationsFromList, - RunInifitely, - SendFromReservationAndUnreserve, -} - -#[derive(Debug, Encode, Decode)] -pub enum ReplyAction { - Panic, - Exit, -} - -pub type GasAmount = u64; -pub type BlockCount = u32; - #[cfg(not(feature = "wasm-wrapper"))] mod wasm; +pub use io::*; + #[cfg(test)] mod tests { use crate::InitAction; diff --git a/examples/reserve-gas/src/wasm.rs b/examples/reserve-gas/src/wasm.rs index 0d87110b198..7a6bef9dc62 100644 --- a/examples/reserve-gas/src/wasm.rs +++ b/examples/reserve-gas/src/wasm.rs @@ -16,15 +16,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{ - HandleAction, InitAction, ReplyAction, REPLY_FROM_RESERVATION_PAYLOAD, RESERVATION_AMOUNT, -}; use gstd::{ errors::{Error, ExecutionError, ExtError, ReservationError}, exec, msg, prelude::*, MessageId, ReservationId, }; +use io::{ + HandleAction, InitAction, ReplyAction, REPLY_FROM_RESERVATION_PAYLOAD, RESERVATION_AMOUNT, +}; static mut RESERVATION_ID: Option = None; static mut RESERVATIONS: Vec = Vec::new(); diff --git a/examples/rwlock/Cargo.toml b/examples/rwlock/Cargo.toml index b7a8621cb12..2b44b540a31 100644 --- a/examples/rwlock/Cargo.toml +++ b/examples/rwlock/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd = { workspace = true, features = ["debug"] } parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] default = ["std"] diff --git a/examples/rwlock/build.rs b/examples/rwlock/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/rwlock/build.rs +++ b/examples/rwlock/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/rwlock/src/lib.rs b/examples/rwlock/src/lib.rs index 191fe06fb9b..91a8bbf9cf4 100644 --- a/examples/rwlock/src/lib.rs +++ b/examples/rwlock/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Encode, Decode, Debug)] pub enum Command { Get, diff --git a/examples/send-from-reservation/Cargo.toml b/examples/send-from-reservation/Cargo.toml index cbde057d74b..363ef2526e5 100644 --- a/examples/send-from-reservation/Cargo.toml +++ b/examples/send-from-reservation/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/send-from-reservation/build.rs b/examples/send-from-reservation/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/send-from-reservation/build.rs +++ b/examples/send-from-reservation/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/send-from-reservation/src/lib.rs b/examples/send-from-reservation/src/lib.rs index 4f5c72db3c6..8a3e34b1447 100644 --- a/examples/send-from-reservation/src/lib.rs +++ b/examples/send-from-reservation/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Debug, Encode, Decode)] pub enum HandleAction { SendToUser, diff --git a/examples/signal-entry/Cargo.toml b/examples/signal-entry/Cargo.toml index 9e786a2254c..e52b6ed937c 100644 --- a/examples/signal-entry/Cargo.toml +++ b/examples/signal-entry/Cargo.toml @@ -7,14 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] -gcore.workspace = true gstd.workspace = true -parity-scale-codec.workspace = true gear-core.workspace = true +io = { package = "demo-signal-entry-io", path = "io", default-features = false } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true @@ -22,5 +24,5 @@ gtest.workspace = true [features] debug = ["gstd/debug"] wasm-wrapper = [] -std = ["wasm-wrapper", "parity-scale-codec/std"] +std = ["wasm-wrapper", "io/std"] default = ["std"] diff --git a/examples/signal-entry/build.rs b/examples/signal-entry/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/signal-entry/build.rs +++ b/examples/signal-entry/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/signal-entry/io/Cargo.toml b/examples/signal-entry/io/Cargo.toml new file mode 100644 index 00000000000..186e3380fb6 --- /dev/null +++ b/examples/signal-entry/io/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "demo-signal-entry-io" +version = "0.1.0" +edition = "2021" + +[dependencies] +gcore.workspace = true +parity-scale-codec.workspace = true + +[features] +default = ["std"] +std = ["parity-scale-codec/std"] diff --git a/examples/signal-entry/io/src/lib.rs b/examples/signal-entry/io/src/lib.rs new file mode 100644 index 00000000000..dd7470964a6 --- /dev/null +++ b/examples/signal-entry/io/src/lib.rs @@ -0,0 +1,54 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// We can't depend on gstd because it declares panic handler, so we just use gcore. + +#![no_std] + +use gcore::errors::SignalCode; +use parity_scale_codec::{Decode, Encode}; + +#[derive(Debug, Encode, Decode)] +pub enum HandleAction { + Simple, + Wait, + WaitAndPanic, + WaitAndReserveWithPanic, + WaitAndExit, + WaitWithReserveAmountAndPanic(u64), + Panic, + Exit, + Accumulate, + OutOfGas, + PanicInSignal, + AcrossWaits, + ZeroReserve, + ForbiddenCallInSignal([u8; 32]), + ForbiddenAction, + SaveSignal(SignalCode), + ExceedMemory, + ExceedStackLimit, + UnreachableInstruction, + InvalidDebugCall, + UnrecoverableExt, + IncorrectFree, + WaitWithoutSendingMessage, + MemoryAccess, +} + +pub const WAIT_AND_RESERVE_WITH_PANIC_GAS: u64 = 10_000_000_000; diff --git a/examples/signal-entry/src/lib.rs b/examples/signal-entry/src/lib.rs index 53abc5ee02c..f6e0542afe0 100644 --- a/examples/signal-entry/src/lib.rs +++ b/examples/signal-entry/src/lib.rs @@ -18,51 +18,11 @@ #![cfg_attr(not(feature = "std"), no_std)] -// We can't depend on gstd because it declares panic handler, so we just use gcore. -use gcore::errors::SignalCode; -use parity_scale_codec::{Decode, Encode}; - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -#[derive(Debug, Encode, Decode)] -pub enum HandleAction { - Simple, - Wait, - WaitAndPanic, - WaitAndReserveWithPanic, - WaitAndExit, - WaitWithReserveAmountAndPanic(u64), - Panic, - Exit, - Accumulate, - OutOfGas, - PanicInSignal, - AcrossWaits, - ZeroReserve, - ForbiddenCallInSignal([u8; 32]), - ForbiddenAction, - SaveSignal(SignalCode), - ExceedMemory, - ExceedStackLimit, - UnreachableInstruction, - InvalidDebugCall, - UnrecoverableExt, - IncorrectFree, - WaitWithoutSendingMessage, - MemoryAccess, -} - -pub const WAIT_AND_RESERVE_WITH_PANIC_GAS: u64 = 10_000_000_000; - #[cfg(not(feature = "wasm-wrapper"))] mod wasm; +pub use io::*; + #[cfg(test)] mod tests { use gstd::errors::{SignalCode, SimpleExecutionError}; diff --git a/examples/signal-entry/src/wasm.rs b/examples/signal-entry/src/wasm.rs index 8fb46cf5f3c..3109ad146da 100644 --- a/examples/signal-entry/src/wasm.rs +++ b/examples/signal-entry/src/wasm.rs @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{HandleAction, WAIT_AND_RESERVE_WITH_PANIC_GAS}; use gear_core::ids::ProgramId; use gstd::{ debug, @@ -27,6 +26,7 @@ use gstd::{ prelude::*, ActorId, MessageId, }; +use io::{HandleAction, WAIT_AND_RESERVE_WITH_PANIC_GAS}; static mut INITIATOR: ActorId = ActorId::zero(); static mut HANDLE_MSG: Option = None; diff --git a/examples/signal-wait/Cargo.toml b/examples/signal-wait/Cargo.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/signal-wait/src/lib.rs b/examples/signal-wait/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/examples/signal-wait/src/lib.rs @@ -0,0 +1 @@ + diff --git a/examples/stack-allocations/src/lib.rs b/examples/stack-allocations/src/lib.rs index b23726856f4..44c5fef3184 100644 --- a/examples/stack-allocations/src/lib.rs +++ b/examples/stack-allocations/src/lib.rs @@ -68,6 +68,7 @@ mod tests { use parity_scale_codec::Decode; use rand::{Rng, SeedableRng}; + #[allow(clippy::assertions_on_constants)] #[test] fn stress() { use Action::*; diff --git a/examples/state-rollback/Cargo.toml b/examples/state-rollback/Cargo.toml index c4d156bc250..2c962a7fdf2 100644 --- a/examples/state-rollback/Cargo.toml +++ b/examples/state-rollback/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/state-rollback/build.rs b/examples/state-rollback/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/state-rollback/build.rs +++ b/examples/state-rollback/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/state-rollback/src/lib.rs b/examples/state-rollback/src/lib.rs index e96c8269a56..287eac316f8 100644 --- a/examples/state-rollback/src/lib.rs +++ b/examples/state-rollback/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/sync-duplicate/Cargo.toml b/examples/sync-duplicate/Cargo.toml index f0d0a3adf96..ad04b9b1722 100644 --- a/examples/sync-duplicate/Cargo.toml +++ b/examples/sync-duplicate/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/sync-duplicate/build.rs b/examples/sync-duplicate/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/sync-duplicate/build.rs +++ b/examples/sync-duplicate/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/sync-duplicate/src/lib.rs b/examples/sync-duplicate/src/lib.rs index e96c8269a56..287eac316f8 100644 --- a/examples/sync-duplicate/src/lib.rs +++ b/examples/sync-duplicate/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/syscalls/Cargo.toml b/examples/syscalls/Cargo.toml index 1e0e64155bd..3db22e28ad1 100644 --- a/examples/syscalls/Cargo.toml +++ b/examples/syscalls/Cargo.toml @@ -7,15 +7,22 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true +io = { package = "test-syscalls-io", path = "io", default-features = false } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] wasm-wrapper = [] -std = ["wasm-wrapper", "parity-scale-codec/std"] +std = ["wasm-wrapper", "parity-scale-codec/std", "io/std"] default = ["std"] diff --git a/examples/syscalls/build.rs b/examples/syscalls/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/syscalls/build.rs +++ b/examples/syscalls/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/syscalls/io/Cargo.toml b/examples/syscalls/io/Cargo.toml new file mode 100644 index 00000000000..43439d910bc --- /dev/null +++ b/examples/syscalls/io/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "test-syscalls-io" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +parity-scale-codec.workspace = true + +[features] +default = ["std"] +std = ["parity-scale-codec/std"] diff --git a/examples/syscalls/io/src/lib.rs b/examples/syscalls/io/src/lib.rs new file mode 100644 index 00000000000..5d8217d773a --- /dev/null +++ b/examples/syscalls/io/src/lib.rs @@ -0,0 +1,110 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +extern crate alloc; + +use alloc::{string::String, vec::Vec}; +use parity_scale_codec::{Decode, Encode}; + +#[cfg(feature = "wasm-wrapper")] +mod code { + include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +} + +#[cfg(feature = "wasm-wrapper")] +pub use code::WASM_BINARY_OPT as WASM_BINARY; + +type MessageId = [u8; 32]; +type ActorId = [u8; 32]; +type Value = u128; +type Gas = u64; + +// Instead of proper gstd primitives we use their raw versions to make this program +// compilable as a dependency for the build of the `gear` with `runtime-benchmarking` feature. +#[derive(Debug, Encode, Decode)] +pub enum Kind { + // Params(salt, gas), Expected(message id, actor id) + CreateProgram(u64, Option, (MessageId, ActorId)), + // Params(value), Expected(error message) + Error(u128, String), + // Params(gas), Expected(message id) + Send(Option, MessageId), + // Params(payload, gas), Expected(message id) + SendRaw(Vec, Option, MessageId), + // Params(gas), Expected(message id) + SendInput(Option, MessageId), + // Expected(message id) + SendPushInput(MessageId), + // Expected(payload size) + Size(u32), + // Expected(message id) + MessageId(MessageId), + // Expected(program id) + ProgramId(ActorId), + // Expected(message sender) + Source(ActorId), + // Expected(message value) + Value(u128), + // Expected(this program's balance) + ValueAvailable(u128), + // Params(gas), Expected(message id) + Reply(Option, MessageId), + // Params(payload, gas), Expected(message id) + ReplyRaw(Vec, Option, MessageId), + // Params(gas), Expected(message id) + ReplyInput(Option, MessageId), + // Expected(message id) + ReplyPushInput(MessageId), + // Expected(reply to id, ReplyCode.to_bytes repr) + ReplyDetails(MessageId, [u8; 4]), + SignalDetails, + SignalDetailsWake, + // Expected values + EnvVars { + performance_multiplier: u32, + existential_deposit: Value, + mailbox_threshold: Gas, + gas_to_value_multiplier: Value, + }, + // Expected(block height) + BlockHeight(u32), + // Expected(block timestamp) + BlockTimestamp(u64), + // Expected(id) + Reserve(Vec), + // Expected(amount) + Unreserve(u64), + // Param(salt), Expected(hash, block number) + Random([u8; 32], ([u8; 32], u32)), + // Expected(lower bound, upper bound )-> estimated gas level + GasAvailable(u64, u64), + // Expected(message id) + ReservationSend(MessageId), + // Param(payload), Expected(message id) + ReservationSendRaw(Vec, MessageId), + // Expected(message id) + ReservationReply(MessageId), + // Param(payload), Expected(message id) + ReservationReplyCommit(Vec, MessageId), + // Param(reserve amount) + SystemReserveGas(u64), + // Param(deposit amount) + ReplyDeposit(u64), +} diff --git a/examples/syscalls/src/lib.rs b/examples/syscalls/src/lib.rs index 6da55c28a3a..c760a91b449 100644 --- a/examples/syscalls/src/lib.rs +++ b/examples/syscalls/src/lib.rs @@ -18,96 +18,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -extern crate alloc; - -use alloc::{string::String, vec::Vec}; -use parity_scale_codec::{Decode, Encode}; - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -type MessageId = [u8; 32]; -type ActorId = [u8; 32]; -type Value = u128; -type Gas = u64; - -// Instead of proper gstd primitives we use their raw versions to make this program -// compilable as a dependency for the build of the `gear` with `runtime-benchmarking` feature. -#[derive(Debug, Encode, Decode)] -pub enum Kind { - // Params(salt, gas), Expected(message id, actor id) - CreateProgram(u64, Option, (MessageId, ActorId)), - // Params(value), Expected(error message) - Error(u128, String), - // Params(gas), Expected(message id) - Send(Option, MessageId), - // Params(payload, gas), Expected(message id) - SendRaw(Vec, Option, MessageId), - // Params(gas), Expected(message id) - SendInput(Option, MessageId), - // Expected(message id) - SendPushInput(MessageId), - // Expected(payload size) - Size(u32), - // Expected(message id) - MessageId(MessageId), - // Expected(program id) - ProgramId(ActorId), - // Expected(message sender) - Source(ActorId), - // Expected(message value) - Value(u128), - // Expected(this program's balance) - ValueAvailable(u128), - // Params(gas), Expected(message id) - Reply(Option, MessageId), - // Params(payload, gas), Expected(message id) - ReplyRaw(Vec, Option, MessageId), - // Params(gas), Expected(message id) - ReplyInput(Option, MessageId), - // Expected(message id) - ReplyPushInput(MessageId), - // Expected(reply to id, ReplyCode.to_bytes repr) - ReplyDetails(MessageId, [u8; 4]), - SignalDetails, - SignalDetailsWake, - // Expected values - EnvVars { - performance_multiplier: u32, - existential_deposit: Value, - mailbox_threshold: Gas, - gas_to_value_multiplier: Value, - }, - // Expected(block height) - BlockHeight(u32), - // Expected(block timestamp) - BlockTimestamp(u64), - // Expected(id) - Reserve(Vec), - // Expected(amount) - Unreserve(u64), - // Param(salt), Expected(hash, block number) - Random([u8; 32], ([u8; 32], u32)), - // Expected(lower bound, upper bound )-> estimated gas level - GasAvailable(u64, u64), - // Expected(message id) - ReservationSend(MessageId), - // Param(payload), Expected(message id) - ReservationSendRaw(Vec, MessageId), - // Expected(message id) - ReservationReply(MessageId), - // Param(payload), Expected(message id) - ReservationReplyCommit(Vec, MessageId), - // Param(reserve amount) - SystemReserveGas(u64), - // Param(deposit amount) - ReplyDeposit(u64), -} - #[cfg(not(feature = "wasm-wrapper"))] mod wasm; diff --git a/examples/syscalls/src/wasm.rs b/examples/syscalls/src/wasm.rs index eaf979d61ad..aef8a9b1fed 100644 --- a/examples/syscalls/src/wasm.rs +++ b/examples/syscalls/src/wasm.rs @@ -16,13 +16,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::Kind; use gstd::{ errors::{ReplyCode, SignalCode, SimpleExecutionError}, exec, format, msg::{self, MessageHandle}, prog, ActorId, CodeId, MessageId, ReservationId, Vec, }; +use io::Kind; use parity_scale_codec::Encode; static mut CODE_ID: CodeId = CodeId::new([0u8; 32]); diff --git a/examples/wait-timeout/Cargo.toml b/examples/wait-timeout/Cargo.toml index c1e7c4e47a0..dc39037b97a 100644 --- a/examples/wait-timeout/Cargo.toml +++ b/examples/wait-timeout/Cargo.toml @@ -7,13 +7,16 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true futures.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/wait-timeout/build.rs b/examples/wait-timeout/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/wait-timeout/build.rs +++ b/examples/wait-timeout/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/wait-timeout/src/lib.rs b/examples/wait-timeout/src/lib.rs index 4b9bcfbd53c..d49f3121ad2 100644 --- a/examples/wait-timeout/src/lib.rs +++ b/examples/wait-timeout/src/lib.rs @@ -21,14 +21,6 @@ use gstd::ActorId; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/wait/Cargo.toml b/examples/wait/Cargo.toml index 1ef9502fc9c..5c3a90af8fc 100644 --- a/examples/wait/Cargo.toml +++ b/examples/wait/Cargo.toml @@ -7,12 +7,15 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true gcore.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug", "gcore/debug"] diff --git a/examples/wait/build.rs b/examples/wait/build.rs index bd6ee0ee6b9..b04603c81a3 100644 --- a/examples/wait/build.rs +++ b/examples/wait/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/wait/src/lib.rs b/examples/wait/src/lib.rs index e96c8269a56..287eac316f8 100644 --- a/examples/wait/src/lib.rs +++ b/examples/wait/src/lib.rs @@ -16,15 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] - -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(not(feature = "std"))] mod wasm; diff --git a/examples/wait_wake/Cargo.toml b/examples/wait_wake/Cargo.toml index b92655788c4..8c7e5208fab 100644 --- a/examples/wait_wake/Cargo.toml +++ b/examples/wait_wake/Cargo.toml @@ -7,12 +7,18 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true parity-scale-codec.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true diff --git a/examples/wait_wake/build.rs b/examples/wait_wake/build.rs index 3c78830980f..b04603c81a3 100644 --- a/examples/wait_wake/build.rs +++ b/examples/wait_wake/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program(); } diff --git a/examples/wait_wake/src/lib.rs b/examples/wait_wake/src/lib.rs index d450e946f0a..a58887d0458 100644 --- a/examples/wait_wake/src/lib.rs +++ b/examples/wait_wake/src/lib.rs @@ -20,14 +20,6 @@ use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[derive(Encode, Debug, Decode, PartialEq, Eq)] pub enum Request { EchoWait(u32), diff --git a/examples/waiter/Cargo.toml b/examples/waiter/Cargo.toml index 546e34a37f7..661191712f5 100644 --- a/examples/waiter/Cargo.toml +++ b/examples/waiter/Cargo.toml @@ -7,14 +7,19 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.wasm-dep-builder.program] +exclude-features = ["std", "wasm-wrapper"] + +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] futures.workspace = true gstd.workspace = true -gcore.workspace = true -parity-scale-codec.workspace = true +io = { package = "demo-waiter-io", path = "io", default-features = false } [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [dev-dependencies] gtest.workspace = true @@ -24,5 +29,5 @@ demo-waiter = { workspace = true, features = ["debug"] } [features] debug = ["gstd/debug"] wasm-wrapper = [] -std = ["parity-scale-codec/std", "wasm-wrapper"] +std = ["io/std", "wasm-wrapper"] default = ["std"] diff --git a/examples/waiter/build.rs b/examples/waiter/build.rs index 3c78830980f..d28451f1bbd 100644 --- a/examples/waiter/build.rs +++ b/examples/waiter/build.rs @@ -16,10 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gear_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .exclude_features(vec!["std", "wasm-wrapper"]) - .build(); + wasm_dep_builder::track_program() } diff --git a/examples/waiter/io/Cargo.toml b/examples/waiter/io/Cargo.toml new file mode 100644 index 00000000000..47fdc5fdbd1 --- /dev/null +++ b/examples/waiter/io/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "demo-waiter-io" +version = "0.1.0" +edition = "2021" + +[dependencies] +parity-scale-codec.workspace = true +gcore.workspace = true + +[features] +default = ["std"] +std = ["parity-scale-codec/std"] diff --git a/examples/waiter/io/src/lib.rs b/examples/waiter/io/src/lib.rs new file mode 100644 index 00000000000..4a22b46c544 --- /dev/null +++ b/examples/waiter/io/src/lib.rs @@ -0,0 +1,92 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +extern crate alloc; + +use alloc::vec::Vec; +use gcore::BlockCount; +use parity_scale_codec::{Decode, Encode}; + +type ActorId = [u8; 32]; + +#[derive(Debug, Encode, Decode)] +pub enum WaitSubcommand { + Wait, + WaitFor(u32), + WaitUpTo(u32), +} + +#[derive(Debug, Encode, Decode)] +pub enum SleepForWaitType { + All, + Any, +} + +#[derive(Debug, Encode, Decode)] +pub enum LockContinuation { + Nothing, + SleepFor(u32), + MoveToStatic, + Wait, + Forget, +} + +#[derive(Debug, Encode, Decode)] +pub enum MxLockContinuation { + Lock, + General(LockContinuation), +} + +#[derive(Debug, Encode, Decode)] +pub enum LockStaticAccessSubcommand { + Drop, + AsRef, + AsMut, + Deref, + DerefMut, +} + +#[derive(Debug, Encode, Decode, Clone, Copy)] +pub enum RwLockType { + Read, + Write, +} + +#[derive(Debug, Encode, Decode)] +pub enum RwLockContinuation { + // Here will be Lock(RwLockType) + General(LockContinuation), +} + +#[derive(Debug, Encode, Decode)] +pub enum Command { + Wait(WaitSubcommand), + SendFor(ActorId, BlockCount), + SendUpTo(ActorId, BlockCount), + SendUpToWait(ActorId, BlockCount), + SendAndWaitFor(BlockCount, ActorId), + ReplyAndWait(WaitSubcommand), + SleepFor(Vec, SleepForWaitType), + WakeUp([u8; 32]), + MxLock(Option, MxLockContinuation), + MxLockStaticAccess(LockStaticAccessSubcommand), + RwLock(RwLockType, RwLockContinuation), + RwLockStaticAccess(RwLockType, LockStaticAccessSubcommand), +} diff --git a/examples/waiter/src/lib.rs b/examples/waiter/src/lib.rs index b9b43558d65..85b728d3d77 100644 --- a/examples/waiter/src/lib.rs +++ b/examples/waiter/src/lib.rs @@ -18,25 +18,11 @@ #![cfg_attr(not(feature = "std"), no_std)] -extern crate alloc; - -use alloc::vec::Vec; -use gcore::BlockCount; -use parity_scale_codec::{Decode, Encode}; - -type ActorId = [u8; 32]; - -#[cfg(feature = "wasm-wrapper")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "wasm-wrapper")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "wasm-wrapper"))] mod wasm; +pub use io::*; + #[cfg(feature = "std")] pub fn system_reserve() -> u64 { gstd::Config::system_reserve() @@ -47,68 +33,3 @@ pub fn system_reserve() -> u64 { pub fn default_wait_up_to_duration() -> u32 { gstd::Config::wait_up_to() } - -#[derive(Debug, Encode, Decode)] -pub enum WaitSubcommand { - Wait, - WaitFor(u32), - WaitUpTo(u32), -} - -#[derive(Debug, Encode, Decode)] -pub enum SleepForWaitType { - All, - Any, -} - -#[derive(Debug, Encode, Decode)] -pub enum LockContinuation { - Nothing, - SleepFor(u32), - MoveToStatic, - Wait, - Forget, -} - -#[derive(Debug, Encode, Decode)] -pub enum MxLockContinuation { - Lock, - General(LockContinuation), -} - -#[derive(Debug, Encode, Decode)] -pub enum LockStaticAccessSubcommand { - Drop, - AsRef, - AsMut, - Deref, - DerefMut, -} - -#[derive(Debug, Encode, Decode, Clone, Copy)] -pub enum RwLockType { - Read, - Write, -} - -#[derive(Debug, Encode, Decode)] -pub enum RwLockContinuation { - // Here will be Lock(RwLockType) - General(LockContinuation), -} - -#[derive(Debug, Encode, Decode)] -pub enum Command { - Wait(WaitSubcommand), - SendFor(ActorId, BlockCount), - SendUpTo(ActorId, BlockCount), - SendUpToWait(ActorId, BlockCount), - SendAndWaitFor(BlockCount, ActorId), - ReplyAndWait(WaitSubcommand), - SleepFor(Vec, SleepForWaitType), - WakeUp([u8; 32]), - MxLock(Option, MxLockContinuation), - MxLockStaticAccess(LockStaticAccessSubcommand), - RwLock(RwLockType, RwLockContinuation), - RwLockStaticAccess(RwLockType, LockStaticAccessSubcommand), -} diff --git a/examples/waiter/src/wasm.rs b/examples/waiter/src/wasm.rs index f92987b6f1f..19a0b35f341 100644 --- a/examples/waiter/src/wasm.rs +++ b/examples/waiter/src/wasm.rs @@ -16,16 +16,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{ - Command, LockContinuation, LockStaticAccessSubcommand, MxLockContinuation, RwLockContinuation, - RwLockType, SleepForWaitType, WaitSubcommand, -}; use core::ops::{Deref, DerefMut}; use futures::future; use gstd::{ exec, format, msg, sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}, }; +use io::{ + Command, LockContinuation, LockStaticAccessSubcommand, MxLockContinuation, RwLockContinuation, + RwLockType, SleepForWaitType, WaitSubcommand, +}; static mut MUTEX: Mutex<()> = Mutex::new(()); static mut MUTEX_LOCK_GUARD: Option> = None; diff --git a/examples/waiter/tests/utils.rs b/examples/waiter/tests/utils/mod.rs similarity index 100% rename from examples/waiter/tests/utils.rs rename to examples/waiter/tests/utils/mod.rs diff --git a/examples/waiting-proxy/Cargo.toml b/examples/waiting-proxy/Cargo.toml index 076c2520096..fc063b0812f 100644 --- a/examples/waiting-proxy/Cargo.toml +++ b/examples/waiting-proxy/Cargo.toml @@ -7,11 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lib] +crate-type = ["lib", "cdylib"] + [dependencies] gstd.workspace = true [build-dependencies] -gear-wasm-builder.workspace = true +wasm-dep-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/waiting-proxy/build.rs b/examples/waiting-proxy/build.rs index 374613a2d14..96b5e8e9ae3 100644 --- a/examples/waiting-proxy/build.rs +++ b/examples/waiting-proxy/build.rs @@ -17,5 +17,5 @@ // along with this program. If not, see . fn main() { - gear_wasm_builder::build(); + wasm_dep_builder::track_program(); } diff --git a/examples/waiting-proxy/src/lib.rs b/examples/waiting-proxy/src/lib.rs index bc6163a1546..a5d28abf05d 100644 --- a/examples/waiting-proxy/src/lib.rs +++ b/examples/waiting-proxy/src/lib.rs @@ -18,13 +18,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - #[cfg(not(feature = "std"))] mod wasm; diff --git a/gclient/Cargo.toml b/gclient/Cargo.toml index daf873f476c..aee153022ec 100644 --- a/gclient/Cargo.toml +++ b/gclient/Cargo.toml @@ -30,20 +30,10 @@ wat.workspace = true env_logger.workspace = true hex-literal.workspace = true log.workspace = true -demo-async-tester.workspace = true demo-calc-hash.workspace = true -demo-calc-hash-in-one-block.workspace = true -demo-custom.workspace = true -demo-constructor = { workspace = true, features = ["std"] } -demo-distributor.workspace = true demo-meta-io.workspace = true demo-new-meta.workspace = true -demo-mul-by-const.workspace = true -demo-node.workspace = true -demo-program-factory.workspace = true -demo-proxy = { workspace = true, features = ["std"] } -demo-proxy-relay.workspace = true -demo-reserve-gas = { workspace = true, features = ["std"] } gmeta = { workspace = true } gstd = { workspace = true, features = ["debug"] } demo-wat.workspace = true +gclient-binaries = { path = "binaries" } diff --git a/gclient/binaries/Cargo.toml b/gclient/binaries/Cargo.toml new file mode 100644 index 00000000000..0d18c5fb20e --- /dev/null +++ b/gclient/binaries/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "gclient-binaries" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +demo-async-tester.workspace = true +demo-calc-hash-in-one-block.workspace = true +demo-custom.workspace = true +demo-constructor = { workspace = true, features = ["std"] } +demo-distributor.workspace = true +demo-mul-by-const.workspace = true +demo-node.workspace = true +demo-program-factory.workspace = true +demo-proxy = { workspace = true, features = ["std"] } +demo-proxy-relay.workspace = true +demo-reserve-gas = { workspace = true, features = ["std"] } + +[build-dependencies] +wasm-dep-builder.workspace = true diff --git a/gclient/binaries/build.rs b/gclient/binaries/build.rs new file mode 100644 index 00000000000..867b17139ce --- /dev/null +++ b/gclient/binaries/build.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +fn main() { + wasm_dep_builder::build_binaries(); +} diff --git a/gclient/binaries/src/lib.rs b/gclient/binaries/src/lib.rs new file mode 100644 index 00000000000..f347ab47538 --- /dev/null +++ b/gclient/binaries/src/lib.rs @@ -0,0 +1,19 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +include!(concat!(env!("OUT_DIR"), "/wasm_binaries.rs")); diff --git a/gclient/src/api/calls.rs b/gclient/src/api/calls.rs index 8fe32673874..8585a7d2252 100644 --- a/gclient/src/api/calls.rs +++ b/gclient/src/api/calls.rs @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#![allow(clippy::assertions_on_constants)] + use super::{GearApi, Result}; use crate::{api::storage::account_id::IntoAccountId32, utils, Error}; use gear_core::{ diff --git a/gclient/tests/backend.rs b/gclient/tests/backend.rs index 3403e74f5ed..937dd29401b 100644 --- a/gclient/tests/backend.rs +++ b/gclient/tests/backend.rs @@ -20,6 +20,7 @@ use demo_custom::{InitMessage, WASM_BINARY}; use gclient::{EventProcessor, GearApi}; +use gclient_binaries::*; use parity_scale_codec::Encode; #[tokio::test] diff --git a/gclient/tests/loop.rs b/gclient/tests/loop.rs index 470f6162a3a..33bd107dd60 100644 --- a/gclient/tests/loop.rs +++ b/gclient/tests/loop.rs @@ -20,6 +20,7 @@ use demo_constructor::{Calls, Scheme, WASM_BINARY}; use gclient::{EventProcessor, GearApi}; +use gclient_binaries::*; use parity_scale_codec::Encode; #[tokio::test] diff --git a/gclient/tests/memory_dump.rs b/gclient/tests/memory_dump.rs index d8c2c0a3919..4d7729214b8 100644 --- a/gclient/tests/memory_dump.rs +++ b/gclient/tests/memory_dump.rs @@ -18,6 +18,7 @@ use demo_custom::{InitMessage, WASM_BINARY}; use gclient::{EventListener, EventProcessor, GearApi, Result}; +use gclient_binaries::*; use gear_core::ids::ProgramId; use parity_scale_codec::Encode; diff --git a/gclient/tests/node.rs b/gclient/tests/node.rs index 6992948d53e..76711c687b2 100644 --- a/gclient/tests/node.rs +++ b/gclient/tests/node.rs @@ -1,4 +1,5 @@ use gclient::{Error, EventProcessor, GearApi}; +use gclient_binaries::*; use gear_core::ids::ProgramId; use hex::ToHex; use parity_scale_codec::{Decode, Encode}; diff --git a/gclient/tests/state.rs b/gclient/tests/state.rs index 0eec34dcdbb..125d24aa602 100644 --- a/gclient/tests/state.rs +++ b/gclient/tests/state.rs @@ -18,6 +18,7 @@ use demo_meta_io::Wallet; use gclient::{EventProcessor, GearApi}; +use gclient_binaries::*; use gmeta::MetadataRepr; use parity_scale_codec::{Decode, Encode}; diff --git a/gsdk/Cargo.toml b/gsdk/Cargo.toml index b49039d8855..d889c402878 100644 --- a/gsdk/Cargo.toml +++ b/gsdk/Cargo.toml @@ -42,6 +42,7 @@ rand = { workspace = true, optional = true } [dev-dependencies] gsdk = { path = ".", features = ["testing"] } +gsdk-binaries = { path = "binaries" } tokio = { workspace = true, features = [ "full" ] } demo-messager.workspace = true demo-new-meta.workspace = true diff --git a/gsdk/binaries/Cargo.toml b/gsdk/binaries/Cargo.toml new file mode 100644 index 00000000000..2c97cb86e47 --- /dev/null +++ b/gsdk/binaries/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "gsdk-binaries" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +demo-waiter.workspace = true + +[build-dependencies] +wasm-dep-builder.workspace = true diff --git a/gsdk/binaries/build.rs b/gsdk/binaries/build.rs new file mode 100644 index 00000000000..867b17139ce --- /dev/null +++ b/gsdk/binaries/build.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +fn main() { + wasm_dep_builder::build_binaries(); +} diff --git a/gsdk/binaries/src/lib.rs b/gsdk/binaries/src/lib.rs new file mode 100644 index 00000000000..f347ab47538 --- /dev/null +++ b/gsdk/binaries/src/lib.rs @@ -0,0 +1,19 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +include!(concat!(env!("OUT_DIR"), "/wasm_binaries.rs")); diff --git a/gsdk/tests/rpc.rs b/gsdk/tests/rpc.rs index 420547e0fa4..62409df1ab4 100644 --- a/gsdk/tests/rpc.rs +++ b/gsdk/tests/rpc.rs @@ -20,6 +20,7 @@ use gear_core::ids::{CodeId, ProgramId}; use gsdk::{Api, Error, Result}; +use gsdk_binaries::*; use jsonrpsee::types::error::{CallError, ErrorObject}; use parity_scale_codec::Encode; use std::{borrow::Cow, process::Command, str::FromStr}; diff --git a/gtest/Cargo.toml b/gtest/Cargo.toml index 73f8817e787..1934832e17f 100644 --- a/gtest/Cargo.toml +++ b/gtest/Cargo.toml @@ -26,8 +26,5 @@ rand = { workspace = true, features = ["std", "std_rng"] } log.workspace = true [dev-dependencies] -demo-custom.workspace = true -demo-piggy-bank.workspace = true -demo-ping.workspace = true -demo-futures-unordered.workspace = true demo-meta-io.workspace = true +gtest-binaries = { path = "binaries" } diff --git a/gtest/binaries/Cargo.toml b/gtest/binaries/Cargo.toml new file mode 100644 index 00000000000..76d0575e98d --- /dev/null +++ b/gtest/binaries/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "gtest-binaries" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +demo-custom.workspace = true +demo-piggy-bank.workspace = true +demo-ping.workspace = true +demo-futures-unordered.workspace = true + +[build-dependencies] +wasm-dep-builder.workspace = true diff --git a/gtest/binaries/build.rs b/gtest/binaries/build.rs new file mode 100644 index 00000000000..867b17139ce --- /dev/null +++ b/gtest/binaries/build.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +fn main() { + wasm_dep_builder::build_binaries(); +} diff --git a/gtest/binaries/src/lib.rs b/gtest/binaries/src/lib.rs new file mode 100644 index 00000000000..f347ab47538 --- /dev/null +++ b/gtest/binaries/src/lib.rs @@ -0,0 +1,19 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +include!(concat!(env!("OUT_DIR"), "/wasm_binaries.rs")); diff --git a/gtest/src/lib.rs b/gtest/src/lib.rs index d8a30361a00..c2396255298 100644 --- a/gtest/src/lib.rs +++ b/gtest/src/lib.rs @@ -430,6 +430,9 @@ mod manager; mod program; mod system; +#[cfg(test)] +use gtest_binaries as binaries; + pub use crate::log::{CoreLog, Log, RunResult}; pub use codec; pub use error::{Result, TestError}; diff --git a/gtest/src/mailbox.rs b/gtest/src/mailbox.rs index 6cb0fbeeb6e..6b979a82d35 100644 --- a/gtest/src/mailbox.rs +++ b/gtest/src/mailbox.rs @@ -132,7 +132,7 @@ impl<'a> MessageReplier<'a> { mod tests { use std::convert::TryInto; - use crate::{program::ProgramIdWrapper, Log, Program, System}; + use crate::{binaries::*, program::ProgramIdWrapper, Log, Program, System}; use codec::Encode; use gear_core::{ ids::MessageId, diff --git a/gtest/src/program.rs b/gtest/src/program.rs index 4febb547ac1..85913f5e8cf 100644 --- a/gtest/src/program.rs +++ b/gtest/src/program.rs @@ -834,7 +834,7 @@ pub fn calculate_program_id(code_id: CodeId, salt: &[u8], id: Option) #[cfg(test)] mod tests { use super::Program; - use crate::{Log, System}; + use crate::{binaries::*, Log, System}; use gear_core_errors::ErrorReplyReason; #[test] diff --git a/node/authorship/Cargo.toml b/node/authorship/Cargo.toml index eb8ef45d211..b12228c5228 100644 --- a/node/authorship/Cargo.toml +++ b/node/authorship/Cargo.toml @@ -41,7 +41,9 @@ sp-inherents = { workspace = true, features = ["std"] } prometheus-endpoint.workspace = true [dev-dependencies] +gear-authorship-binaries = { path = "binaries" } gear-runtime-interface = { workspace = true, features = ["std"] } +common = { workspace = true, features = ["std"] } sc-transaction-pool.workspace = true frame-support = { workspace = true, features = ["std"] } frame-system = { workspace = true, features = ["std"] } @@ -59,6 +61,5 @@ runtime-primitives = { workspace = true, features = ["std"] } gear-runtime-common = { workspace = true, features = ["std"] } gear-core = { workspace = true, features = ["std"] } vara-runtime = { workspace = true, features = ["std", "dev"] } -demo-constructor = { workspace = true, features = ["std"] } env_logger.workspace = true parking_lot.workspace = true diff --git a/node/authorship/binaries/Cargo.toml b/node/authorship/binaries/Cargo.toml new file mode 100644 index 00000000000..c438eccd34e --- /dev/null +++ b/node/authorship/binaries/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "gear-authorship-binaries" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +demo-constructor = { workspace = true, features = ["std"] } + +[build-dependencies] +wasm-dep-builder.workspace = true diff --git a/node/authorship/binaries/build.rs b/node/authorship/binaries/build.rs new file mode 100644 index 00000000000..867b17139ce --- /dev/null +++ b/node/authorship/binaries/build.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +fn main() { + wasm_dep_builder::build_binaries(); +} diff --git a/node/authorship/binaries/src/lib.rs b/node/authorship/binaries/src/lib.rs new file mode 100644 index 00000000000..f347ab47538 --- /dev/null +++ b/node/authorship/binaries/src/lib.rs @@ -0,0 +1,19 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +include!(concat!(env!("OUT_DIR"), "/wasm_binaries.rs")); diff --git a/node/authorship/src/tests.rs b/node/authorship/src/tests.rs index d0b7ebf2ce9..156d23cc52e 100644 --- a/node/authorship/src/tests.rs +++ b/node/authorship/src/tests.rs @@ -32,6 +32,7 @@ use core::convert::TryFrom; use demo_constructor::{Calls, Scheme, WASM_BINARY}; use frame_support::{assert_ok, storage::storage_prefix, traits::PalletInfoAccess}; use futures::executor::block_on; +use gear_authorship_binaries::*; use gear_runtime_common::constants::BANK_ADDRESS; use pallet_gear_rpc_runtime_api::GearApi; use parking_lot::Mutex; diff --git a/node/service/src/client.rs b/node/service/src/client.rs index 5e664a9f127..fc273eceb59 100644 --- a/node/service/src/client.rs +++ b/node/service/src/client.rs @@ -54,6 +54,7 @@ impl sc_executor::NativeExecutionDispatch for VaraExecutorDispatch { type ExtendHostFunctions = ( frame_benchmarking::benchmarking::HostFunctions, gear_ri::gear_ri::HostFunctions, + gear_ri::gear_benchmarks::HostFunctions, gear_ri::sandbox::HostFunctions, ); /// Otherwise we only use the default Substrate host functions. diff --git a/pallets/gear-debug/Cargo.toml b/pallets/gear-debug/Cargo.toml index e0c9efb3478..4357b46c9fc 100644 --- a/pallets/gear-debug/Cargo.toml +++ b/pallets/gear-debug/Cargo.toml @@ -48,7 +48,6 @@ pallet-gear-scheduler = { workspace = true, features = ["std"] } pallet-gear-program = { workspace = true, features = ["std"] } gear-wasm-instrument.workspace = true demo-vec.workspace = true -test-syscalls.workspace = true [features] default = ['std'] @@ -68,7 +67,6 @@ std = [ "pallet-authorship/std", "primitive-types/std", "pallet-gear/std", - "test-syscalls/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/pallets/gear/Cargo.toml b/pallets/gear/Cargo.toml index 46dd5d103bb..003b5062d73 100644 --- a/pallets/gear/Cargo.toml +++ b/pallets/gear/Cargo.toml @@ -56,15 +56,12 @@ serde = { workspace = true, optional = true, features = ["derive"] } rand = { workspace = true, optional = true } rand_pcg = { workspace = true, optional = true } sp-consensus-slots = { workspace = true, optional = true } -test-syscalls = { workspace = true, optional = true } -demo-read-big-state = { workspace = true, optional = true } -demo-proxy = { workspace = true, optional = true } -demo-reserve-gas = { workspace = true, optional = true } -demo-delayed-sender = { workspace = true, optional = true } -demo-constructor = { workspace = true, optional = true } -demo-waiter = { workspace = true, optional = true } -demo-init-wait = { workspace = true, optional = true } -demo-signal-entry = { workspace = true, optional = true } +demo-reserve-gas-io = { workspace = true, optional = true } +demo-constructor-io = { workspace = true, optional = true } +demo-waiter-io = { workspace = true, optional = true } +demo-read-big-state-io = { workspace = true, optional = true } +demo-signal-entry-io = { workspace = true, optional = true } +test-syscalls-io = { workspace = true, optional = true } # Some of tests require `debug` feature enabled [dev-dependencies] @@ -72,51 +69,8 @@ wabt.workspace = true hex.workspace = true blake2-rfc.workspace = true gstd.workspace = true -demo-async.workspace = true -demo-async-init.workspace = true -demo-async-recursion.workspace = true -demo-async-tester = { workspace = true, features = ["debug"] } -demo-delayed-sender.workspace = true -demo-distributor.workspace = true -demo-init-fail-sender.workspace = true -demo-init-wait.workspace = true -demo-init-wait-reply-exit.workspace = true demo-new-meta.workspace = true -demo-futures-unordered.workspace = true -demo-program-factory.workspace = true -demo-program-generator.workspace = true -demo-proxy.workspace = true -demo-proxy-relay.workspace = true -demo-proxy-reservation-with-gas.workspace = true -demo-read-big-state.workspace = true -demo-incomplete-async-payloads.workspace = true -demo-gas-burned.workspace = true -demo-waiting-proxy.workspace = true demo-calc-hash.workspace = true -demo-calc-hash-over-blocks.workspace = true -demo-calc-hash-in-one-block.workspace = true -demo-compose.workspace = true -demo-constructor = { workspace = true, features = ["debug"] } -demo-mul-by-const.workspace = true -demo-wait.workspace = true -demo-waiter = { workspace = true, features = ["debug"] } -demo-wait-timeout.workspace = true -demo-wait-wake.workspace = true -demo-reserve-gas.workspace = true -demo-rwlock.workspace = true -demo-reservation-manager.workspace = true -demo-send-from-reservation.workspace = true -demo-signal-entry = { workspace = true, features = ["debug"] } -demo-state-rollback.workspace = true -demo-async-signal-entry.workspace = true -demo-async-custom-entry.workspace = true -demo-out-of-memory.workspace = true -demo-ping.workspace = true -demo-sync-duplicate.workspace = true -demo-custom.workspace = true -demo-delayed-reservation-sender = { workspace = true, features = ["debug"] } -demo-async-critical = { workspace = true, features = ["debug"] } -test-syscalls = { workspace = true, features = ["debug"] } page_size.workspace = true frame-support-test = { workspace = true, features = ["std"] } common = { workspace = true, features = ["std"] } @@ -126,6 +80,7 @@ pallet-gear-scheduler = { workspace = true, features = ["std"] } pallet-gear-program = { workspace = true, features = ["std"] } pallet-gear-voucher = { workspace = true, features = ["std"] } gmeta.workspace = true +pallet-gear-binaries = { path = "binaries", features = ["std", "debug"] } [features] default = ['std'] @@ -161,22 +116,13 @@ std = [ "primitive-types/std", "serde/std", "sp-consensus-babe/std", - "test-syscalls?/std", - "demo-read-big-state?/std", - "demo-proxy?/std", - "demo-reserve-gas?/std", - "demo-delayed-sender?/std", - "demo-constructor?/std", - "demo-waiter?/std", - "demo-init-wait?/std", - "demo-signal-entry?/std", - "gear-runtime-interface/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", "common/runtime-benchmarks", + "gear-runtime-interface/runtime-benchmarks", "gear-core-backend/mock", "gear-core-errors/codec", "gear-sandbox", @@ -184,16 +130,13 @@ runtime-benchmarks = [ "sp-consensus-babe", "rand", "rand_pcg", - "test-syscalls/wasm-wrapper", - "demo-read-big-state/wasm-wrapper", - "demo-proxy/wasm-wrapper", "gsys", - "demo-reserve-gas/wasm-wrapper", - "demo-delayed-sender/wasm-wrapper", - "demo-constructor/wasm-wrapper", - "demo-waiter/wasm-wrapper", - "demo-init-wait/wasm-wrapper", - "demo-signal-entry/wasm-wrapper", + "demo-reserve-gas-io", + "demo-constructor-io/wasm-wrapper", + "demo-waiter-io", + "demo-read-big-state-io", + "demo-signal-entry-io", + "test-syscalls-io", ] runtime-benchmarks-checkers = [] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/gear/binaries/Cargo.toml b/pallets/gear/binaries/Cargo.toml new file mode 100644 index 00000000000..6d3a3f2b8c2 --- /dev/null +++ b/pallets/gear/binaries/Cargo.toml @@ -0,0 +1,91 @@ +[package] +name = "pallet-gear-binaries" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[package.metadata.wasm-dep-builder.binaries] +include = ["demo-*", "test-syscalls"] + +[dependencies] +demo-async.workspace = true +demo-async-init.workspace = true +demo-async-recursion.workspace = true +demo-async-tester.workspace = true +demo-async-critical.workspace = true +demo-delayed-sender.workspace = true +demo-distributor.workspace = true +demo-init-fail-sender.workspace = true +demo-init-wait.workspace = true +demo-init-wait-reply-exit.workspace = true +demo-futures-unordered.workspace = true +demo-program-factory.workspace = true +demo-program-generator.workspace = true +demo-proxy.workspace = true +demo-proxy-relay.workspace = true +demo-proxy-reservation-with-gas.workspace = true +demo-read-big-state.workspace = true +demo-incomplete-async-payloads.workspace = true +demo-gas-burned.workspace = true +demo-waiting-proxy.workspace = true +demo-calc-hash-over-blocks.workspace = true +demo-calc-hash-in-one-block.workspace = true +demo-compose.workspace = true +demo-constructor.workspace = true +demo-mul-by-const.workspace = true +demo-wait.workspace = true +demo-waiter.workspace = true +demo-wait-timeout.workspace = true +demo-wait-wake.workspace = true +demo-reserve-gas.workspace = true +demo-rwlock.workspace = true +demo-reservation-manager.workspace = true +demo-send-from-reservation.workspace = true +demo-signal-entry.workspace = true +demo-state-rollback.workspace = true +demo-async-signal-entry.workspace = true +demo-async-custom-entry.workspace = true +demo-out-of-memory.workspace = true +demo-ping.workspace = true +demo-sync-duplicate.workspace = true +demo-custom.workspace = true +demo-delayed-reservation-sender.workspace = true +test-syscalls.workspace = true + +[build-dependencies] +wasm-dep-builder.workspace = true + +[features] +default = ['std'] +std = [ + "demo-read-big-state/std", + "demo-proxy/std", + "demo-reserve-gas/std", + "demo-delayed-sender/std", + "demo-constructor/std", + "demo-waiter/std", + "demo-init-wait/std", + "test-syscalls/std", +] +wasm-wrapper = [ + "demo-read-big-state/wasm-wrapper", + "demo-proxy/wasm-wrapper", + "demo-reserve-gas/wasm-wrapper", + "demo-delayed-sender/wasm-wrapper", + "demo-constructor/wasm-wrapper", + "demo-waiter/wasm-wrapper", + "demo-init-wait/wasm-wrapper", + "demo-signal-entry/wasm-wrapper", + "test-syscalls/wasm-wrapper", +] +debug = [ + "demo-async-tester/debug", + "demo-constructor/debug", + "demo-waiter/debug", + "demo-delayed-reservation-sender/debug", + "demo-signal-entry/debug", + "test-syscalls/debug", +] diff --git a/pallets/gear/binaries/build.rs b/pallets/gear/binaries/build.rs new file mode 100644 index 00000000000..867b17139ce --- /dev/null +++ b/pallets/gear/binaries/build.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +fn main() { + wasm_dep_builder::build_binaries(); +} diff --git a/pallets/gear/binaries/src/lib.rs b/pallets/gear/binaries/src/lib.rs new file mode 100644 index 00000000000..f347ab47538 --- /dev/null +++ b/pallets/gear/binaries/src/lib.rs @@ -0,0 +1,19 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +include!(concat!(env!("OUT_DIR"), "/wasm_binaries.rs")); diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index 89b614a5b7b..f25b63fa447 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -33,6 +33,7 @@ //! So, we suppose this instruction have weight 0. #![cfg(feature = "runtime-benchmarks")] +#![allow(clippy::assertions_on_constants)] #[allow(dead_code)] mod code; diff --git a/pallets/gear/src/benchmarking/tasks.rs b/pallets/gear/src/benchmarking/tasks.rs index c94c6f1de48..8629354cb9c 100644 --- a/pallets/gear/src/benchmarking/tasks.rs +++ b/pallets/gear/src/benchmarking/tasks.rs @@ -15,6 +15,7 @@ use super::*; use gear_core::ids::ReservationId; +use gear_runtime_interface::{gear_benchmarks, WasmBinary}; #[track_caller] fn send_user_message_prepare(delay: u32) @@ -22,8 +23,6 @@ where T: Config, T::AccountId: Origin, { - use demo_delayed_sender::WASM_BINARY; - let caller = benchmarking::account("caller", 0, 0); let _ = CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); @@ -33,7 +32,7 @@ where let salt = vec![]; Gear::::upload_program( RawOrigin::Signed(caller).into(), - WASM_BINARY.to_vec(), + gear_benchmarks::wasm_binary(WasmBinary::DemoDelayedSender), salt, delay.encode(), 100_000_000_000, @@ -51,7 +50,9 @@ where T: Config, T::AccountId: Origin, { - use demo_reserve_gas::{InitAction, WASM_BINARY}; + use demo_reserve_gas_io::InitAction; + + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::DemoReserveGas); let caller = benchmarking::account("caller", 0, 0); let _ = @@ -60,10 +61,10 @@ where init_block::(None); let salt = vec![]; - let program_id = ProgramId::generate_from_user(CodeId::generate(WASM_BINARY), &salt); + let program_id = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), &salt); Gear::::upload_program( RawOrigin::Signed(caller).into(), - WASM_BINARY.to_vec(), + wasm_binary, salt, InitAction::Normal(vec![(50_000, 100)]).encode(), 10_000_000_000, @@ -119,7 +120,9 @@ where T: Config, T::AccountId: Origin, { - use demo_constructor::{Call, Calls, Scheme, WASM_BINARY}; + use demo_constructor_io::{Call, Calls, Scheme}; + + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::DemoConstructor); let caller = benchmarking::account("caller", 0, 0); let _ = @@ -128,10 +131,10 @@ where init_block::(None); let salt = vec![]; - let program_id = ProgramId::generate_from_user(CodeId::generate(WASM_BINARY), &salt); + let program_id = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), &salt); Gear::::upload_program( RawOrigin::Signed(caller.clone()).into(), - WASM_BINARY.to_vec(), + wasm_binary, salt, Scheme::empty().encode(), 10_000_000_000, @@ -176,7 +179,9 @@ where T: Config, T::AccountId: Origin, { - use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; + use demo_waiter_io::{Command, WaitSubcommand}; + + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::DemoWaiter); let caller = benchmarking::account("caller", 0, 0); let _ = @@ -185,10 +190,10 @@ where init_block::(None); let salt = vec![]; - let program_id = ProgramId::generate_from_user(CodeId::generate(WASM_BINARY), &salt); + let program_id = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), &salt); Gear::::upload_program( RawOrigin::Signed(caller.clone()).into(), - WASM_BINARY.to_vec(), + wasm_binary, salt, vec![], 10_000_000_000, @@ -227,7 +232,9 @@ where T: Config, T::AccountId: Origin, { - use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; + use demo_waiter_io::{Command, WaitSubcommand}; + + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::DemoWaiter); let caller = benchmarking::account("caller", 0, 0); let _ = @@ -236,10 +243,10 @@ where init_block::(None); let salt = vec![]; - let program_id = ProgramId::generate_from_user(CodeId::generate(WASM_BINARY), &salt); + let program_id = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), &salt); Gear::::upload_program( RawOrigin::Signed(caller.clone()).into(), - WASM_BINARY.to_vec(), + wasm_binary, salt, vec![], 10_000_000_000, diff --git a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs index b7be7a58668..ae92a8be050 100644 --- a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs +++ b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs @@ -34,21 +34,24 @@ use common::event::DispatchStatus; use frame_support::traits::Randomness; use gear_core::ids::{CodeId, ReservationId}; use gear_core_errors::{ReplyCode, SuccessReplyReason}; +use gear_runtime_interface::{gear_benchmarks, WasmBinary}; use gear_wasm_instrument::syscalls::SyscallName; use pallet_timestamp::Pallet as TimestampPallet; use parity_scale_codec::Decode; -use test_syscalls::{Kind, WASM_BINARY as SYSCALLS_TEST_WASM_BINARY}; +use test_syscalls_io::Kind; pub fn read_big_state() where T: Config, T::AccountId: Origin, { - use demo_read_big_state::{State, Strings, WASM_BINARY}; + use demo_read_big_state_io::{State, Strings}; #[cfg(feature = "std")] utils::init_logger(); + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::DemoReadBigState); + let origin = benchmarking::account::("origin", 0, 0); let _ = CurrencyOf::::deposit_creating( &origin, @@ -59,7 +62,7 @@ where Gear::::upload_program( RawOrigin::Signed(origin.clone()).into(), - WASM_BINARY.to_vec(), + wasm_binary.clone(), salt.to_vec(), Default::default(), BlockGasLimitOf::::get(), @@ -68,7 +71,7 @@ where ) .expect("Failed to upload read_big_state binary"); - let pid = ProgramId::generate_from_user(CodeId::generate(WASM_BINARY), salt); + let pid = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), salt); utils::run_to_next_block::(None); let string = String::from("hi").repeat(4095); @@ -135,7 +138,7 @@ where T: Config, T::AccountId: Origin, { - use demo_signal_entry::{HandleAction, WASM_BINARY}; + use demo_signal_entry_io::HandleAction; use frame_support::assert_ok; use gear_core_errors::*; @@ -144,6 +147,8 @@ where #[cfg(feature = "std")] utils::init_logger(); + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::DemoSignalEntry); + let origin = benchmarking::account::("origin", 0, 0); let _ = CurrencyOf::::deposit_creating( &origin, @@ -155,7 +160,7 @@ where // Upload program assert_ok!(Gear::::upload_program( RawOrigin::Signed(origin.clone()).into(), - WASM_BINARY.to_vec(), + wasm_binary.clone(), salt.to_vec(), origin.encode(), GAS_LIMIT, @@ -163,7 +168,7 @@ where false, )); - let pid = ProgramId::generate_from_user(CodeId::generate(WASM_BINARY), salt); + let pid = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), salt); utils::run_to_next_block::(None); // Ensure that program is uploaded and initialized correctly @@ -1055,8 +1060,9 @@ where let child_code = child_wasm.code; let child_code_hash = child_wasm.hash; - let tester_pid = - ProgramId::generate_from_user(CodeId::generate(SYSCALLS_TEST_WASM_BINARY), b""); + let wasm_binary = gear_benchmarks::wasm_binary(WasmBinary::TestSyscalls); + + let tester_pid = ProgramId::generate_from_user(CodeId::generate(&wasm_binary), b""); // Deploy program with valid code hash let child_deployer = benchmarking::account::("child_deployer", 0, 0); @@ -1083,7 +1089,7 @@ where ); Gear::::upload_program( RawOrigin::Signed(default_account).into(), - SYSCALLS_TEST_WASM_BINARY.to_vec(), + wasm_binary, b"".to_vec(), child_code_hash.encode(), 50_000_000_000, diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index 6efe0f6aa18..aeda33421bf 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -23,6 +23,9 @@ extern crate alloc; +#[cfg(test)] +use pallet_gear_binaries as binaries; + #[cfg(feature = "runtime-benchmarks")] mod benchmarking; diff --git a/pallets/gear/src/schedule.rs b/pallets/gear/src/schedule.rs index 281ee55ae6d..2300e17d228 100644 --- a/pallets/gear/src/schedule.rs +++ b/pallets/gear/src/schedule.rs @@ -20,6 +20,7 @@ //! sane default schedule from a `WeightInfo` implementation. #![allow(unused_parens)] +#![allow(clippy::assertions_on_constants)] use crate::{weights::WeightInfo, Config}; use core_processor::configs::PageCosts; diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index 5c7b29cb528..04b53592c18 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use crate::binaries::*; use crate::{ internal::HoldBoundBuilder, manager::HandleKind, @@ -14485,6 +14486,7 @@ mod utils { RuntimeOrigin, Test, }; use crate::{ + binaries::*, mock::{run_to_next_block, Balances, Gear, System, USER_1}, BalanceOf, BlockGasLimitOf, CurrencyOf, GasHandlerOf, GasInfo, GearBank, HandleKind, ProgramStorageOf, SentOf, diff --git a/runtime-interface/Cargo.toml b/runtime-interface/Cargo.toml index 20ebcae809c..644040fa765 100644 --- a/runtime-interface/Cargo.toml +++ b/runtime-interface/Cargo.toml @@ -23,6 +23,9 @@ byteorder.workspace = true codec = { workspace = true } log = { workspace = true, optional = true } +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +gear-runtime-interface-binaries = { path = "binaries", optional = true } + [target.'cfg(windows)'.dependencies] winapi = { workspace = true, features = ["memoryapi"] } @@ -42,3 +45,4 @@ std = [ "codec/std", "log", ] +runtime-benchmarks = ["gear-runtime-interface-binaries"] diff --git a/runtime-interface/binaries/Cargo.toml b/runtime-interface/binaries/Cargo.toml new file mode 100644 index 00000000000..fd689851861 --- /dev/null +++ b/runtime-interface/binaries/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "gear-runtime-interface-binaries" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[package.metadata.wasm-dep-builder.binaries] +include = ["demo-*", "test-syscalls"] + +[dependencies] +demo-delayed-sender.workspace = true +demo-reserve-gas.workspace = true +demo-read-big-state.workspace = true +demo-constructor.workspace = true +demo-waiter.workspace = true +demo-signal-entry.workspace = true +test-syscalls.workspace = true + +[build-dependencies] +wasm-dep-builder.workspace = true + +[features] +default = ["std"] +std = [ + "demo-delayed-sender/std", + "demo-reserve-gas/std", + "demo-read-big-state/std", + "demo-constructor/std", + "demo-waiter/std", + "demo-signal-entry/std", + "test-syscalls/std", +] +wasm-wrapper = [ + "demo-delayed-sender/wasm-wrapper", + "demo-reserve-gas/wasm-wrapper", + "demo-read-big-state/wasm-wrapper", + "demo-constructor/wasm-wrapper", + "demo-waiter/wasm-wrapper", + "demo-signal-entry/wasm-wrapper", + "test-syscalls/wasm-wrapper", +] diff --git a/runtime-interface/binaries/build.rs b/runtime-interface/binaries/build.rs new file mode 100644 index 00000000000..867b17139ce --- /dev/null +++ b/runtime-interface/binaries/build.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +fn main() { + wasm_dep_builder::build_binaries(); +} diff --git a/runtime-interface/binaries/src/lib.rs b/runtime-interface/binaries/src/lib.rs new file mode 100644 index 00000000000..821f2c85638 --- /dev/null +++ b/runtime-interface/binaries/src/lib.rs @@ -0,0 +1,21 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![no_std] + +include!(concat!(env!("OUT_DIR"), "/wasm_binaries.rs")); diff --git a/runtime-interface/src/lib.rs b/runtime-interface/src/lib.rs index 57150ddc21a..33cbbde5a9e 100644 --- a/runtime-interface/src/lib.rs +++ b/runtime-interface/src/lib.rs @@ -301,3 +301,41 @@ pub trait GearDebug { .as_nanos() } } + +#[cfg(feature = "runtime-benchmarks")] +#[derive(Debug, Clone, Copy, Encode, Decode, PartialEq, Eq)] +#[codec(crate = codec)] +#[repr(i64)] +pub enum WasmBinary { + DemoDelayedSender, + DemoReserveGas, + DemoReadBigState, + DemoConstructor, + DemoWaiter, + DemoSignalEntry, + TestSyscalls, +} + +#[cfg(feature = "runtime-benchmarks")] +impl PassBy for WasmBinary { + type PassBy = Codec; +} + +#[cfg(feature = "runtime-benchmarks")] +#[runtime_interface] +pub trait GearBenchmarks { + fn wasm_binary(binary: WasmBinary) -> Vec { + use gear_runtime_interface_binaries::*; + + match binary { + WasmBinary::DemoDelayedSender => demo_delayed_sender::WASM_BINARY, + WasmBinary::DemoReserveGas => demo_reserve_gas::WASM_BINARY, + WasmBinary::DemoReadBigState => demo_read_big_state::WASM_BINARY, + WasmBinary::DemoConstructor => demo_constructor::WASM_BINARY, + WasmBinary::DemoWaiter => demo_waiter::WASM_BINARY, + WasmBinary::DemoSignalEntry => demo_signal_entry::WASM_BINARY, + WasmBinary::TestSyscalls => test_syscalls::WASM_BINARY, + } + .to_vec() + } +} diff --git a/utils/wasm-dep-builder/Cargo.toml b/utils/wasm-dep-builder/Cargo.toml new file mode 100644 index 00000000000..3d51a13ced5 --- /dev/null +++ b/utils/wasm-dep-builder/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "wasm-dep-builder" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +cargo_metadata = "0.18.1" +gear-wasm-builder.workspace = true +serde_json.workspace = true +serde = { workspace = true, features = ["derive"] } +derive_more.workspace = true +fs4 = "0.7" +globset = { version = "0.4.14", features = ["serde1"] } +dirs.workspace = true +anyhow.workspace = true +filetime = "0.2.23" diff --git a/utils/wasm-dep-builder/src/builder.rs b/utils/wasm-dep-builder/src/builder.rs new file mode 100644 index 00000000000..a896a61f5ba --- /dev/null +++ b/utils/wasm-dep-builder/src/builder.rs @@ -0,0 +1,289 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{ + lock::{BinariesLockFileConfig, LockFileConfig, ProgramLockFileConfig}, + utils::{ + cargo_home_dir, crate_target_dir, get_no_build_env, get_no_path_remap_env, profile, + wasm32_target_dir, WASM32_TARGET, + }, + UnderscoreString, NO_BUILD_INNER_ENV, +}; +use anyhow::Context; +use cargo_metadata::Package; +use gear_wasm_builder::{ + optimize, + optimize::{OptType, Optimizer}, +}; +use std::{ + collections::BTreeSet, + env, fs, io, + io::Write, + path::{Path, PathBuf}, + process::Command, +}; + +const DEFAULT_EXCLUDED_FEATURES: [&str; 3] = ["default", "std", "wasm-wrapper"]; + +#[derive(Debug, Eq, PartialEq)] +enum RebuildKind { + Fresh, + Dirty, +} + +#[derive(Debug)] +pub struct BuildPackage { + name: UnderscoreString, + rebuild_kind: RebuildKind, + features: BTreeSet, + wasm_bloaty: PathBuf, + wasm: PathBuf, +} + +impl BuildPackage { + pub fn new(pkg: &Package, config: LockFileConfig, excluded_features: BTreeSet) -> Self { + let name = UnderscoreString(pkg.name.clone()); + let (rebuild_kind, features) = Self::resolve_features(pkg, config, excluded_features); + let (wasm_bloaty, wasm) = Self::wasm_paths(&name); + + Self { + name, + rebuild_kind, + features, + wasm_bloaty, + wasm, + } + } + + fn resolve_features( + pkg: &Package, + config: LockFileConfig, + excluded_features: BTreeSet, + ) -> (RebuildKind, BTreeSet) { + match config { + LockFileConfig::Program(ProgramLockFileConfig { features }) => { + // make full list of excluded features + let excluded_features = excluded_features + .into_iter() + .map(UnderscoreString) + .chain( + DEFAULT_EXCLUDED_FEATURES + .map(str::to_string) + .map(UnderscoreString), + ) + .collect(); + + // actually exclude features from list of enabled features + let features: BTreeSet = + features.difference(&excluded_features).cloned().collect(); + + // collect all of the features with their original names + let orig_features: BTreeSet = + pkg.features.keys().cloned().map(UnderscoreString).collect(); + + // get original names of enabled features + // because list is built from `CARGO_FEATURE_*` env vars (underscored names) + // in given config + let features: BTreeSet = orig_features + .intersection(&features) + .cloned() + .map(|s| s.0) + .collect(); + + // if config type is `Program` it's anyway has to be built + // because such config is written in case of any changes occurred + (RebuildKind::Dirty, features) + } + LockFileConfig::Binaries(BinariesLockFileConfig { features }) => { + // if config type is `Binaries` then no changes were made in program + // and builder have already done its job + (RebuildKind::Fresh, features) + } + } + } + + fn wasm_paths(name: &UnderscoreString) -> (PathBuf, PathBuf) { + let wasm32_target_dir = wasm32_target_dir().join(profile()); + let wasm_bloaty = wasm32_target_dir.join(format!("{name}.wasm")); + let mut wasm = wasm_bloaty.clone(); + wasm.set_extension("opt.wasm"); + (wasm_bloaty, wasm) + } + + pub fn name(&self) -> &UnderscoreString { + &self.name + } + + pub fn features(&self) -> &BTreeSet { + &self.features + } + + pub fn wasm_bloaty_path(&self) -> &Path { + self.wasm_bloaty.as_path() + } + + pub fn wasm_path(&self) -> &Path { + self.wasm.as_path() + } + + fn cargo_args(&self) -> impl Iterator { + let pkg_name = self.name.original().clone(); + let features = self + .features + .iter() + .map(|feature| format!("{pkg_name}/{feature}")) + .collect::>() + .join(","); + + [ + "--package".to_string(), + pkg_name, + "--features".to_string(), + features, + ] + .into_iter() + } + + fn optimize(&self) { + let (wasm_bloaty, wasm) = (&self.wasm_bloaty, &self.wasm); + + optimize::optimize_wasm(wasm_bloaty.clone(), wasm.clone(), "4", true) + .with_context(|| { + format!( + "failed to optimize {wasm_bloaty}", + wasm_bloaty = wasm_bloaty.display() + ) + }) + .unwrap(); + + let mut optimizer = Optimizer::new(wasm.clone()).unwrap(); + optimizer.insert_stack_end_export().unwrap_or_else(|err| { + println!( + "cargo:warning=Cannot insert stack end export into `{name}`: {err}", + name = self.name.original() + ) + }); + optimizer.strip_custom_sections(); + + let binary_opt = optimizer.optimize(OptType::Opt).unwrap(); + fs::write(wasm, binary_opt).unwrap(); + } +} + +#[derive(Debug)] +pub struct BuildPackages { + packages: Vec, + workspace_root: PathBuf, +} + +impl BuildPackages { + pub fn new(workspace_root: PathBuf) -> Self { + Self { + packages: Default::default(), + workspace_root, + } + } + + pub fn insert(&mut self, build_pkg: BuildPackage) { + self.packages.push(build_pkg); + } + + fn skip_build(&self) -> bool { + let any_dirty = self + .packages + .iter() + .any(|pkg| pkg.rebuild_kind == RebuildKind::Dirty); + + get_no_build_env() || !any_dirty + } + + fn cargo_args(&self) -> impl Iterator + '_ { + self.packages.iter().flat_map(BuildPackage::cargo_args) + } + + fn cargo_profile(&self) -> String { + let profile = profile(); + if profile == "debug" { + "dev".to_string() + } else { + profile + } + } + + fn cargo_config(&self) -> String { + let home_dir = dirs::home_dir() + .context("unable to get home directory") + .unwrap(); + + let cargo_dir = cargo_home_dir(); + let cargo_checkouts_dir = cargo_dir.join("git").join("checkouts"); + + let config = [ + (&home_dir, "/home"), + (&self.workspace_root, "/code"), + (&cargo_dir, "/cargo"), + (&cargo_checkouts_dir, "/deps"), + ] + .into_iter() + .map(|(from, to)| format!("--remap-path-prefix={from}={to}", from = from.display())) + .map(|flag| format!("\"{flag}\"")) + .collect::>() + .join(", "); + + // we set additional RUSTFLAGS via config because env vars reset flags we have in any `.cargo/config.toml` + format!("target.wasm32-unknown-unknown.rustflags=[{config}]") + } + + pub fn build(&mut self) -> bool { + if self.skip_build() { + return false; + } + + let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".into()); + let mut cargo = Command::new(cargo); + + if !get_no_path_remap_env() { + cargo.arg("--config").arg(self.cargo_config()); + } + + cargo + .arg("build") + .arg("--no-default-features") + .args(self.cargo_args()) + .arg("--profile") + .arg(self.cargo_profile()) + .env(NO_BUILD_INNER_ENV, "1") + .env("CARGO_BUILD_TARGET", WASM32_TARGET) + .env("CARGO_TARGET_DIR", crate_target_dir()) + // remove host flags + .env_remove("CARGO_ENCODED_RUSTFLAGS"); + let output = cargo.output().expect("Failed to execute cargo command"); + if !output.status.success() { + let _ = io::stderr().write_all(&output.stderr); + panic!("{}", output.status); + } + + for pkg in &mut self.packages { + if pkg.rebuild_kind == RebuildKind::Dirty { + pkg.optimize(); + } + } + + true + } +} diff --git a/utils/wasm-dep-builder/src/lib.rs b/utils/wasm-dep-builder/src/lib.rs new file mode 100644 index 00000000000..f05770f104e --- /dev/null +++ b/utils/wasm-dep-builder/src/lib.rs @@ -0,0 +1,249 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +mod builder; +mod lock; +mod metadata; +mod utils; + +use crate::{ + builder::{BuildPackage, BuildPackages}, + lock::{BinariesLockFile, BinariesLockFileConfig, ProgramLockFile, ProgramLockFileConfig}, + metadata::{BinariesMetadata, ProgramMetadata}, + utils::{ + default_wasm32_target_dir, get_no_build_env, get_no_build_inner_env, manifest_dir, out_dir, + profile, wasm32_target_dir, UnderscoreString, + }, +}; +use anyhow::Context; +use cargo_metadata::{camino::Utf8PathBuf, Metadata, MetadataCommand, Package}; +use std::{ + env, + fmt::Write, + fs, + path::{Path, PathBuf}, +}; + +const NO_BUILD_ENV: &str = "__GEAR_WASM_BUILDER_NO_BUILD"; + +/// [`track_program()`] must write config file anyway +/// except case where builder compiles program to WASM so +/// we don't want creation of garbage config files +/// because [`track_program()`] will be called again but in another environment +const NO_BUILD_INNER_ENV: &str = "__GEAR_WASM_BUILDER_NO_BUILD_INNER"; + +const NO_PATH_REMAP_ENV: &str = "__GEAR_WASM_BUILDER_NO_PATH_REMAP"; + +struct PostPackage { + name: UnderscoreString, + manifest_path: Utf8PathBuf, + wasm_bloaty: PathBuf, + wasm: PathBuf, +} + +impl PostPackage { + fn new(pkg: &Package, build_pkg: &BuildPackage) -> Self { + Self { + name: build_pkg.name().clone(), + manifest_path: pkg.manifest_path.clone(), + wasm_bloaty: build_pkg.wasm_bloaty_path().to_path_buf(), + wasm: build_pkg.wasm_path().to_path_buf(), + } + } + + fn copy_binaries(&self) { + let destination_dir = default_wasm32_target_dir().join(profile()); + let copy_binary = |binary: &PathBuf| { + let file_name = binary.file_name().unwrap(); + fs::copy(binary, destination_dir.join(file_name)).unwrap() + }; + + copy_binary(&self.wasm_bloaty); + copy_binary(&self.wasm); + } + + fn write_binpath(&self) { + let path = self + .manifest_path + .parent() + .expect("file path must have parent") + .join(".binpath"); + let contents = self.wasm_bloaty.with_extension("").display().to_string(); + fs::write(&path, contents) + .with_context(|| format!("failed to write `.binpath` at {path}")) + .unwrap(); + } + + fn write_wasm_binary(&self, wasm_binaries: &mut String) { + let pkg_name = &self.name; + let (wasm_bloaty, wasm) = if get_no_build_env() { + ("&[]".to_string(), "&[]".to_string()) + } else { + ( + format!(r#"include_bytes!("{}")"#, to_unix_path(&self.wasm_bloaty)), + format!(r#"include_bytes!("{}")"#, to_unix_path(&self.wasm)), + ) + }; + + let _ = write!( + wasm_binaries, + r#" +pub mod {pkg_name} {{ + #[allow(unused_imports)] + pub use ::{pkg_name}::*; + + pub const WASM_BINARY_BLOATY: &[u8] = {wasm_bloaty}; + pub const WASM_BINARY: &[u8] = {wasm}; +}} + "#, + ); + } +} + +fn to_unix_path(path: &Path) -> String { + // Windows uses `\\` path delimiter which cannot be used in `include_*` Rust macros + path.display().to_string().replace('\\', "/") +} + +fn find_pkg<'a>(metadata: &'a Metadata, pkg_name: &str) -> &'a Package { + metadata + .packages + .iter() + .find(|package| package.name == pkg_name) + .unwrap() +} + +/// Build Gear programs to WASM binaries. +/// +/// Collects every program by listing crate dependencies and +/// tracks changes via program lock file. +pub fn build_binaries() { + println!("cargo:rerun-if-env-changed={NO_BUILD_ENV}"); + println!("cargo:rerun-if-env-changed={NO_PATH_REMAP_ENV}"); + + let manifest_dir = manifest_dir(); + let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); + let out_dir = out_dir(); + + let wasm32_target_dir = wasm32_target_dir().join(profile()); + fs::create_dir_all(wasm32_target_dir).unwrap(); + + let build_rs = manifest_dir.join("build.rs"); + println!("cargo:rerun-if-changed={}", build_rs.display()); + // track if demo is being added or removed + let cargo_toml = manifest_dir.join("Cargo.toml"); + println!("cargo:rerun-if-changed={}", cargo_toml.display()); + + let metadata = MetadataCommand::new().no_deps().exec().unwrap(); + let pkg = find_pkg(&metadata, &pkg_name); + + let binaries_metadata = BinariesMetadata::from_value(pkg.metadata.clone()); + + let mut build_packages = + BuildPackages::new(metadata.workspace_root.clone().into_std_path_buf()); + let mut post_actions = Vec::new(); + + for dep in pkg + .dependencies + .iter() + .filter(|dep| binaries_metadata.filter_dep(&dep.name)) + { + let pkg = find_pkg(&metadata, &dep.name); + println!("cargo:rerun-if-changed={}", pkg.manifest_path); + + // check if demo has this crate as dependency + let contains = pkg + .dependencies + .iter() + .any(|dep| dep.name == env!("CARGO_PKG_NAME")); + if !contains { + println!( + "cargo:warning=`{}` doesn't have `wasm-dep-builder` dependency, skipping", + dep.name + ); + continue; + } + + let program_metadata = ProgramMetadata::from_value(pkg.metadata.clone()); + + let lock = lock::file_path(&dep.name); + println!("cargo:rerun-if-changed={}", lock.display()); + let mut lock = BinariesLockFile::open(&dep.name); + + let lock_config = lock.read_any(); + let build_pkg = BuildPackage::new(pkg, lock_config, program_metadata.exclude_features); + + let features = build_pkg.features().clone(); + post_actions.push(( + lock, + BinariesLockFileConfig { features }, + PostPackage::new(pkg, &build_pkg), + )); + + build_packages.insert(build_pkg); + } + + let packages_built = build_packages.build(); + + let mut wasm_binaries = String::new(); + for (mut lock, config, package) in post_actions { + if packages_built { + // we don't need to write config in lock file + // because we didn't build anything so next time when + // `__GEAR_WASM_BUILDER_NO_BUILD` is changed builder will mark + // crate as dirty and do an actual build + lock.write(config); + + // don't copy WASM binaries because we may not build them yet + package.copy_binaries(); + } + + package.write_binpath(); + package.write_wasm_binary(&mut wasm_binaries); + } + + fs::write(out_dir.join("wasm_binaries.rs"), wasm_binaries).unwrap(); +} + +/// Track Gear program to build. +/// +/// Never calls any `cargo:rerun-if` instructions to +/// keep default cargo build script invocation heuristics such as +/// tracking of every project file, its dependencies and features. +/// +/// On every build script invocation just writes config to lock file. +pub fn track_program() { + if get_no_build_inner_env() { + // we entered `wasm-dep-builder` + return; + } + + let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); + let wasm32_target_dir = wasm32_target_dir().join(profile()); + + fs::create_dir_all(wasm32_target_dir).unwrap(); + + let features = env::vars() + .filter_map(|(key, _val)| key.strip_prefix("CARGO_FEATURE_").map(str::to_lowercase)) + .map(UnderscoreString) + .collect(); + let config = ProgramLockFileConfig { features }; + + let mut lock = ProgramLockFile::open(pkg_name); + lock.write(config); +} diff --git a/utils/wasm-dep-builder/src/lock.rs b/utils/wasm-dep-builder/src/lock.rs new file mode 100644 index 00000000000..99c55daf09f --- /dev/null +++ b/utils/wasm-dep-builder/src/lock.rs @@ -0,0 +1,127 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{profile, wasm32_target_dir, UnderscoreString}; +use anyhow::Context; +use filetime::FileTime; +use fs4::FileExt; +use serde::{Deserialize, Serialize}; +use std::{ + collections::BTreeSet, + fs, + io::{Seek, SeekFrom}, + path::PathBuf, +}; + +pub fn file_path(pkg_name: impl AsRef) -> PathBuf { + let pkg_name = pkg_name.as_ref().replace('-', "_"); + wasm32_target_dir() + .join(profile()) + .join(format!("{}.lock", pkg_name)) +} + +fn truncate_file(file: &mut fs::File) { + file.set_len(0).unwrap(); + file.seek(SeekFrom::Start(0)).unwrap(); +} + +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, derive_more::Unwrap)] +#[serde(rename_all = "kebab-case")] +pub enum LockFileConfig { + Program(ProgramLockFileConfig), + Binaries(BinariesLockFileConfig), +} + +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ProgramLockFileConfig { + pub features: BTreeSet, +} + +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct BinariesLockFileConfig { + pub features: BTreeSet, +} + +#[derive(Debug)] +pub struct ProgramLockFile { + file: fs::File, +} + +impl ProgramLockFile { + pub fn open(pkg_name: impl AsRef) -> Self { + let path = file_path(pkg_name); + let file = fs::File::options() + .create(true) + .write(true) + // we don't care what is in file because point of `crate::track_program()` + // is just to write config to lock file on regular build script invocation + .truncate(true) + .open(path) + .unwrap(); + file.lock_exclusive().unwrap(); + + Self { file } + } + + pub fn write(&mut self, config: ProgramLockFileConfig) { + serde_json::to_writer(&mut self.file, &LockFileConfig::Program(config)).unwrap(); + } +} + +#[derive(Debug)] +pub struct BinariesLockFile { + file: fs::File, +} + +impl BinariesLockFile { + pub fn open(pkg_name: impl AsRef) -> Self { + let path = file_path(pkg_name); + let file = fs::File::options() + // we never create file because it means `crate::track_program()` was never called + // so project structure is corrupted + .write(true) + .read(true) + .open(&path) + .with_context(|| { + format!( + "failed to open lock file in binaries builder, path: {}", + path.display() + ) + }) + .unwrap(); + file.lock_exclusive().unwrap(); + + Self { file } + } + + pub fn read_any(&mut self) -> LockFileConfig { + serde_json::from_reader(&mut self.file).unwrap() + } + + pub fn write(&mut self, config: BinariesLockFileConfig) { + truncate_file(&mut self.file); + serde_json::to_writer(&mut self.file, &LockFileConfig::Binaries(config)).unwrap(); + } +} + +impl Drop for BinariesLockFile { + fn drop(&mut self) { + // set mtime to zero so cargo won't rerun `crate::build_binaries()` yet again + filetime::set_file_handle_times(&self.file, None, Some(FileTime::zero())).unwrap(); + } +} diff --git a/utils/wasm-dep-builder/src/metadata.rs b/utils/wasm-dep-builder/src/metadata.rs new file mode 100644 index 00000000000..948b3255455 --- /dev/null +++ b/utils/wasm-dep-builder/src/metadata.rs @@ -0,0 +1,87 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use globset::{Glob, GlobSet}; +use serde::Deserialize; +use std::collections::BTreeSet; + +#[derive(Deserialize, derive_more::Unwrap)] +#[serde(rename_all = "kebab-case")] +enum CrateMetadata { + Program(ProgramMetadata), + Binaries(BinariesMetadata), +} + +impl CrateMetadata { + fn from_value(mut value: serde_json::Value) -> Option { + let value = value.get_mut(env!("CARGO_PKG_NAME"))?.take(); + Some(serde_json::from_value::(value).unwrap()) + } +} + +#[derive(Default, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct ProgramMetadata { + #[serde(default)] + pub exclude_features: BTreeSet, +} + +impl ProgramMetadata { + pub fn from_value(value: serde_json::Value) -> Self { + CrateMetadata::from_value(value) + .map(|metadata| metadata.unwrap_program()) + .unwrap_or_default() + } +} + +#[derive(Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct BinariesMetadata { + #[serde(default = "BinariesMetadata::default_include")] + include: GlobSet, + #[serde(default)] + exclude: BTreeSet, +} + +impl Default for BinariesMetadata { + fn default() -> Self { + Self { + include: Self::default_include(), + exclude: Default::default(), + } + } +} + +impl BinariesMetadata { + pub fn from_value(value: serde_json::Value) -> Self { + CrateMetadata::from_value(value) + .map(|metadata| metadata.unwrap_binaries()) + .unwrap_or_default() + } + + fn default_include() -> GlobSet { + GlobSet::builder() + .add(Glob::new("demo-*").unwrap()) + .build() + .unwrap() + } + + pub fn filter_dep(&self, pkg_name: &str) -> bool { + !self.exclude.contains(pkg_name) && self.include.is_match(pkg_name) + } +} diff --git a/utils/wasm-dep-builder/src/utils.rs b/utils/wasm-dep-builder/src/utils.rs new file mode 100644 index 00000000000..6fb2b043cc6 --- /dev/null +++ b/utils/wasm-dep-builder/src/utils.rs @@ -0,0 +1,141 @@ +// This file is part of Gear. +// +// Copyright (C) 2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{NO_BUILD_ENV, NO_BUILD_INNER_ENV, NO_PATH_REMAP_ENV}; +use serde::{Deserialize, Serialize}; +use std::{cmp::Ordering, env, fmt, path::PathBuf}; + +pub const WASM32_TARGET: &str = "wasm32-unknown-unknown"; + +pub fn manifest_dir() -> PathBuf { + env::var("CARGO_MANIFEST_DIR").unwrap().into() +} + +pub fn out_dir() -> PathBuf { + env::var("OUT_DIR").unwrap().into() +} + +pub fn profile() -> String { + out_dir() + .components() + .rev() + .take_while(|c| c.as_os_str() != "target") + .collect::>() + .into_iter() + .rev() + .take_while(|c| c.as_os_str() != "build") + .last() + .expect("Path should have subdirs in the `target` dir") + .as_os_str() + .to_string_lossy() + .into() +} + +fn target_dir() -> PathBuf { + let profile = profile(); + + out_dir() + .ancestors() + .find(|path| path.ends_with(&profile)) + .and_then(|path| path.parent()) + .map(|p| p.to_owned()) + .expect("Could not find target directory") +} + +/// `target/wasm32-unknown-unknown` +pub fn default_wasm32_target_dir() -> PathBuf { + target_dir().join(WASM32_TARGET) +} + +/// `target/wasm-dep-builder` +pub fn crate_target_dir() -> PathBuf { + target_dir().join(env!("CARGO_PKG_NAME")) +} + +/// `target/wasm-dep-builder/wasm32-unknown-unknown` +pub fn wasm32_target_dir() -> PathBuf { + crate_target_dir().join(WASM32_TARGET) +} + +pub fn cargo_home_dir() -> PathBuf { + env::var("CARGO_HOME").unwrap().into() +} + +pub fn get_no_build_env() -> bool { + env::var(NO_BUILD_ENV).is_ok() +} + +pub fn get_no_build_inner_env() -> bool { + env::var(NO_BUILD_INNER_ENV).is_ok() +} + +pub fn get_no_path_remap_env() -> bool { + env::var(NO_PATH_REMAP_ENV).is_ok() +} + +#[derive(Clone, Serialize, Deserialize)] +#[serde(transparent)] +pub struct UnderscoreString(pub String); + +impl UnderscoreString { + pub fn original(&self) -> &String { + &self.0 + } + + fn underscore(&self) -> String { + self.0.replace('-', "_") + } +} + +impl> From for UnderscoreString { + fn from(s: T) -> Self { + Self(s.into()) + } +} + +impl fmt::Display for UnderscoreString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.underscore(), f) + } +} + +impl fmt::Debug for UnderscoreString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.0, f) + } +} + +impl PartialEq for UnderscoreString { + fn eq(&self, other: &Self) -> bool { + self.underscore() == other.underscore() + } +} + +impl Eq for UnderscoreString {} + +impl PartialOrd for UnderscoreString { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for UnderscoreString { + fn cmp(&self, other: &Self) -> Ordering { + self.underscore().cmp(&other.underscore()) + } +}