Skip to content

Commit 3d5d715

Browse files
authored
Merge pull request #478 from Concordium/ar/cor-2473-implement-a-default-allocator-for-concordium-std-on-wasm32
Ar/cor 2473 implement a default allocator for concordium std on wasm32
2 parents 1bb0dc1 + 3b992f2 commit 3d5d715

9 files changed

Lines changed: 140 additions & 125 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ jobs:
7676
with:
7777
submodules: recursive
7878
- name: Run internal wasm unit test
79-
working-directory: concordium-std
79+
working-directory: concordium-std-internal-test
8080
run: |
8181
# curl -L https://github.com/Concordium/concordium-smart-contract-tools/releases/download/releases/cargo-concordium/${CARGO_CONCORDIUM_VERSION}/cargo-concordium-linux-amd64 -o /tmp/cargo-concordium
8282
# chmod +x /tmp/cargo-concordium
8383
# sudo mv /tmp/cargo-concordium /usr/bin/cargo-concordium
8484
# todo change to use release as part of https://linear.app/concordium/issue/COR-2479/release-for-wasm32v1
8585
rustup target add wasm32v1-none
8686
cargo install --git https://github.com/Concordium/concordium-smart-contract-tools.git --branch feature/wasm32v1 --locked
87-
cargo concordium test --only-unit-tests -- --features internal-wasm-test
87+
cargo concordium test --only-unit-tests
8888
8989
std_clippy_wasm32v1:
9090
name: Clippy on concordium-std for wasm32v1 target
@@ -99,7 +99,7 @@ jobs:
9999
run: |
100100
rustup component add clippy
101101
rustup target add wasm32v1-none
102-
cargo clippy --target wasm32v1-none -- -D warnings
102+
cargo clippy --target wasm32v1-none --features wasm-test,build-schema,bump_alloc,debug -- -D warnings
103103
104104
std_check:
105105
name: Check on concordium-std for x64 and wasm32 and different features
@@ -113,11 +113,15 @@ jobs:
113113
working-directory: concordium-std
114114
run: |
115115
# Try different feature combinations on default (x86 linux) target
116+
cargo check --no-default-features
116117
cargo check
117118
118119
# Try different feature combinations on wasm32v1 target
119120
rustup target add wasm32v1-none
120-
cargo check --target wasm32v1-none
121+
cargo check --target wasm32v1-none --no-default-features
122+
cargo check --target wasm32v1-none --no-default-features --features bump_alloc
123+
cargo check --target wasm32v1-none --no-default-features --features dlmalloc
124+
cargo check --target wasm32v1-none
121125
cargo check --target wasm32v1-none --features wasm-test
122126
cargo check --target wasm32v1-none --features build-schema
123127
cargo check --target wasm32v1-none --features bump_alloc

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ resolver = "3"
44
members = [
55
"concordium-cis2",
66
"concordium-std",
7+
"concordium-std-internal-test",
78
"concordium-std-derive",
89
"contract-testing",
910
]

concordium-cis2/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ serde = [
3838
"primitive-types/impl-serde",
3939
]
4040

41-
[lib]
42-
crate-type = ["rlib"]
43-
4441
[package.metadata.docs.rs]
45-
# This sets the default target to `wasm32-unknown-unknown` and only builds that
42+
# This sets the default target to `wasm32v1-none` and only builds that
4643
# target on docs.rs. This is useful because the some parts of documentation only
4744
# exist on that platform.
4845
targets = ["wasm32v1-none"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "concordium-std-internal-test"
3+
version = "1.0.0"
4+
authors = ["Concordium <developers@concordium.com>"]
5+
edition = "2024"
6+
rust-version = "1.85"
7+
license = "MPL-2.0"
8+
9+
[dependencies]
10+
concordium-std = { path = "../concordium-std", features = ["internal-wasm-test", "wasm-test"]}
11+
12+
[lib]
13+
crate-type = ["cdylib", "rlib"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Crate whose only purpose is to build the internal tests in `concordium-std` into a WASM file, such that they can
2+
be run by `cargo concoridum test`.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![no_std]
2+
3+
extern crate concordium_std;

concordium-std/CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
## Unreleased
44

55
- Removed the native test `StateTrie`
6-
- The crate now targets [`wasm32v1-none`](https://doc.rust-lang.org/rustc/platform-support/wasm32v1-none.html) as the supported WASM target. The crate also no longer has an `std` crate feature.
7-
Smart contracts using `concordium-std` should specify `#[no_std]` and compile to `wasm32v1-none`.
8-
The `concordium-std` crate still supports compiling to targets like x86 linux (for unit testing e.g.), in which case the crate will add the Rust `std` crate as a dependency.
6+
- The crate is now intended for use on the [`wasm32v1-none`](https://doc.rust-lang.org/rustc/platform-support/wasm32v1-none.html) target, which is a `no_std` target.
7+
Smart contracts using `concordium-std` should specify `#[no_std]` and compile to the target `wasm32v1-none`. The previously supported target `wasm32-unknown-unknown`
8+
(which has a partly stubbed `std` implementation) is no longer supported with `concordium-std`. The crate feature `std` has likewise been removed.
9+
The allocator used by default by `concordium-std` is [`dlmalloc`](https://crates.io/crates/dlmalloc). The crate feature `bump_alloc`
10+
will switch to use the custom, lightweight `bump_alloc` allocator.
11+
Notice that `dlmalloc` is the same as used by the `std` implementation of `wasm32-unknown-unknown`.
12+
The `concordium-std` crate still supports compiling to targets like x64 linux (for unit testing e.g.), in which case the crate will add the Rust `std` crate as a dependency.
913
- The crate feature `p7` has been removed. The functionality it guarded (related to protocol P7) is unconditionally compiled.
1014
- The crate feature `crypto-primitives` has been removed. It had no effect anymore (was previously used by the now deprecated test infrastructure).
1115
- The types `StateMap` and `StateSet` and related types no longer requires the low-level state type to be specified.

concordium-std/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository = "https://github.com/Concordium/concordium-rust-smart-contracts/"
1111
readme = "./README.md"
1212

1313
[dependencies]
14+
dlmalloc = { version = "0.2.14", features = ["global"], optional = true }
1415
quickcheck = {version = "1", optional = true }
1516
getrandom = { version = "0.2", features = ["custom"], optional = true }
1617

@@ -21,7 +22,7 @@ default-features = false
2122
features = ["smart-contract"]
2223

2324
[features]
24-
default = ["bump_alloc"]
25+
default = ["dlmalloc"]
2526
# Enabling the wasm-test feature changes the #[concoridum_test] macro to output test functions callable from WASM interpreter
2627
wasm-test = ["concordium-contracts-common/wasm-test"]
2728
# Own internal wasm-tests leak out to the smart contracts using this library,
@@ -33,13 +34,11 @@ build-schema = ["concordium-contracts-common/build-schema"]
3334
concordium-quickcheck = ["getrandom", "quickcheck", "concordium-contracts-common/concordium-quickcheck"] # // decide what to do with this feature flag as part of https://linear.app/concordium/issue/COR-2474/property-based-tests-on-wasm32-target
3435
# Enabling debug feature changes the #[concoridum_dbg] macro to log messages via the WASM interpreter
3536
debug = []
36-
# Custom allocator. See module documentation for bump_alloc in this crate
37+
# Use the dlmalloc allocator
38+
dlmalloc = ["dep:dlmalloc"]
39+
# Use the custom bump allocator instead of dlmalloc. See module documentation for bump_alloc in this crate.
3740
bump_alloc = []
3841

39-
[lib]
40-
# cdylib is needed below to compile into a wasm module with internal unit tests.
41-
crate-type = ["cdylib", "rlib"]
42-
4342
[dev-dependencies]
4443
trybuild = "1.0"
4544

@@ -48,3 +47,5 @@ trybuild = "1.0"
4847
# target on docs.rs. This is useful because the some parts of documentation only
4948
# exist on that platform.
5049
targets = ["wasm32v1-none"]
50+
# Default features to build documentation for.
51+
features = ["debug"]

0 commit comments

Comments
 (0)