{"id":"98d087bef2e85401","repo":"rust-lang/rust","slug":"can-t-link-as-reactor-on-non-wasi-target","errorCode":null,"errorMessage":"can't link as reactor on non-wasi target","messagePattern":"can't link as reactor on non-wasi target","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_ssa/src/back/linker.rs","lineNumber":969,"sourceCode":"    fn set_output_kind(\n        &mut self,\n        output_kind: LinkOutputKind,\n        _crate_type: CrateType,\n        out_filename: &Path,\n    ) {\n        match output_kind {\n            LinkOutputKind::DynamicNoPicExe\n            | LinkOutputKind::DynamicPicExe\n            | LinkOutputKind::StaticNoPicExe\n            | LinkOutputKind::StaticPicExe => {}\n            LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {\n                self.link_arg(\"/DLL\");\n                let mut arg: OsString = \"/IMPLIB:\".into();\n                arg.push(out_filename.with_extension(\"dll.lib\"));\n                self.link_arg(arg);\n            }\n            LinkOutputKind::WasiReactorExe => {\n                panic!(\"can't link as reactor on non-wasi target\");\n            }\n        }\n    }\n\n    fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) {\n        // On MSVC-like targets rustc supports import libraries using alternative naming\n        // scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.\n        if let Some(path) = try_find_native_dynamic_library(self.sess, name, verbatim) {\n            self.link_arg(path);\n        } else {\n            self.link_arg(format!(\"{}{}\", name, if verbatim { \"\" } else { \".lib\" }));\n        }\n    }\n\n    fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {\n        // When producing a dll, MSVC linker may not emit an implib file if the dll doesn't export\n        // any symbols, so we skip linking if the implib file is not present.\n        let implib_path = path.with_extension(\"dll.lib\");","sourceCodeStart":951,"sourceCodeEnd":987,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_ssa/src/back/linker.rs#L951-L987","documentation":"Thrown by the MSVC linker's set_output_kind when it receives a LinkOutputKind::WasiReactorExe. The MSVC linker only knows how to produce Windows executables, DLLs, and their import libraries; a WASI reactor executable is a WebAssembly concept with no MSVC representation, so reaching this arm means the chosen linker does not match the requested output kind. It signals a fundamentally inconsistent target configuration.","triggerScenarios":"Produced when crate-type/output configuration requests a WASI reactor executable (e.g. -C link-arg or target spec selecting reactor) but the linker selected for the job is the MSVC linker. Usually the result of a target spec or -C linker-flavor mismatch mixing wasm output flags with an msvc toolchain.","commonSituations":"A custom or hand-edited target JSON that combines WASI-ish options with an msvc linker flavor. Forcing -C linker-flavor incorrectly. A misconfigured xwin/cross environment routing a wasm build through the Windows linker.","solutions":["Target an actual WASI triple such as wasm32-wasip1 or wasm32-wasip2 and let rustc select the wasm linker.","Verify -C linker-flavor and the target spec's linker flavor are not set to a Windows/MSVC flavor for a wasm/reactor build.","Remove reactor-specific options (e.g. -C link-arg=--export=...) unless targeting wasm32-wasi with a wasm-compatible linker."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn reactor_target_ok(target: &str) -> bool {\n    target.contains(\"wasi\")\n}\n\n// caller: if cfg!(feature = \"reactor\") { assert!(reactor_target_ok(&target)); }","typeGuard":"fn is_wasi_reactor_capable(target: &str) -> bool {\n    target.starts_with(\"wasm32-wasi\") || target.starts_with(\"wasm32-wasip1\")\n        || target.starts_with(\"wasm32-wasip2\") || target.starts_with(\"wasm32-wasi-preview2\")\n}","tryCatchPattern":"let stderr = String::from_utf8_lossy(&output.stderr);\nif stderr.contains(\"can't link as reactor on non-wasi target\") {\n    return Err(LinkError::ReactorRequiresWasi { actual_target: target.into() });\n}","preventionTips":["Only enable `-C link-arg=--reactor` (or the `reactor` crate-type) when targeting `wasm32-wasi*`.","Gate reactor features behind a Cargo cfg that checks the target family.","Document the WASI requirement in the crate's README so consumers do not enable reactor on `wasm32-unknown-unknown`."],"tags":["msvc","wasi","linker","target-spec","wasm"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}