`cabi_realloc` is referenced but never linked on `wasm32-unknown-emscripten`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust, wasm
- 領域
- build-system
調査の方向性
Start in crates/guest-rust/build.rs, where the CARGO_CFG_TARGET_FAMILY comparison fails on unix,wasm, and then check the matching cfg in src/rt/mod.rs (maybe_link_cabi_realloc). Reproduce with cargo build --release --target wasm32-unknown-emscripten on a staticlib that depends on wit-bindgen. Done when that build links, the two checks agree on whether Emscripten is included, and the other wasm and Linux targets build as before.
索引モデルが issue の本文から書いたものです。
説明
crates/guest-rust/build.rs (still the case in v0.63.0) decides whether to link the cabi_realloc shim with:
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or(String::new());
if target_family != "wasm" {
return;
}
Cargo joins a cfg with several values with commas. wasm32-unknown-emscripten is the one wasm target with two families, so CARGO_CFG_TARGET_FAMILY is unix,wasm there, the comparison fails, and the build script returns before linking anything.
The crate's own Rust cfgs disagree with it. In src/rt/mod.rs, maybe_link_cabi_realloc references cabi_realloc under #[cfg(all(target_family = "wasm", any(target_env = "p1", target_env = "")))], and cfg(target_family = "wasm") is true on Emscripten, whose target_env is "". So the symbol is referenced but never provided. Any static library built on wit-bindgen for Emscripten then fails its final emcc link.
Reproduction (wit-bindgen 0.63.0, Rust 1.98.0, Emscripten 6.0.12):
# Cargo.toml
[lib]
crate-type = ["staticlib"]
[dependencies]
wit-bindgen = "=0.63.0"
// src/lib.rs, with wit/w.wit = `package repro:w; world w { export greet: func(name: string) -> string; }`
wit_bindgen::generate!({ world: "w", path: "wit" });
struct C;
impl Guest for C { fn greet(name: String) -> String { format!("hi {name}") } }
export!(C);
#[unsafe(no_mangle)]
pub extern "C" fn answer() -> i32 { 42 }
cargo build --release --target wasm32-unknown-emscripten
emcc main.c target/wasm32-unknown-emscripten/release/libwbrepro.a -o m.js
# wasm-ld: error: …wit_bindgen….rcgu.o: undefined symbol: cabi_realloc
(main.c calls answer().)
Fix: read the family as a list.
if !target_family.split(',').any(|f| f == "wasm") {
return;
}
With this patched in through [patch.crates-io], the reproduction links and runs under node. Builds for wasm32-unknown-unknown, wasm32-wasip2 and x86_64-unknown-linux-gnu are unaffected; Emscripten is the only target whose family list differs.
The check dates from #851, where it reads as "any wasm target", with a panic for wasm architectures other than wasm32. I found nothing suggesting Emscripten was meant to be excluded. If it was, the cfgs in rt/mod.rs would need to exclude it too, so as it stands the two halves disagree either way.
Context: we hit this building a C ABI whose types come from wit-bindgen-generated bindings, for hosts that compile to the browser with Emscripten. We work around it with a #[no_mangle] extern "C" fn cabi_realloc on Emscripten that forwards to wit_bindgen::rt::cabi_realloc.
- 主要言語
- Rust
- スター
- 1.5k
- フォーク
- 306
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 21
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytecodealliance/wit-bindgen のほかの issue
-
gen-rust
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
bytecodealliance/wit-bindgen#1791 ·
メンテナーはふだん 1 日以内に返信
-
gen-rust
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
bytecodealliance/wit-bindgen#1790 ·
メンテナーはふだん 1 日以内に返信
-
gen-rust
難易度 3/5 半日 初心者へのやさしさ 55/100
bytecodealliance/wit-bindgen#1787 ·
メンテナーはふだん 1 日以内に返信
-
gen-c#
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
bytecodealliance/wit-bindgen#1759 ·
メンテナーはふだん 1 日以内に返信
-
Async exports never free the block of indirect parameters対応中かも @Aditya1404Sal が 37 日前に担当しました。 オープンasync
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
bytecodealliance/wit-bindgen#1757 ·
メンテナーはふだん 1 日以内に返信
bytecodealliance/wit-bindgen の issue をすべて見る
似ている issue
-
lane:collections todo:ticket
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 3 日以内に返信
-
bugfix
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
storytold/designcraft#3662 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
good first issue tooling
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Nixitov/Riptide-Native#521 ·
メンテナーはふだん 1 日以内に返信