Skip to content

Commit

Permalink
Try to fix include paths for new wasmer-windows target
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 14, 2022
1 parent cb6fda1 commit d2af38e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-sys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 56 additions & 17 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`")?
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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: {}",
Expand Down

0 comments on commit d2af38e

Please sign in to comment.