Skip to content

Commit

Permalink
tests/integration/cli: add TARGET path detection to wasmer path
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Jun 16, 2022
1 parent a6173f9 commit 9ebe1c2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
6 changes: 6 additions & 0 deletions tests/integration/cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);
}
57 changes: 54 additions & 3 deletions tests/integration/cli/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,76 @@ pub const WASMER_PATH: &str = concat!(
"/../../../target/release/wasmer"
);

#[cfg(feature = "debug")]
pub const WASMER_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../",
env!("CARGO_CFG_TARGET"),
"/debug/wasmer"
);

/* env var TARGET is set by tests/integration/cli/build.rs on compile-time */

#[cfg(not(feature = "debug"))]
pub const WASMER_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/",
env!("TARGET"),
"/release/wasmer"
);

#[cfg(not(windows))]
pub const LIBWASMER_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/release/libwasmer.a"
);

#[cfg(windows)]
pub const LIBWASMER_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/release/wasmer.lib"
);

#[cfg(not(windows))]
pub const LIBWASMER_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target",
env!("TARGET"),
"/release/libwasmer.a"
);

#[cfg(windows)]
pub const LIBWASMER_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../",
env!("TARGET"),
"/release/wasmer.lib"
);

/// Get the path to the `libwasmer.a` static library.
pub fn get_libwasmer_path() -> PathBuf {
PathBuf::from(
let mut ret = PathBuf::from(
env::var("WASMER_TEST_LIBWASMER_PATH").unwrap_or_else(|_| LIBWASMER_PATH.to_string()),
)
);
if !ret.exists() {
ret = PathBuf::from(LIBWASMER_TARGET_PATH.to_string());
}
if !ret.exists() {
panic!("Could not find libwasmer path! {:?}", ret);
}
ret
}

/// Get the path to the `wasmer` executable to be used in this test.
pub fn get_wasmer_path() -> PathBuf {
PathBuf::from(env::var("WASMER_TEST_WASMER_PATH").unwrap_or_else(|_| WASMER_PATH.to_string()))
let mut ret = PathBuf::from(
env::var("WASMER_TEST_WASMER_PATH").unwrap_or_else(|_| WASMER_PATH.to_string()),
);
if !ret.exists() {
ret = PathBuf::from(WASMER_TARGET_PATH.to_string());
}
if !ret.exists() {
panic!("Could not find wasmer executable path! {:?}", ret);
}
ret
}

0 comments on commit 9ebe1c2

Please sign in to comment.