Skip to content

Ar/cor 2473 implement a default allocator for concordium std on wasm32 - #478

Merged
allanbrondum merged 9 commits into
feature/wasm32v1from
ar/cor-2473-implement-a-default-allocator-for-concordium-std-on-wasm32
Aug 20, 2026
Merged

Ar/cor 2473 implement a default allocator for concordium std on wasm32#478
allanbrondum merged 9 commits into
feature/wasm32v1from
ar/cor-2473-implement-a-default-allocator-for-concordium-std-on-wasm32

Conversation

@allanbrondum

@allanbrondum allanbrondum commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Purpose

Set dlmalloc as the default allocator. It was default when compiling to https://doc.rust-lang.org/rustc/platform-support/wasm32-unknown-unknown.html with std library.

Changes

  • dlmalloc is default
  • bump_alloc feature enabled bump_alloc
  • global_alloc is default and sets the global allocator
  • updated concordium_std lib.rs docs for this change and the previous changes for wasm32v1 feature
  • moved running internal wasm tests to concordium-std-internal-test, since it requires the cdylib crate type, which cannot be applied to concordium-std if it must be compilable without the global_alloc feature

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

@allanbrondum
allanbrondum changed the base branch from main to ar/cor-2467-make-concordium-std-compile-with-wasm32v1 August 10, 2026 14:31
Comment thread concordium-std/Cargo.toml Outdated
Comment thread concordium-std/src/lib.rs
//! contracts. For this reason it re-exports a number of definitions from other
//! libraries.
//!
//! # Versions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to the end of the documentation

Base automatically changed from ar/cor-2467-make-concordium-std-compile-with-wasm32v1 to feature/wasm32v1 August 12, 2026 07:54
Comment thread concordium-cis2/Cargo.toml
Comment thread concordium-std/Cargo.toml Outdated
Comment thread concordium-std/Cargo.toml
…ust-smart-contracts into ar/cor-2473-implement-a-default-allocator-for-concordium-std-on-wasm32
Comment thread concordium-std/Cargo.toml Outdated
# cdylib is needed below to compile into a wasm module with internal unit tests.
crate-type = ["cdylib", "rlib"]
# Set a global allocator. Otherwise, it must be set in smart contract.
global_alloc = []

@limemloh limemloh Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure when this feature is useful? Would the user ever want to disable default features and then enable just global_alloc alone? or any of the allocators without having global_alloc as well?
To me there seems to be 3 choices,

  • none of the allocators enabled (disable default features)
  • dlmalloc
  • bump_alloc

@allanbrondum allanbrondum Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The combination I thought of was enabling bump_alloc but wanting to set it as global allocator yourself. The features dlmalloc and bump_alloc are truly additive, the global_alloc feature is not really additive (https://doc.rust-lang.org/cargo/reference/features.html#feature-unification). That can especially be relevant if you have several smart contracts in the same workspace. But it may be simpler not to have the feaute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed global_alloc feature, bump_alloc module is now compiled on WASM32 unconditionally

@allanbrondum
allanbrondum merged commit 3d5d715 into feature/wasm32v1 Aug 20, 2026
12 checks passed
@allanbrondum
allanbrondum deleted the ar/cor-2473-implement-a-default-allocator-for-concordium-std-on-wasm32 branch August 20, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants