diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index cc567bd15c0..7d3f7f5b390 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -107,7 +107,7 @@ jobs: - name: Set up base deps on musl if: matrix.build == 'linux-musl-x64' run: | - apk add build-base bash musl-dev curl make libtool libffi-dev gcc gcc-multilib automake autoconf git openssl-dev g++ + apk add build-base bash musl-dev curl make libtool libffi-dev gcc build-base automake autoconf git openssl-dev g++ - name: Install Rust uses: dtolnay/rust-toolchain@stable with: diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index e307d492ca2..b1d1696b761 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -8,6 +8,7 @@ use clap::Parser; use serde::{Deserialize, Serialize}; #[cfg(feature = "http")] use std::collections::BTreeMap; +use std::default; use std::env; use std::fs; use std::fs::File; @@ -563,31 +564,69 @@ impl CreateExe { include_dir.pop(); include_dir.push("include"); + let mut default_include_path = None; + + #[cfg(target_os = "macos")] + { + if let Ok(output) = Command::new("xcrun").arg("--show-sdk-path").output() { + default_include_path = + Some(String::from_utf8_lossy(&output.stdout).to_string()); + } + } + + #[cfg(target_os = "linux")] + { + default_include_path = Some("/usr/include".to_string()); + } + + #[cfg(target_os = "windows")] + { + // TODO: discover include path? + default_include_path = Some( + "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\ucrt" + .to_string(), + ); + } + + let default_include_path = match default_include_path { + Some(s) => Some(s), + None => { + if zig_triple.contains("windows") { + return Err(anyhow::anyhow!("no default include path ")); + } else { + None + } + } + }; + let mut cmd = Command::new(zig_binary_path); - let mut cmd_mut: &mut Command = cmd - .arg("cc") - .arg("-target") - .arg(&zig_triple) - .arg(&format!("-L{}", libwasmer_path.display())) - .arg(&format!("-l:{}", lib_filename)) - // xcrun --show-sdk-path - // .arg("-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include") - .arg("-I/usr/include") - .arg(&format!("-I{}", include_dir.display())) - .arg(&format!("-I{}", header_code_path.display())); + cmd.arg("cc"); + cmd.arg("-target"); + cmd.arg(&zig_triple); + cmd.arg(&format!("-L{}", libwasmer_path.display())); + cmd.arg(&format!("-l:{}", lib_filename)); + + if let Some(default_include) = default_include_path { + cmd.arg(format!("-I{default_include}")); + } + + cmd.arg(&format!("-I{}", include_dir.display())); + cmd.arg(&format!("-I{}", header_code_path.display())); + if !zig_triple.contains("windows") { - cmd_mut = cmd_mut.arg("-lunwind"); + cmd.arg("-lunwind"); } - cmd_mut = cmd_mut.arg(&object_path).arg(&c_src_path); + + cmd.arg(&object_path); + cmd.arg(&c_src_path); if let Some(volume_obj) = pirita_volume_path.as_ref() { - cmd_mut = cmd_mut.arg(volume_obj.clone()); + cmd.arg(volume_obj.clone()); } - println!("cmd (zig cc): {:?}", cmd_mut); + println!("cmd (zig cc): {:?}", cmd); - cmd_mut - .arg("-o") + cmd.arg("-o") .arg(&output_path) .output() .context("Could not execute `zig`")? diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 361fba82606..94416974dab 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -23,7 +23,6 @@ fn test_no_start_wat_path() -> String { #[test] fn test_cross_compile_python_windows() -> anyhow::Result<()> { - let temp_dir = tempfile::TempDir::new()?; let python_wasmer_path = temp_dir.path().join("python.exe"); @@ -35,7 +34,7 @@ fn test_cross_compile_python_windows() -> anyhow::Result<()> { .arg("-o") .arg(python_wasmer_path) .output()?; - + if !output.status.success() { bail!( "linking failed with: stdout: {}\n\nstderr: {}",