cbcl-wasm: fix unresolved allocator imports for cdylib host loading #6

Merged
hugooconnor merged 0 commits from refs/pull/6/head into main 2026-04-30 05:28:10 +00:00
hugooconnor commented 2026-04-30 03:48:47 +00:00 (Migrated from codeberg.org)

Summary

  • Replaces the broken hand-rolled WasmAlloc shim (which declared __rust_alloc / __rust_dealloc as externs that the cdylib compiler never generates) with dlmalloc::GlobalDlmalloc. The previous code produced a wasm binary with two unresolved env::__rust_* imports, so any non-JS host (wasmtime, etc.) refused to instantiate it. wasm-bindgen builds masked the issue for browsers; the C-ABI path was effectively unreachable.
  • Imports alloc::string::ToString in cbcl-parser/src/protocol_parser.rs. Without it, --no-default-features builds fail with to_string not found on &str and the wasm32 build never completes.

Test plan

  • cargo build --target wasm32-unknown-unknown --no-default-features -p cbcl-wasm --release succeeds (warnings only).
  • Resulting cbcl_wasm.wasm lists cbcl_alloc / cbcl_free / cbcl_parse_message / cbcl_run_pipeline / cbcl_verify_dialect / cbcl_verify_message_shape / cbcl_verify_protocol as exports and has no unresolved imports.
  • Loaded under wasmtime: cbcl_parse_message, cbcl_verify_message_shape, cbcl_verify_protocol all return correct results on the lib.rs unit-test fixtures (SHAPE_DIALECT, PROTOCOL_DIALECT).
  • cargo test --workspace should be re-run on CI; the fix is gated to wasm32-unknown-unknown cdylib so std-feature unit tests are unaffected, but worth confirming.

🤖 Generated with Claude Code

## Summary - Replaces the broken hand-rolled `WasmAlloc` shim (which declared `__rust_alloc` / `__rust_dealloc` as externs that the cdylib compiler never generates) with `dlmalloc::GlobalDlmalloc`. The previous code produced a wasm binary with two unresolved `env::__rust_*` imports, so any non-JS host (wasmtime, etc.) refused to instantiate it. wasm-bindgen builds masked the issue for browsers; the C-ABI path was effectively unreachable. - Imports `alloc::string::ToString` in `cbcl-parser/src/protocol_parser.rs`. Without it, `--no-default-features` builds fail with `to_string` not found on `&str` and the wasm32 build never completes. ## Test plan - [x] `cargo build --target wasm32-unknown-unknown --no-default-features -p cbcl-wasm --release` succeeds (warnings only). - [x] Resulting `cbcl_wasm.wasm` lists `cbcl_alloc / cbcl_free / cbcl_parse_message / cbcl_run_pipeline / cbcl_verify_dialect / cbcl_verify_message_shape / cbcl_verify_protocol` as exports and has no unresolved imports. - [x] Loaded under wasmtime: `cbcl_parse_message`, `cbcl_verify_message_shape`, `cbcl_verify_protocol` all return correct results on the lib.rs unit-test fixtures (`SHAPE_DIALECT`, `PROTOCOL_DIALECT`). - [ ] `cargo test --workspace` should be re-run on CI; the fix is gated to `wasm32-unknown-unknown` cdylib so std-feature unit tests are unaffected, but worth confirming. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hugooconnor commented 2026-04-30 04:19:54 +00:00 (Migrated from codeberg.org)

Addressed in 21ca834: widened the Cargo target dep cfg to all target_arch = "wasm32" so it is a strict superset of where the source's #[global_allocator] activates. Cargo target cfgs can't reference features, so this is the closest expressible match.

Verified cargo build --target wasm32-wasip1 --no-default-features -p cbcl-wasm --release now builds (it was the failure mode you flagged). wasm32-unknown-unknown still builds and cargo test -p cbcl-wasm is still 62/62 on native. Cargo.lock is unchanged.

Addressed in 21ca834: widened the Cargo target dep cfg to all `target_arch = "wasm32"` so it is a strict superset of where the source's `#[global_allocator]` activates. Cargo target cfgs can't reference features, so this is the closest expressible match. Verified `cargo build --target wasm32-wasip1 --no-default-features -p cbcl-wasm --release` now builds (it was the failure mode you flagged). `wasm32-unknown-unknown` still builds and `cargo test -p cbcl-wasm` is still 62/62 on native. `Cargo.lock` is unchanged.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
anuna-research/cbcl-rs!6
No description provided.