Skip to content

feat(rust): support native symbol linking and import resolution - #1786

Merged
alexcrichton merged 9 commits into
bytecodealliance:mainfrom
Snowiiii:feat/rust-native-symbols
Nov 16, 2026
Merged

alexcrichton merged 9 commits into
bytecodealliance:mainfrom
Snowiiii:feat/rust-native-symbols

Conversation

@Snowiiii

Copy link
Copy Markdown
Contributor

Picks up #1685 (with @BjornTheProgrammer's permission) to address #1062, rebased onto main with review feedback addressed:

  • Export #[doc(hidden)] rt::extern_wasm! and use it across codegen and async_support, moving fast/cold AtomicPtr caching into rt::resolve_import.
  • Replace #[no_mangle] C hooks with a lock-synchronized &str-based rt::register_import_resolver (no_std wasip3_task_set also routes through extern_wasm!).
  • Return wit_component::metadata::encode world bytes from __wit_bindgen_world_<world> instead of just the world name.
  • Switch target_arch = "wasm32" gates to target_family = "wasm", move detailed native ABI docs to crates/guest-rust/NATIVE.md, and drop the separate native-e2e subcrate in favor of codegen.rs + native_imports unit tests.

Comment thread crates/rust/tests/codegen.rs Outdated
Comment on lines +27 to +30
// A different package from `multiple_paths` above. Two different
// worlds under one name corrupt each other's `component-type` sections
// on wasm, and collide on the world marker symbol natively. So this
// technically is a fix to the existing tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's ok to drop this comment and just have the update inline

Comment thread crates/rust/tests/codegen.rs Outdated
assert_ne!(r0.1, r1.1, "each thread should have its own _RET_AREA");
assert_eq!(r0.2, "111");
assert_eq!(r1.2, "222222");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor comment, but could the native-related tests move to a separate tests/native.rs to keep things separated?

Comment thread crates/rust/src/interface.rs Outdated
Comment on lines +453 to +458
{native_cfg}
::std::thread_local! {{
static _RET_AREA: ::core::cell::UnsafeCell<_RetArea> = const {{
::core::cell::UnsafeCell::new(_RetArea([::core::mem::MaybeUninit::uninit(); {size}]))
}};
}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar to above with locks, I'm skeptical use the usefulnes of no-std native support here. Compiling for no_std doesn't mean that the platform has no threads, and this'll be broken with threads in such a scenario (which I suspect you ran into which is why this is changing).

I'm not entirely sure what to do about this, but I'd rather not just pick the first thing that happens to compile and call it good. I think that either (a) threads should be ignored and the original codegen is retained, or (b) threads are fully supported and somehow the no-std native case is handled. For the latter that could mean allocating return areas instead of relying on a global, it could mean a mutex could be added, or perhaps something else I'm not thinking of.

Depending on how ambitiuos the solution is, however, I think it might be best to ignore this for now and have a follow-up which addresses things if that makes sense.

Comment thread crates/rust/src/lib.rs Outdated
Comment on lines +999 to +1000
let emit_native_world =
!self.opts.pub_export_macro || section_suffix == "imports and exports";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you explain a bit more what's going on here? I would naively expect a new configuration option for this, as opposed to both repurposing a previous option or detecting sort of a magical string constant here.

@Snowiiii

Copy link
Copy Markdown
Contributor Author

@alexcrichton tried to address review

@alexcrichton
alexcrichton added this pull request to the merge queue Nov 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 16, 2026
@alexcrichton
alexcrichton added this pull request to the merge queue Nov 16, 2026
Merged via the queue into bytecodealliance:main with commit d276c62 Nov 16, 2026
31 checks passed
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.

3 participants