Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenable create-exe tests #3531

Merged
merged 22 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ out.txt
wapm.toml
build-capi.tar.gz
build-wasmer.tar.gz
lcov.info
lcov.info
link/
link.tar.gz
4 changes: 2 additions & 2 deletions tests/integration/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ publish = false

[dev-dependencies]
rand = "0.8.5"
tar = "0.4.38"
flate2 = "1.0.24"
target-lexicon = "0.12.4"
pretty_assertions = "1.3.0"
object = "0.30.0"
Expand All @@ -19,6 +17,8 @@ object = "0.30.0"
anyhow = "1"
tempfile = "3"
target-lexicon = "0.12.5"
tar = "0.4.38"
flate2 = "1.0.24"

[features]
default = ["webc_runner"]
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::get_repo_root_path;
use anyhow::bail;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -48,3 +50,39 @@ pub fn run_code(

Ok(output.to_owned())
}

// Take the wasmer/package directory and package it to a .tar.gz tarball
pub fn package_wasmer_to_tarball(tmp_targz_path: &PathBuf) {
if tmp_targz_path.exists() {
return;
}
let root_path = get_repo_root_path().unwrap();
let package_path = root_path.join("package");
if !package_path.exists() {
panic!("package path {} does not exist", package_path.display());
}
println!(
"packaging /package to .tar.gz: {}",
tmp_targz_path.display()
);
package_directory(&package_path, &tmp_targz_path);
println!("packaging done");
println!(
"tmp tar gz path: {} - exists: {:?}",
tmp_targz_path.display(),
tmp_targz_path.exists()
);
}

fn package_directory(in_dir: &PathBuf, out: &PathBuf) {
use flate2::write::GzEncoder;
use flate2::Compression;
use std::fs::File;
let tar = File::create(out).unwrap();
let enc = GzEncoder::new(tar, Compression::none());
let mut a = tar::Builder::new(enc);
a.append_dir_all("bin", in_dir.join("bin")).unwrap();
a.append_dir_all("lib", in_dir.join("lib")).unwrap();
a.append_dir_all("include", in_dir.join("include")).unwrap();
a.finish().unwrap();
}
syrusakbary marked this conversation as resolved.
Show resolved Hide resolved
68 changes: 13 additions & 55 deletions tests/integration/cli/tests/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl WasmerCreateExe {
output.args(self.extra_cli_flags.iter());
output.arg("-o");
output.arg(&self.native_executable_path);
if !self.extra_cli_flags.contains(&"--target".to_string()) {
let tarball_path = get_repo_root_path().unwrap().join("link.tar.gz");
package_wasmer_to_tarball(&tarball_path);
output.arg("--tarball");
output.arg(&tarball_path);
}
let cmd = format!("{:?}", output);

println!("(integration-test) running create-exe: {cmd}");
Expand Down Expand Up @@ -257,14 +263,8 @@ fn test_create_exe_with_precompiled_works_1() {

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_works() -> anyhow::Result<()> {
let temp_dir = tempfile::tempdir()?;
let operating_dir: PathBuf = temp_dir.path().to_owned();
Expand Down Expand Up @@ -301,14 +301,8 @@ fn create_exe_works() -> anyhow::Result<()> {
/// Tests that "-c" and "-- -c" are treated differently
// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_works_multi_command_args_handling() -> anyhow::Result<()> {
let temp_dir = tempfile::tempdir()?;
let operating_dir: PathBuf = temp_dir.path().to_owned();
Expand Down Expand Up @@ -373,14 +367,8 @@ fn create_exe_works_multi_command_args_handling() -> anyhow::Result<()> {

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_works_multi_command() -> anyhow::Result<()> {
let temp_dir = tempfile::tempdir()?;
let operating_dir: PathBuf = temp_dir.path().to_owned();
Expand Down Expand Up @@ -436,14 +424,8 @@ fn create_exe_works_multi_command() -> anyhow::Result<()> {

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_works_with_file() -> anyhow::Result<()> {
let temp_dir = tempfile::tempdir()?;
let operating_dir: PathBuf = temp_dir.path().to_owned();
Expand Down Expand Up @@ -509,12 +491,6 @@ fn create_exe_works_with_file() -> anyhow::Result<()> {
// see https://github.com/wasmerio/wasmer/issues/3459
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_serialized_works() -> anyhow::Result<()> {
let temp_dir = tempfile::tempdir()?;
let operating_dir: PathBuf = temp_dir.path().to_owned();
Expand Down Expand Up @@ -697,42 +673,24 @@ fn create_exe_with_object_input(args: Vec<String>) -> anyhow::Result<()> {

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_with_object_input_default() -> anyhow::Result<()> {
create_exe_with_object_input(vec![])
}

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_with_object_input_symbols() -> anyhow::Result<()> {
create_exe_with_object_input(vec!["--object-format".to_string(), "symbols".to_string()])
}

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
// #[cfg_attr(target_os = "windows", ignore)]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
// Test temporarily ignored during the release of 3.2.0-alpha
// because create-exe links to the old libwasmer.a which expects
// MetadataHeader::VERSION == 1, but we want to upgrade to version 2.
//
// https://github.com/wasmerio/wasmer/issues/3513
#[ignore]
fn create_exe_with_object_input_serialized() -> anyhow::Result<()> {
create_exe_with_object_input(vec![
"--object-format".to_string(),
Expand Down
35 changes: 4 additions & 31 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use anyhow::{bail, Context};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use wasmer_integration_tests_cli::{get_repo_root_path, get_wasmer_path, ASSET_PATH, C_ASSET_PATH};
use wasmer_integration_tests_cli::{
get_wasmer_path, package_wasmer_to_tarball, ASSET_PATH, C_ASSET_PATH,
};

fn wasi_test_python_path() -> PathBuf {
Path::new(C_ASSET_PATH).join("python-0.1.0.wasmer")
Expand Down Expand Up @@ -195,20 +197,6 @@ fn run_wasi_works() -> anyhow::Result<()> {
Ok(())
}

#[cfg(feature = "webc_runner")]
fn package_directory(in_dir: &PathBuf, out: &PathBuf) {
use flate2::write::GzEncoder;
use flate2::Compression;
use std::fs::File;
let tar = File::create(out).unwrap();
let enc = GzEncoder::new(tar, Compression::none());
let mut a = tar::Builder::new(enc);
a.append_dir_all("bin", in_dir.join("bin")).unwrap();
a.append_dir_all("lib", in_dir.join("lib")).unwrap();
a.append_dir_all("include", in_dir.join("include")).unwrap();
a.finish().unwrap();
}

/// TODO: on linux-musl, the packaging of libwasmer.a doesn't work properly
/// Tracked in https://github.com/wasmerio/wasmer/issues/3271
#[cfg(not(any(target_env = "musl", target_os = "windows")))]
Expand All @@ -224,24 +212,9 @@ fn test_wasmer_create_exe_pirita_works() -> anyhow::Result<()> {
let python_exe_output_path = temp_dir.join("python");

let native_target = target_lexicon::HOST;
let root_path = get_repo_root_path().unwrap();
let package_path = root_path.join("package");
if !package_path.exists() {
panic!("package path {} does not exist", package_path.display());
}
let tmp_targz_path = temp_dir.join("link.tar.gz");
package_wasmer_to_tarball(&tmp_targz_path);
println!("compiling to target {native_target}");
println!(
"packaging /package to .tar.gz: {}",
tmp_targz_path.display()
);
package_directory(&package_path, &tmp_targz_path);
println!("packaging done");
println!(
"tmp tar gz path: {} - exists: {:?}",
tmp_targz_path.display(),
tmp_targz_path.exists()
);

let mut cmd = Command::new(get_wasmer_path());
cmd.arg("create-exe");
Expand Down