From 1b7609cf1cb04d5dc480375f8addd357e5fa83aa Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 14 May 2026 14:45:33 +0200 Subject: [PATCH] Disable `main_needs_argc_argv` for Wasm --- compiler/rustc_target/src/spec/base/wasm.rs | 7 +++++++ .../src/spec/targets/wasm32_unknown_emscripten.rs | 1 + compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs | 4 ---- .../rustc_target/src/spec/targets/wasm32_wasip1_threads.rs | 4 ---- compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs | 4 ---- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_target/src/spec/base/wasm.rs b/compiler/rustc_target/src/spec/base/wasm.rs index 587eeac14beb7..1596100e629d7 100644 --- a/compiler/rustc_target/src/spec/base/wasm.rs +++ b/compiler/rustc_target/src/spec/base/wasm.rs @@ -118,6 +118,13 @@ pub(crate) fn options() -> TargetOptions { // with unwinding. llvm_args: cvs!["-wasm-use-legacy-eh=false"], + // WASI's `sys::args::init` function ignores its arguments; instead, + // `args::args()` makes the WASI API calls itself. + // + // Other Wasm targets make no use of `std::env` entirely. + // Emscripten enables it explicitly. + main_needs_argc_argv: false, + ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/targets/wasm32_unknown_emscripten.rs b/compiler/rustc_target/src/spec/targets/wasm32_unknown_emscripten.rs index e640e31164596..2104286ec8684 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_unknown_emscripten.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_unknown_emscripten.rs @@ -28,6 +28,7 @@ pub(crate) fn target() -> Target { crt_static_respected: true, crt_static_default: true, crt_static_allows_dylibs: true, + main_needs_argc_argv: true, panic_strategy: PanicStrategy::Unwind, no_default_libraries: false, families: cvs!["unix", "wasm"], diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs index 2d3dd0862d64c..f67b3b82edfac 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs @@ -41,10 +41,6 @@ pub(crate) fn target() -> Target { // without a main function. options.crt_static_allows_dylibs = true; - // WASI's `sys::args::init` function ignores its arguments; instead, - // `args::args()` makes the WASI API calls itself. - options.main_needs_argc_argv = false; - // And, WASI mangles the name of "main" to distinguish between different // signatures. options.entry_name = "__main_void".into(); diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs index 645f7ad40bb60..42f0a6a185e0e 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs @@ -52,10 +52,6 @@ pub(crate) fn target() -> Target { // without a main function. options.crt_static_allows_dylibs = true; - // WASI's `sys::args::init` function ignores its arguments; instead, - // `args::args()` makes the WASI API calls itself. - options.main_needs_argc_argv = false; - // And, WASI mangles the name of "main" to distinguish between different // signatures. options.entry_name = "__main_void".into(); diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs index b53bf3b7bd52b..656ce31c32f7f 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs @@ -46,10 +46,6 @@ pub(crate) fn target() -> Target { // without a main function. options.crt_static_allows_dylibs = true; - // WASI's `sys::args::init` function ignores its arguments; instead, - // `args::args()` makes the WASI API calls itself. - options.main_needs_argc_argv = false; - // And, WASI mangles the name of "main" to distinguish between different // signatures. options.entry_name = "__main_void".into();