From f5fed266ece015c677784f5b9faa4994dbf3235e Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 24 Jun 2024 20:40:54 +0200 Subject: [PATCH 1/2] Fix invalid wasi targets compatibility --- src/lib.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dbeb44685..d90432a32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1288,7 +1288,8 @@ impl Build { self.compile_objects(&objects)?; self.assemble(lib_name, &dst.join(gnu_lib_name), &objects)?; - if self.get_target()?.contains("msvc") { + let target = self.get_target()?; + if target.contains("msvc") { let compiler = self.get_base_compiler()?; let atlmfc_lib = compiler .env() @@ -1334,11 +1335,12 @@ impl Build { .print_metadata(&format_args!("cargo:rustc-link-lib={}", stdlib.display())); } // Link c++ lib from WASI sysroot - if self.get_target()?.contains("wasi") { + if Build::is_wasi_target(target.as_ref()) { let wasi_sysroot = self.wasi_sysroot()?; self.cargo_output.print_metadata(&format_args!( - "cargo:rustc-flags=-L {}/lib/wasm32-wasi -lstatic=c++ -lstatic=c++abi", - Path::new(&wasi_sysroot).display() + "cargo:rustc-flags=-L {}/lib/{} -lstatic=c++ -lstatic=c++abi", + Path::new(&wasi_sysroot).display(), + target )); } } @@ -1940,7 +1942,7 @@ impl Build { cmd.push_cc_arg("-fno-plt".into()); } } - if target == "wasm32-wasip1" { + if Build::is_wasi_target(target) { // WASI does not support exceptions yet. // https://github.com/WebAssembly/exception-handling cmd.push_cc_arg("-fno-exceptions".into()); @@ -2888,10 +2890,7 @@ impl Build { autodetect_android_compiler(target, &host, gnu, clang) } else if target.contains("cloudabi") { format!("{}-{}", target, traditional) - } else if target == "wasm32-wasi" - || target == "wasm32-unknown-wasi" - || target == "wasm32-unknown-unknown" - { + } else if Build::is_wasi_target(target) { if self.cpp { "clang++".to_string() } else { @@ -3922,6 +3921,10 @@ impl Build { )) } } + fn is_wasi_target(target : &str) -> bool { + const TARGETS : [&'static str; 5] = ["wasm32-wasi", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2", "wasm32-wasi-threads"]; + return TARGETS.contains(&target); + } fn cuda_file_count(&self) -> usize { self.files From 38080577fa0e12fb4d86de2c5410ab0d4f35e326 Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 24 Jun 2024 20:47:58 +0200 Subject: [PATCH 2/2] Fix fmt issues --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d90432a32..7023a84af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3921,8 +3921,14 @@ impl Build { )) } } - fn is_wasi_target(target : &str) -> bool { - const TARGETS : [&'static str; 5] = ["wasm32-wasi", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2", "wasm32-wasi-threads"]; + fn is_wasi_target(target: &str) -> bool { + const TARGETS: [&'static str; 5] = [ + "wasm32-wasi", + "wasm32-wasip1", + "wasm32-wasip1-threads", + "wasm32-wasip2", + "wasm32-wasi-threads", + ]; return TARGETS.contains(&target); }