-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unexpected exit code with std::process::ExitCode when compiling wasm32-wasip1 #130532
Comments
It seems that we just call rust/library/std/src/sys/pal/wasi/os.rs Lines 274 to 276 in f79a912
|
Minimized: #![crate_type = "cdylib"]
use std::process::ExitCode;
#[no_mangle]
pub fn fun() -> ExitCode {
ExitCode::from(2)
} (func $fun (;0;) (type 0) (result i32)
i32.const 1
) rust/library/std/src/sys/pal/unsupported/process.rs Lines 271 to 278 in eeb90cd
|
Oh, "cool"! |
@ShE3py that is so concise! Thanks. I’d also be very interested in getting some insight on where to look in the code base for this sort of thing. |
I'm kinda just abusing my IDE (RustRover)’s Go To Declaration & Find Usages shortcuts, you may need to tell yours to use the wasm target for name resolution/code indexing instead of your OS’ default one. |
Rollup merge of rust-lang#130554 - ShE3py:unsupported-exitcode, r=Noratrieb `pal::unsupported::process::ExitCode`: use an `u8` instead of a `bool` `ExitCode` should “represents the status code the current process can return to its parent under normal termination”, but is currently represented as a `bool` on unsupported platforms, making the `impl From<u8> for ExitCode` lossy. Fixes rust-lang#130532. History: [IRLO thread](https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426) (`ExitCode` as a `main` return), rust-lang#48618 (initial impl), rust-lang#93445 (`From<u8>` impl).
I ran the tests in my reproducer repo against the latest nightly (post merge of #130554) and the all pass now. Thanks! |
When compiled as a standard binary on the host system, the exit codes are returned as expected. When compiled with wasm32-wasip1, the use of ExitCode results in the exit code of 1, regardless of the value provided to ExitCode::from.
The following are the minimal examples used while reproducing the bug:
The above example produces the expected error code of 10 when compiling for the the host system and
wasm32-wasi
(executed with wasmtime 24.0.0).The above example produces the exit code
11
when compiled for the host system but returns exit code 1 when compiled withwasm32-wasi
(again run in wasmtime 24.0.0).Investigative Details
Looking at the resulting WASM (decompiled to WAT) we see the main function returns a
i32.const 1
(here compiled with#[no_mangle] for ease of searching
):For source code of the reproducer, see: peterschwarz/wasm32-wasip-exit-code-reproducer
Meta
Tested against stable, beta and nightly.
rustc --version --verbose
:rustc +beta --version --verbose
rustc +nightly --version --verbose
The text was updated successfully, but these errors were encountered: