Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Update a few aspects of the adapter build #17

Merged
merged 2 commits into from
Dec 7, 2022

Conversation

alexcrichton
Copy link
Member

  • Use the wasm32-unknown-unknown target for the adapter and specify flags in .cargo/config.toml to avoid having to pass the same flags everywhere. This allows using wasm32-wasi for tests to ensure the flags only apply to the adapter.

  • Use opt-level=s since speed is not of the utmost concern for this wasm but since it's likely to be included in many places size is likely more important.

  • Use strip = 'debuginfo' for the release build to remove the standard library's debugging information which isn't necessary.

  • Remove debug = 0 from the dev profile to have debugging information for development.

  • Add a small README.md describing what's here for now.

* Use the `wasm32-unknown-unknown` target for the adapter and specify
  flags in `.cargo/config.toml` to avoid having to pass the same flags
  everywhere. This allows using `wasm32-wasi` for tests to ensure the
  flags only apply to the adapter.

* Use `opt-level=s` since speed is not of the utmost concern for this
  wasm but since it's likely to be included in many places size is
  likely more important.

* Use `strip = 'debuginfo'` for the release build to remove the standard
  library's debugging information which isn't necessary.

* Remove `debug = 0` from the `dev` profile to have debugging
  information for development.

* Add a small `README.md` describing what's here for now.
@sunfishcode
Copy link
Member

One unfortunate thing about wasm32-unknown-unknown is that the Rust wasm32-unknown-unknown target is still using --export-dynamic, which makes the resulting wasm module export get_global_ptr and set_global_ptr. And there are some other subtle differences between wasm32-unknown-unknown and wasm32-wasi.

How inconvenient would be to use target.polyfill in the config.toml file, and have users build with RUSTFLAGS=--cfg=polyfill, instead of reusing wasm32-unknown-unknown? That way we're not tied to how wasm32-unknown-unknown does things.

@alexcrichton
Copy link
Member Author

I can change yeah, but can you elaborat on "other subtle differences"? I would additionally like to remove the $foo.command_export exports injected by LLD for the wasi target.

Additionally there's no real reason that --export-dynamic is used on the wasm32-unknown-unknown target other than it was literally the only way to do things at the time, but that was years ago and I surmise things have changed in the meantime.

This commit adds a `command` feature to main crate to avoid importing
the `_start` function when the `command` feature is disabled, making
this adapter useful for non-command WASI programs as well.

For now this still emits the `command` export in the final component but
with `use` in `*.wit` files it should be easier to avoid that export.
@alexcrichton
Copy link
Member Author

I've added a new commit with a feature that came up yesterday which is to have one build of the adapter for commands and another that's not for commands. The latter should be useful for "my wasm just happens to import WASI" but has its own form of exported interface.

@sunfishcode
Copy link
Member

Following up on the discussion above, I submitted some PRs to Rust:

Looking more closely, the other difference I see between wasm32-wasi and wasm32-unknown-unknown is that wasm32-unknown-unknown does options.default_adjusted_cabi = Some(Abi::Wasm); while wasm32-wasi doesn't. I think that only affects structs passed or returned by value, which neither wasi_snapshot_preview1 nor the canonical ABI for wit interfaces have.

@sunfishcode
Copy link
Member

Ok, I've now convinced myself that we can do this. If we ever do hit the ABI differences, we should find out about them via link-time signature mismatches.

@sunfishcode sunfishcode merged commit 345edcf into bytecodealliance:main Dec 7, 2022
@alexcrichton alexcrichton deleted the some-updates branch December 7, 2022 15:54
@alexcrichton
Copy link
Member Author

Thanks for opening those! Also, yeah, we don't have to worry about the cabi bits there. That's basically only for interacting with C code and otherwise wit-bindgen takes care of all the ABI details necessary for the canonical ABI through other means.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants