From b3bf384d18707199cbd58cea15b3534e7e0fb7ca Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Tue, 27 Jun 2023 12:33:03 +0800 Subject: [PATCH] Moved another create-exe test into "create_exe.rs" --- tests/integration/cli/tests/create_exe.rs | 121 +++++++++++++++++++++- tests/integration/cli/tests/run.rs | 111 -------------------- 2 files changed, 119 insertions(+), 113 deletions(-) diff --git a/tests/integration/cli/tests/create_exe.rs b/tests/integration/cli/tests/create_exe.rs index 21a80d62f20..45a10f7192f 100644 --- a/tests/integration/cli/tests/create_exe.rs +++ b/tests/integration/cli/tests/create_exe.rs @@ -1,6 +1,11 @@ //! Tests of the `wasmer create-exe` command. -use std::{fs, io::prelude::*, path::PathBuf, process::Command}; +use std::{ + fs, + io::prelude::*, + path::{Path, PathBuf}, + process::Command, +}; use anyhow::{bail, Context}; use assert_cmd::prelude::OutputAssertExt; @@ -693,7 +698,7 @@ fn test_wasmer_create_exe_pirita_works() { // std::fs::create_dir_all(&temp_dir); use wasmer_integration_tests_cli::get_repo_root_path; - let temp_dir = tempfile::TempDir::new().unwrap(); + let temp_dir = TempDir::new().unwrap(); let temp_dir = temp_dir.path().to_path_buf(); let python_wasmer_path = temp_dir.join("python.wasmer"); std::fs::copy(create_exe_python_wasmer(), &python_wasmer_path).unwrap(); @@ -738,3 +743,115 @@ fn test_wasmer_create_exe_pirita_works() { command.assert().success().stdout("hello\n"); } + +// FIXME: Fix and re-enable this test +// See https://github.com/wasmerio/wasmer/issues/3615 +#[test] +#[ignore] +fn test_cross_compile_python_windows() { + let temp_dir = TempDir::new().unwrap(); + + let targets: &[&str] = if cfg!(windows) { + &[ + "aarch64-darwin", + "x86_64-darwin", + "x86_64-linux-gnu", + "aarch64-linux-gnu", + ] + } else { + &[ + "aarch64-darwin", + "x86_64-darwin", + "x86_64-linux-gnu", + "aarch64-linux-gnu", + "x86_64-windows-gnu", + ] + }; + + let compilers: &[&str] = if cfg!(target_env = "musl") { + // MUSL has no support for LLVM in C-API + &["cranelift", "singlepass"] + } else { + &["cranelift", "singlepass", "llvm"] + }; + + // llvm-objdump --disassemble-all --demangle ./objects/wasmer_vm-50cb118b098c15db.wasmer_vm.60425a0a-cgu.12.rcgu.o + // llvm-objdump --macho --exports-trie ~/.wasmer/cache/wasmer-darwin-arm64/lib/libwasmer.dylib + let excluded_combinations = &[ + ("aarch64-darwin", "llvm"), // LLVM: aarch64 not supported relocation Arm64MovwG0 not supported + ("aarch64-linux-gnu", "llvm"), // LLVM: aarch64 not supported relocation Arm64MovwG0 not supported + // https://github.com/ziglang/zig/issues/13729 + ("x86_64-darwin", "llvm"), // undefined reference to symbol 'wasmer_vm_raise_trap' kind Unknown + ("x86_64-windows-gnu", "llvm"), // unimplemented symbol `wasmer_vm_raise_trap` kind Unknown + ]; + + for t in targets { + for c in compilers { + if excluded_combinations.contains(&(t, c)) { + continue; + } + println!("{t} target {c}"); + let python_wasmer_path = temp_dir.path().join(format!("{t}-python")); + + let tarball = match std::env::var("GITHUB_TOKEN") { + Ok(_) => Some(assert_tarball_is_present_local(t).unwrap()), + Err(_) => None, + }; + let mut cmd = Command::new(get_wasmer_path()); + + cmd.arg("create-exe"); + cmd.arg(create_exe_python_wasmer()); + cmd.arg("--target"); + cmd.arg(t); + cmd.arg("-o"); + cmd.arg(python_wasmer_path.clone()); + cmd.arg(format!("--{c}")); + if std::env::var("GITHUB_TOKEN").is_ok() { + cmd.arg("--debug-dir"); + cmd.arg(format!("{t}-{c}")); + } + + if t.contains("x86_64") && *c == "singlepass" { + cmd.arg("-m"); + cmd.arg("avx"); + } + + if let Some(t) = tarball { + cmd.arg("--tarball"); + cmd.arg(t); + } + + let assert = cmd.assert().success(); + + if !python_wasmer_path.exists() { + let p = std::fs::read_dir(temp_dir.path()) + .unwrap() + .filter_map(|e| Some(e.ok()?.path())) + .collect::>(); + let output = assert.get_output(); + panic!("target {t} was not compiled correctly tempdir: {p:#?}, {output:?}",); + } + } + } +} + +fn assert_tarball_is_present_local(target: &str) -> Result { + let wasmer_dir = std::env::var("WASMER_DIR").expect("no WASMER_DIR set"); + let directory = match target { + "aarch64-darwin" => "wasmer-darwin-arm64.tar.gz", + "x86_64-darwin" => "wasmer-darwin-amd64.tar.gz", + "x86_64-linux-gnu" => "wasmer-linux-amd64.tar.gz", + "aarch64-linux-gnu" => "wasmer-linux-aarch64.tar.gz", + "x86_64-windows-gnu" => "wasmer-windows-gnu64.tar.gz", + _ => return Err(anyhow::anyhow!("unknown target {target}")), + }; + let libwasmer_cache_path = Path::new(&wasmer_dir).join("cache").join(directory); + if !libwasmer_cache_path.exists() { + return Err(anyhow::anyhow!( + "targz {} does not exist", + libwasmer_cache_path.display() + )); + } + println!("using targz {}", libwasmer_cache_path.display()); + Ok(libwasmer_cache_path) +} diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 8077dd4cc5c..8b9e9a0e555 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -93,117 +93,6 @@ fn test_run_customlambda() { assert.stdout("139583862445\n"); } -fn assert_tarball_is_present_local(target: &str) -> Result { - let wasmer_dir = std::env::var("WASMER_DIR").expect("no WASMER_DIR set"); - let directory = match target { - "aarch64-darwin" => "wasmer-darwin-arm64.tar.gz", - "x86_64-darwin" => "wasmer-darwin-amd64.tar.gz", - "x86_64-linux-gnu" => "wasmer-linux-amd64.tar.gz", - "aarch64-linux-gnu" => "wasmer-linux-aarch64.tar.gz", - "x86_64-windows-gnu" => "wasmer-windows-gnu64.tar.gz", - _ => return Err(anyhow::anyhow!("unknown target {target}")), - }; - let libwasmer_cache_path = Path::new(&wasmer_dir).join("cache").join(directory); - if !libwasmer_cache_path.exists() { - return Err(anyhow::anyhow!( - "targz {} does not exist", - libwasmer_cache_path.display() - )); - } - println!("using targz {}", libwasmer_cache_path.display()); - Ok(libwasmer_cache_path) -} - -// FIXME: Fix and re-enable this test -// See https://github.com/wasmerio/wasmer/issues/3615 -#[test] -#[ignore] -fn test_cross_compile_python_windows() { - let temp_dir = tempfile::TempDir::new().unwrap(); - - #[cfg(not(windows))] - let targets = &[ - "aarch64-darwin", - "x86_64-darwin", - "x86_64-linux-gnu", - "aarch64-linux-gnu", - "x86_64-windows-gnu", - ]; - - #[cfg(windows)] - let targets = &[ - "aarch64-darwin", - "x86_64-darwin", - "x86_64-linux-gnu", - "aarch64-linux-gnu", - ]; - - // MUSL has no support for LLVM in C-API - #[cfg(target_env = "musl")] - let compilers = &["cranelift", "singlepass"]; - #[cfg(not(target_env = "musl"))] - let compilers = &["cranelift", "singlepass", "llvm"]; - - // llvm-objdump --disassemble-all --demangle ./objects/wasmer_vm-50cb118b098c15db.wasmer_vm.60425a0a-cgu.12.rcgu.o - // llvm-objdump --macho --exports-trie ~/.wasmer/cache/wasmer-darwin-arm64/lib/libwasmer.dylib - let excluded_combinations = &[ - ("aarch64-darwin", "llvm"), // LLVM: aarch64 not supported relocation Arm64MovwG0 not supported - ("aarch64-linux-gnu", "llvm"), // LLVM: aarch64 not supported relocation Arm64MovwG0 not supported - // https://github.com/ziglang/zig/issues/13729 - ("x86_64-darwin", "llvm"), // undefined reference to symbol 'wasmer_vm_raise_trap' kind Unknown - ("x86_64-windows-gnu", "llvm"), // unimplemented symbol `wasmer_vm_raise_trap` kind Unknown - ]; - - for t in targets { - for c in compilers { - if excluded_combinations.contains(&(t, c)) { - continue; - } - println!("{t} target {c}"); - let python_wasmer_path = temp_dir.path().join(format!("{t}-python")); - - let tarball = match std::env::var("GITHUB_TOKEN") { - Ok(_) => Some(assert_tarball_is_present_local(t).unwrap()), - Err(_) => None, - }; - let mut cmd = Command::new(get_wasmer_path()); - - cmd.arg("create-exe"); - cmd.arg(wasi_test_python_path()); - cmd.arg("--target"); - cmd.arg(t); - cmd.arg("-o"); - cmd.arg(python_wasmer_path.clone()); - cmd.arg(format!("--{c}")); - if std::env::var("GITHUB_TOKEN").is_ok() { - cmd.arg("--debug-dir"); - cmd.arg(format!("{t}-{c}")); - } - - if t.contains("x86_64") && *c == "singlepass" { - cmd.arg("-m"); - cmd.arg("avx"); - } - - if let Some(t) = tarball { - cmd.arg("--tarball"); - cmd.arg(t); - } - - let assert = cmd.assert().success(); - - if !python_wasmer_path.exists() { - let p = std::fs::read_dir(temp_dir.path()) - .unwrap() - .filter_map(|e| Some(e.ok()?.path())) - .collect::>(); - let output = assert.get_output(); - panic!("target {t} was not compiled correctly tempdir: {p:#?}, {output:?}",); - } - } - } -} - #[test] fn run_whoami_works() { // running test locally: should always pass since