mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Fix cross-compile test by switching to build-exe
We run this test only on linux and macos, on Windows it might or might not work.
This commit is contained in:
@@ -235,7 +235,6 @@ impl CreateExe {
|
|||||||
std::fs::copy(&header_path, Path::new("static_defs.h"))
|
std::fs::copy(&header_path, Path::new("static_defs.h"))
|
||||||
.context("Could not access given header file")?;
|
.context("Could not access given header file")?;
|
||||||
if let Some(setup) = cross_compilation.as_ref() {
|
if let Some(setup) = cross_compilation.as_ref() {
|
||||||
println!("compile zig static_defs.h");
|
|
||||||
self.compile_zig(
|
self.compile_zig(
|
||||||
output_path,
|
output_path,
|
||||||
wasm_module_path,
|
wasm_module_path,
|
||||||
@@ -256,7 +255,6 @@ impl CreateExe {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("compiling non-pirita with object format {object_format:?}");
|
|
||||||
match object_format {
|
match object_format {
|
||||||
ObjectFormat::Serialized => {
|
ObjectFormat::Serialized => {
|
||||||
let module = Module::from_file(&store, &wasm_module_path)
|
let module = Module::from_file(&store, &wasm_module_path)
|
||||||
@@ -308,7 +306,6 @@ impl CreateExe {
|
|||||||
writer.write_all(header_file_src.as_bytes())?;
|
writer.write_all(header_file_src.as_bytes())?;
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
if let Some(setup) = cross_compilation.as_ref() {
|
if let Some(setup) = cross_compilation.as_ref() {
|
||||||
println!("compile zig static_defs.h 2");
|
|
||||||
self.compile_zig(
|
self.compile_zig(
|
||||||
output_path,
|
output_path,
|
||||||
object_file_path,
|
object_file_path,
|
||||||
@@ -406,12 +403,11 @@ impl CreateExe {
|
|||||||
v.canonicalize().unwrap_or(v)
|
v.canonicalize().unwrap_or(v)
|
||||||
} else {
|
} else {
|
||||||
{
|
{
|
||||||
let libwasmer_path = if target_triple.unwrap_or(Triple::host()).operating_system
|
let os = target_triple.unwrap_or(Triple::host()).operating_system;
|
||||||
== wasmer_types::OperatingSystem::Windows
|
let libwasmer_path = match os {
|
||||||
{
|
OperatingSystem::Windows => "lib/wasmer.lib",
|
||||||
"lib/wasmer.lib"
|
// OperatingSystem::Darwin => "lib/libwasmer.dylib",
|
||||||
} else {
|
_ => "lib/libwasmer.a",
|
||||||
"lib/libwasmer.a"
|
|
||||||
};
|
};
|
||||||
let tarball_dir;
|
let tarball_dir;
|
||||||
let filename = if let Some(local_tarball) = cross_subc.tarball.as_ref() {
|
let filename = if let Some(local_tarball) = cross_subc.tarball.as_ref() {
|
||||||
@@ -489,13 +485,9 @@ impl CreateExe {
|
|||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("compile_c: output {c_src_path:?} to {c_src_obj:?}");
|
|
||||||
|
|
||||||
run_c_compile(&c_src_path, &c_src_obj, target_triple.clone())
|
run_c_compile(&c_src_path, &c_src_obj, target_triple.clone())
|
||||||
.context("Failed to compile C source code")?;
|
.context("Failed to compile C source code")?;
|
||||||
|
|
||||||
println!("linking code...");
|
|
||||||
|
|
||||||
LinkCode {
|
LinkCode {
|
||||||
object_paths: vec![c_src_obj, wasm_object_path],
|
object_paths: vec![c_src_obj, wasm_object_path],
|
||||||
output_path,
|
output_path,
|
||||||
@@ -506,8 +498,6 @@ impl CreateExe {
|
|||||||
.run()
|
.run()
|
||||||
.context("Failed to link objects together")?;
|
.context("Failed to link objects together")?;
|
||||||
|
|
||||||
println!("linking code done");
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,18 +536,13 @@ impl CreateExe {
|
|||||||
libwasmer_path.pop();
|
libwasmer_path.pop();
|
||||||
|
|
||||||
if let Some(entrypoint) = pirita_main_atom.as_ref() {
|
if let Some(entrypoint) = pirita_main_atom.as_ref() {
|
||||||
println!("entrypint - static wasmer_main.c source:");
|
|
||||||
let c_code = Self::generate_pirita_wasmer_main_c_static(pirita_atoms, entrypoint);
|
let c_code = Self::generate_pirita_wasmer_main_c_static(pirita_atoms, entrypoint);
|
||||||
println!("{c_code}");
|
|
||||||
std::fs::write(&c_src_path, c_code)?;
|
std::fs::write(&c_src_path, c_code)?;
|
||||||
} else {
|
} else {
|
||||||
println!("no entrypint - default wasmer_main.c source");
|
|
||||||
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
|
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("header code path code:");
|
|
||||||
if !header_code_path.is_dir() {
|
if !header_code_path.is_dir() {
|
||||||
println!("{}", std::fs::read_to_string(&header_code_path).unwrap());
|
|
||||||
header_code_path.pop();
|
header_code_path.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,38 +557,31 @@ impl CreateExe {
|
|||||||
include_dir.push("include");
|
include_dir.push("include");
|
||||||
|
|
||||||
let mut cmd = Command::new(zig_binary_path);
|
let mut cmd = Command::new(zig_binary_path);
|
||||||
cmd.arg("cc");
|
cmd.arg("build-exe");
|
||||||
cmd.arg("--verbose");
|
|
||||||
cmd.arg("-target");
|
cmd.arg("-target");
|
||||||
cmd.arg(&zig_triple);
|
cmd.arg(&zig_triple);
|
||||||
cmd.arg(&format!("-L{}", libwasmer_path.display()));
|
|
||||||
cmd.arg(&format!("-l:{}", lib_filename));
|
|
||||||
cmd.arg(&format!("-I{}/", include_dir.display()));
|
cmd.arg(&format!("-I{}/", include_dir.display()));
|
||||||
cmd.arg(&format!("-I{}/", header_code_path.display()));
|
cmd.arg(&format!("-I{}/", header_code_path.display()));
|
||||||
cmd.arg("-isystem");
|
cmd.arg("--library");
|
||||||
|
cmd.arg("c");
|
||||||
|
cmd.arg("-OReleaseSafe");
|
||||||
|
cmd.arg(&format!("-femit-bin={}", output_path.display()));
|
||||||
|
|
||||||
if !zig_triple.contains("windows") {
|
if !zig_triple.contains("windows") {
|
||||||
cmd.arg("-lunwind");
|
cmd.arg("-lunwind");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("pirita object path (should contain all functions): {}", object_path.display());
|
|
||||||
|
|
||||||
cmd.arg(&object_path);
|
cmd.arg(&object_path);
|
||||||
cmd.arg(&c_src_path);
|
cmd.arg(&c_src_path);
|
||||||
|
cmd.arg(libwasmer_path.join(lib_filename));
|
||||||
|
|
||||||
if let Some(volume_obj) = pirita_volume_path.as_ref() {
|
if let Some(volume_obj) = pirita_volume_path.as_ref() {
|
||||||
cmd.arg(volume_obj.clone());
|
cmd.arg(volume_obj.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("zig cc command: {cmd:#?} -> {output_path:?}");
|
cmd.output().context("Could not execute `zig`")?
|
||||||
|
|
||||||
cmd.arg("-o")
|
|
||||||
.arg(&output_path)
|
|
||||||
.output()
|
|
||||||
.context("Could not execute `zig`")?
|
|
||||||
};
|
};
|
||||||
if !compilation.status.success() {
|
if !compilation.status.success() {
|
||||||
println!("compilation error");
|
|
||||||
return Err(anyhow::anyhow!(String::from_utf8_lossy(
|
return Err(anyhow::anyhow!(String::from_utf8_lossy(
|
||||||
&compilation.stderr
|
&compilation.stderr
|
||||||
)
|
)
|
||||||
@@ -619,7 +597,6 @@ impl CreateExe {
|
|||||||
target: &Target,
|
target: &Target,
|
||||||
output_path: &Path,
|
output_path: &Path,
|
||||||
) -> anyhow::Result<PathBuf> {
|
) -> anyhow::Result<PathBuf> {
|
||||||
|
|
||||||
let volume_object_path = output_path.join("volumes.obj");
|
let volume_object_path = output_path.join("volumes.obj");
|
||||||
|
|
||||||
let mut volumes_object = get_object_for_target(target.triple())?;
|
let mut volumes_object = get_object_for_target(target.triple())?;
|
||||||
@@ -713,23 +690,14 @@ impl CreateExe {
|
|||||||
metadata_length,
|
metadata_length,
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("symbols: pirita header file:");
|
|
||||||
println!("{header_file_src}");
|
|
||||||
println!("------");
|
|
||||||
|
|
||||||
let mut writer = BufWriter::new(File::create(&object_path)?);
|
let mut writer = BufWriter::new(File::create(&object_path)?);
|
||||||
obj.write_stream(&mut writer)
|
obj.write_stream(&mut writer)
|
||||||
.map_err(|err| anyhow::anyhow!(err.to_string()))?;
|
.map_err(|err| anyhow::anyhow!(err.to_string()))?;
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
|
|
||||||
std::fs::copy(&object_path, format!("{atom_name}.obj"));
|
|
||||||
|
|
||||||
let mut writer = BufWriter::new(File::create(&header_path)?);
|
let mut writer = BufWriter::new(File::create(&header_path)?);
|
||||||
writer.write_all(header_file_src.as_bytes())?;
|
writer.write_all(header_file_src.as_bytes())?;
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
|
|
||||||
println!("pirita obj created at {}", object_path.display());
|
|
||||||
println!("pirita static_defs.h created at {}", header_path.display());
|
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "static-artifact-create"))]
|
#[cfg(not(feature = "static-artifact-create"))]
|
||||||
ObjectFormat::Symbols => {
|
ObjectFormat::Symbols => {
|
||||||
@@ -836,19 +804,16 @@ impl CreateExe {
|
|||||||
.arg("--verbose")
|
.arg("--verbose")
|
||||||
.arg("-target")
|
.arg("-target")
|
||||||
.arg(&zig_triple)
|
.arg(&zig_triple)
|
||||||
.arg(&format!("-L{}", libwasmer_path.display()))
|
.arg(&format!("-I{}", include_dir.display()))
|
||||||
.arg(&format!("-l:{}", lib_filename))
|
.arg("-lc");
|
||||||
.arg("-isystem")
|
|
||||||
.arg(&format!("-I{}", include_dir.display()));
|
|
||||||
if !zig_triple.contains("windows") {
|
if !zig_triple.contains("windows") {
|
||||||
cmd_mut = cmd_mut.arg("-lunwind");
|
cmd_mut = cmd_mut.arg("-lunwind");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("pirita: output {cmd_mut:?} to {output_path:?}");
|
|
||||||
|
|
||||||
cmd_mut
|
cmd_mut
|
||||||
.args(link_objects.into_iter())
|
.args(link_objects.into_iter())
|
||||||
.arg(&c_src_path)
|
.arg(&c_src_path)
|
||||||
|
.arg(libwasmer_path.join(lib_filename))
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
.arg(&output_path)
|
.arg(&output_path)
|
||||||
.output()
|
.output()
|
||||||
@@ -885,7 +850,6 @@ impl CreateExe {
|
|||||||
let volumes_obj_path = Self::write_volume_obj(volume_bytes, target, tempdir_path)?;
|
let volumes_obj_path = Self::write_volume_obj(volume_bytes, target, tempdir_path)?;
|
||||||
|
|
||||||
if let Some(setup) = cross_compilation.as_ref() {
|
if let Some(setup) = cross_compilation.as_ref() {
|
||||||
println!("compile zig static_defs.h pirita");
|
|
||||||
self.compile_zig(
|
self.compile_zig(
|
||||||
output_path,
|
output_path,
|
||||||
object_file_path,
|
object_file_path,
|
||||||
@@ -1014,9 +978,7 @@ impl CreateExe {
|
|||||||
let _ = std::fs::create_dir_all(&working_dir);
|
let _ = std::fs::create_dir_all(&working_dir);
|
||||||
let (store, _) = self.compiler.get_store_for_target(target.clone())?;
|
let (store, _) = self.compiler.get_store_for_target(target.clone())?;
|
||||||
|
|
||||||
println!("create objs pirita...");
|
|
||||||
Self::create_objs_pirita(&store, file, &target, working_dir, object_format)?;
|
Self::create_objs_pirita(&store, file, &target, working_dir, object_format)?;
|
||||||
println!("pirita objs created!");
|
|
||||||
|
|
||||||
let volumes_obj = file.get_volumes_as_fileblock();
|
let volumes_obj = file.get_volumes_as_fileblock();
|
||||||
self.link_exe_from_dir(
|
self.link_exe_from_dir(
|
||||||
@@ -1060,8 +1022,6 @@ impl CreateExe {
|
|||||||
.canonicalize()
|
.canonicalize()
|
||||||
.context("Failed to find libwasmer")?;
|
.context("Failed to find libwasmer")?;
|
||||||
|
|
||||||
println!("Using libwasmer file: {}", libwasmer_path.display());
|
|
||||||
|
|
||||||
let lib_filename = libwasmer_path
|
let lib_filename = libwasmer_path
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -1418,7 +1378,6 @@ mod http_fetch {
|
|||||||
mut release: serde_json::Value,
|
mut release: serde_json::Value,
|
||||||
target_triple: wasmer::Triple,
|
target_triple: wasmer::Triple,
|
||||||
) -> Result<std::path::PathBuf> {
|
) -> Result<std::path::PathBuf> {
|
||||||
println!("download_release");
|
|
||||||
let check_arch = |name: &str| -> bool {
|
let check_arch = |name: &str| -> bool {
|
||||||
match target_triple.architecture {
|
match target_triple.architecture {
|
||||||
wasmer_types::Architecture::X86_64 => {
|
wasmer_types::Architecture::X86_64 => {
|
||||||
|
|||||||
@@ -962,7 +962,7 @@ pub fn try_unpack_targz<P: AsRef<Path>>(
|
|||||||
|
|
||||||
let try_decode_zip = || {
|
let try_decode_zip = || {
|
||||||
let file = open_file()?;
|
let file = open_file()?;
|
||||||
zip_extract::extract(file, &target_targz_path, strip_toplevel).map_err(|e| {
|
zip_extract::extract(file, target_targz_path, strip_toplevel).map_err(|e| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"could not extract zip file {}: {e}",
|
"could not extract zip file {}: {e}",
|
||||||
target_targz_path.display()
|
target_targz_path.display()
|
||||||
|
|||||||
@@ -21,18 +21,28 @@ fn test_no_start_wat_path() -> String {
|
|||||||
format!("{}/{}", ASSET_PATH, "no_start.wat")
|
format!("{}/{}", ASSET_PATH, "no_start.wat")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cross_compile_python_windows() -> anyhow::Result<()> {
|
fn test_cross_compile_python_windows() -> anyhow::Result<()> {
|
||||||
let temp_dir = tempfile::TempDir::new()?;
|
let temp_dir = tempfile::TempDir::new()?;
|
||||||
let python_wasmer_path = temp_dir.path().join("python.exe");
|
let python_wasmer_path = temp_dir.path().join("python.exe");
|
||||||
|
|
||||||
|
let targets = &[
|
||||||
|
"aarch64-darwin",
|
||||||
|
"x86_64-darwin",
|
||||||
|
"x86_64-linux-gnu",
|
||||||
|
"aarch64-linux-gnu",
|
||||||
|
"x86_64-windows-gnu",
|
||||||
|
];
|
||||||
|
|
||||||
|
for t in targets {
|
||||||
let output = Command::new(get_wasmer_path())
|
let output = Command::new(get_wasmer_path())
|
||||||
.arg("create-exe")
|
.arg("create-exe")
|
||||||
.arg(wasi_test_python_path())
|
.arg(wasi_test_python_path())
|
||||||
.arg("--target")
|
.arg("--target")
|
||||||
.arg("x86_64-windows-gnu")
|
.arg(t)
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
.arg(python_wasmer_path)
|
.arg(python_wasmer_path.clone())
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
@@ -45,6 +55,9 @@ fn test_cross_compile_python_windows() -> anyhow::Result<()> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(python_wasmer_path.exists());
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user