Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Only use substrate-wasm-builder when std feature is enabled. #12790

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, p
pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder", optional = true }

[features]
default = ["std"]
Expand Down Expand Up @@ -86,6 +86,7 @@ std = [
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
"substrate-wasm-builder",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
15 changes: 8 additions & 7 deletions bin/node-template/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}
}
3 changes: 2 additions & 1 deletion bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pallet-vesting = { version = "4.0.0-dev", default-features = false, path = "../.
pallet-whitelist = { version = "4.0.0-dev", default-features = false, path = "../../../frame/whitelist" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder", optional = true }

[features]
default = ["std"]
Expand Down Expand Up @@ -202,6 +202,7 @@ std = [
"sp-io/std",
"pallet-child-bounties/std",
"pallet-alliance/std",
"substrate-wasm-builder",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
15 changes: 8 additions & 7 deletions bin/node/runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}
}
3 changes: 2 additions & 1 deletion client/executor/runtime-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sp-sandbox = { version = "0.10.0-dev", default-features = false, path = "../../.
sp-std = { version = "5.0.0", default-features = false, path = "../../../primitives/std" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder", optional = true }

[features]
default = ["std"]
Expand All @@ -31,4 +31,5 @@ std = [
"sp-runtime/std",
"sp-sandbox/std",
"sp-std/std",
"substrate-wasm-builder",
]
32 changes: 18 additions & 14 deletions client/executor/runtime-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use substrate_wasm_builder::WasmBuilder;

fn main() {
// regular build
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}

// and building with tracing activated
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.set_file_name("wasm_binary_with_tracing.rs")
.append_to_rust_flags(r#"--cfg feature="with-tracing""#)
.build();
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.set_file_name("wasm_binary_with_tracing.rs")
.append_to_rust_flags(r#"--cfg feature="with-tracing""#)
.build();
}
}
10 changes: 8 additions & 2 deletions primitives/runtime-interface/test-wasm-deprecated/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ sp-runtime-interface = { version = "7.0.0", default-features = false, path = "..
sp-std = { version = "5.0.0", default-features = false, path = "../../std" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder", optional = true }

[features]
default = [ "std" ]
std = [ "sp-core/std", "sp-io/std", "sp-runtime-interface/std", "sp-std/std" ]
std = [
"sp-core/std",
"sp-io/std",
"sp-runtime-interface/std",
"sp-std/std",
"substrate-wasm-builder",
]
15 changes: 8 additions & 7 deletions primitives/runtime-interface/test-wasm-deprecated/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}
}
10 changes: 8 additions & 2 deletions primitives/runtime-interface/test-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ sp-runtime-interface = { version = "7.0.0", default-features = false, path = "..
sp-std = { version = "5.0.0", default-features = false, path = "../../std" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder", optional = true }

[features]
default = [ "std" ]
std = [ "sp-core/std", "sp-io/std", "sp-runtime-interface/std", "sp-std/std" ]
std = [
"sp-core/std",
"sp-io/std",
"sp-runtime-interface/std",
"sp-std/std",
"substrate-wasm-builder",
]
15 changes: 8 additions & 7 deletions primitives/runtime-interface/test-wasm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}
}
3 changes: 2 additions & 1 deletion test-utils/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ substrate-test-runtime-client = { version = "2.0.0", path = "./client" }
futures = "0.3.21"

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../utils/wasm-builder" }
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../utils/wasm-builder", optional = true }

[features]
default = [
Expand Down Expand Up @@ -103,6 +103,7 @@ std = [
"sp-trie/std",
"sp-transaction-pool/std",
"trie-db/std",
"substrate-wasm-builder",
]
# Special feature to disable logging
disable-logging = [ "sp-api/disable-logging" ]
40 changes: 22 additions & 18 deletions test-utils/runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
// Note that we set the stack-size to 1MB explicitly even though it is set
// to this value by default. This is because some of our tests (`restoration_of_globals`)
// depend on the stack-size.
.append_to_rust_flags("-Clink-arg=-zstack-size=1048576")
.import_memory()
.build();
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
// Note that we set the stack-size to 1MB explicitly even though it is set
// to this value by default. This is because some of our tests
// (`restoration_of_globals`) depend on the stack-size.
.append_to_rust_flags("-Clink-arg=-zstack-size=1048576")
.import_memory()
.build();
}

WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.set_file_name("wasm_binary_logging_disabled.rs")
.enable_feature("disable-logging")
.build();
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.set_file_name("wasm_binary_logging_disabled.rs")
.enable_feature("disable-logging")
.build();
}
}
25 changes: 13 additions & 12 deletions utils/wasm-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ The Wasm builder is a tool that integrates the process of building the WASM bina
A project that should be compiled as a Wasm binary needs to:

1. Add a `build.rs` file.
2. Add `wasm-builder` as dependency into `build-dependencies`.
2. Add `wasm-builder` as dependency into `build-dependencies` (can be made optional and only enabled when `std` feature is used).

The `build.rs` file needs to contain the following code:

```rust
use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
// Tell the builder to build the project (crate) this `build.rs` is part of.
.with_current_project()
// Make sure to export the `heap_base` global, this is required by Substrate
.export_heap_base()
// Build the Wasm file so that it imports the memory (need to be provided by at instantiation)
.import_memory()
// Build it.
.build()
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
// Tell the builder to build the project (crate) this `build.rs` is part of.
.with_current_project()
// Make sure to export the `heap_base` global, this is required by Substrate
.export_heap_base()
// Build the Wasm file so that it imports the memory (need to be provided by at instantiation)
.import_memory()
// Build it.
.build();
}
}
```

Expand Down