Repository navigation
feat(rust): support native symbol linking and import resolution - #1786
Conversation
…native bindings
…-local _RET_AREA on native
| // 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 |
There was a problem hiding this comment.
It's ok to drop this comment and just have the update inline
| assert_ne!(r0.1, r1.1, "each thread should have its own _RET_AREA"); | ||
| assert_eq!(r0.2, "111"); | ||
| assert_eq!(r1.2, "222222"); | ||
| } |
There was a problem hiding this comment.
Minor comment, but could the native-related tests move to a separate tests/native.rs to keep things separated?
| {native_cfg} | ||
| ::std::thread_local! {{ | ||
| static _RET_AREA: ::core::cell::UnsafeCell<_RetArea> = const {{ | ||
| ::core::cell::UnsafeCell::new(_RetArea([::core::mem::MaybeUninit::uninit(); {size}])) | ||
| }}; | ||
| }} |
There was a problem hiding this comment.
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.
| let emit_native_world = | ||
| !self.opts.pub_export_macro || section_suffix == "imports and exports"; |
There was a problem hiding this comment.
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.
|
@alexcrichton tried to address review |
Picks up #1685 (with @BjornTheProgrammer's permission) to address #1062, rebased onto
mainwith review feedback addressed:#[doc(hidden)]rt::extern_wasm!and use it across codegen andasync_support, moving fast/coldAtomicPtrcaching intort::resolve_import.#[no_mangle]C hooks with a lock-synchronized&str-basedrt::register_import_resolver(no_stdwasip3_task_setalso routes throughextern_wasm!).wit_component::metadata::encodeworld bytes from__wit_bindgen_world_<world>instead of just the world name.target_arch = "wasm32"gates totarget_family = "wasm", move detailed native ABI docs tocrates/guest-rust/NATIVE.md, and drop the separatenative-e2esubcrate in favor ofcodegen.rs+native_importsunit tests.