Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide cabi_realloc on wasm32-wasip2 by default #122411

Merged
merged 2 commits into from Apr 3, 2024

Conversation

alexcrichton
Copy link
Member

This commit provides a component model intrinsic in the standard library
by default on the wasm32-wasip2 target. This intrinsic is not
required by the component model itself but is quite common to use, for
example it's needed if a wasm module receives a string or a list.

The intention of this commit is to provide an overridable definition in
the standard library through a weak definition of this function. That
means that downstream crates can provide their own customized and more
specific versions if they'd like, but the standard library's version
should suffice for general-purpose use.

@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2024

r? @m-ou-se

rustbot has assigned @m-ou-se.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-wasi Operating system: Wasi, Webassembly System Interface S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 12, 2024
@alexcrichton
Copy link
Member Author

cc @sunfishcode and @rylev

I've tested this locally where the wit-bindgen test suite passes with the wasm32-wasip2 target from this PR

alexcrichton added a commit to alexcrichton/witx-bindgen that referenced this pull request Mar 12, 2024
This commit adds some initial support for `wasm32-wasip2` in
`wit-bindgen`. Everything works as-is but one of the benefits of a new
target is that we can move runtime bits such as `cabi_realloc` into the
standard library rather than in this crate. This PR sets up
infrastructure to test the `wasm32-wasip2` target and additionally
assumes rust-lang/rust#122411 for providing the implementation of
`cabi_realloc`.
} else if #[cfg(all(target_os = "wasi", target_env = "p2"))] {
mod wasip2;
pub use self::wasip2::*;
} else if #[cfg(target_os = "wasi")] {
mod wasi;
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to rename this module to wasip1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I'll do that as a follow-up

@bors
Copy link
Contributor

bors commented Mar 13, 2024

☔ The latest upstream changes (presumably #122423) made this pull request unmergeable. Please resolve the merge conflicts.

The ordering of targets in `pal/mod.rs` did not end up using the wasip2
implementation, so after reordering that I've edited the implementation
to compile correctly.
This commit provides a component model intrinsic in the standard library
by default on the `wasm32-wasip2` target. This intrinsic is not
required by the component model itself but is quite common to use, for
example it's needed if a wasm module receives a string or a list.

The intention of this commit is to provide an overridable definition in
the standard library through a weak definition of this function. That
means that downstream crates can provide their own customized and more
specific versions if they'd like, but the standard library's version
should suffice for general-purpose use.
Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

As I mentioned above, it's inconvenient that this cabi_realloc isn't available for no_std builds, however there are alternatives if we use Nightly Rust, so we can revisit this later if needed.

github-merge-queue bot pushed a commit to bytecodealliance/wit-bindgen that referenced this pull request Mar 18, 2024
This commit adds some initial support for `wasm32-wasip2` in
`wit-bindgen`. Everything works as-is but one of the benefits of a new
target is that we can move runtime bits such as `cabi_realloc` into the
standard library rather than in this crate. This PR sets up
infrastructure to test the `wasm32-wasip2` target and additionally
assumes rust-lang/rust#122411 for providing the implementation of
`cabi_realloc`.
@jeffparsons
Copy link
Contributor

Is this stuck? Might it need a "bors r+" to get it into the queue or is Bors meant to pick up review approvals now?

@alexcrichton
Copy link
Member Author

Ah while @rylev and @sunfishcode and I are all stakeholders on the wasm32-wasip2 target I'm not sure any of us have r+ permissions, so we'll need someone else to tell bors this is ready I think.

@rylev
Copy link
Member

rylev commented Apr 2, 2024

Looks like we might need @m-ou-se to reroll the review.

@m-ou-se
Copy link
Member

m-ou-se commented Apr 2, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Apr 2, 2024

📌 Commit 5af8187 has been approved by m-ou-se

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 2, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 3, 2024
…kingjubilee

Rollup of 4 pull requests

Successful merges:

 - rust-lang#122411 ( Provide cabi_realloc on wasm32-wasip2 by default )
 - rust-lang#123349 (Fix capture analysis for by-move closure bodies)
 - rust-lang#123359 (Link against libc++abi and libunwind as well when building LLVM wrappers on AIX)
 - rust-lang#123388 (use a consistent style for links)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit abb0393 into rust-lang:master Apr 3, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 3, 2024
Rollup merge of rust-lang#122411 - alexcrichton:wasm32-wasip2-cabi-realloc, r=m-ou-se

 Provide cabi_realloc on wasm32-wasip2 by default

This commit provides a component model intrinsic in the standard library
by default on the `wasm32-wasip2` target. This intrinsic is not
required by the component model itself but is quite common to use, for
example it's needed if a wasm module receives a string or a list.

The intention of this commit is to provide an overridable definition in
the standard library through a weak definition of this function. That
means that downstream crates can provide their own customized and more
specific versions if they'd like, but the standard library's version
should suffice for general-purpose use.
rvolosatovs pushed a commit to wrpc/wrpc that referenced this pull request May 23, 2024
This commit adds some initial support for `wasm32-wasip2` in
`wit-bindgen`. Everything works as-is but one of the benefits of a new
target is that we can move runtime bits such as `cabi_realloc` into the
standard library rather than in this crate. This PR sets up
infrastructure to test the `wasm32-wasip2` target and additionally
assumes rust-lang/rust#122411 for providing the implementation of
`cabi_realloc`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-wasi Operating system: Wasi, Webassembly System Interface S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants