wasmer_integration_tests_cli/
assets.rs1use std::path::PathBuf;
2use std::{env, path::Path};
3
4pub fn test_files_path() -> PathBuf {
5 Path::new(env!("CARGO_MANIFEST_DIR"))
6 .join("..")
7 .join("..")
8 .join("..")
9 .join("wasmer-test-files")
10}
11
12pub fn c_asset_path() -> PathBuf {
13 test_files_path().join("examples")
14}
15
16pub fn integration_wasm_path() -> PathBuf {
17 test_files_path().join("integration/wasm")
18}
19
20pub fn integration_webc_path() -> PathBuf {
21 test_files_path().join("integration/webc")
22}
23
24pub fn compilers_path() -> PathBuf {
25 test_files_path().join("compilers")
26}
27
28pub fn legacy_asset_path() -> PathBuf {
29 test_files_path().join("legacy")
30}
31
32pub fn asset_path() -> &'static Path {
33 Path::new(concat!(
34 env!("CARGO_MANIFEST_DIR"),
35 "/../../../tests/examples/"
36 ))
37}
38
39pub fn wasmer_include_path() -> &'static Path {
40 Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../lib/c-api/"))
41}
42
43pub fn wasmer_target_path() -> &'static Path {
44 let path = if cfg!(feature = "debug") {
45 concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/debug/")
46 } else {
47 concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/release/")
48 };
49 Path::new(path)
50}
51
52pub fn wasmer_target_path_2() -> &'static Path {
53 let path = if cfg!(feature = "debug") {
54 concat!(
55 env!("CARGO_MANIFEST_DIR"),
56 "/../../../target/",
57 env!("CARGO_BUILD_TARGET"),
58 "/debug/"
59 )
60 } else {
61 concat!(
62 env!("CARGO_MANIFEST_DIR"),
63 "/../../../target/",
64 env!("CARGO_BUILD_TARGET"),
65 "/release/"
66 )
67 };
68 Path::new(path)
69}
70
71pub const LIBWASMER_FILENAME: &str = {
74 if cfg!(windows) {
75 "wasmer.lib"
76 } else {
77 "libwasmer.a"
78 }
79};
80
81pub fn get_libwasmer_path() -> PathBuf {
83 let mut ret = env::var("WASMER_TEST_LIBWASMER_PATH")
84 .map(PathBuf::from)
85 .unwrap_or_else(|_| wasmer_target_path().join(LIBWASMER_FILENAME));
86
87 if !ret.exists() {
88 ret = wasmer_target_path_2().join(LIBWASMER_FILENAME);
89 }
90 if !ret.exists() {
91 panic!("Could not find libwasmer path! {ret:?}");
92 }
93 ret
94}
95
96pub fn get_wasmer_path() -> PathBuf {
98 let mut ret = env::var("WASMER_TEST_WASMER_PATH")
99 .map(PathBuf::from)
100 .unwrap_or_else(|_| wasmer_target_path().join("wasmer"));
101
102 if !ret.exists() {
103 ret = wasmer_target_path_2().join("wasmer");
104 }
105 if !ret.exists() {
106 ret = match get_repo_root_path() {
107 Some(s) => {
108 let release_dir = s.join("target").join("release");
109
110 if cfg!(windows) {
111 release_dir.join("wasmer.exe")
112 } else {
113 release_dir.join("wasmer")
114 }
115 }
116 None => {
117 panic!("Could not find wasmer executable path! {ret:?}");
118 }
119 };
120 }
121
122 if !ret.exists() {
123 ret = match get_repo_root_path() {
124 Some(s) => {
125 let executable = if cfg!(windows) {
126 "wasmer.exe"
127 } else {
128 "wasmer"
129 };
130 s.join("target")
131 .join(target_lexicon::HOST.to_string())
132 .join("release")
133 .join(executable)
134 }
135 None => {
136 panic!("Could not find wasmer executable path! {ret:?}");
137 }
138 };
139 }
140
141 if !ret.exists() {
142 if let Some(root) = get_repo_root_path() {
143 use std::process::Stdio;
144 let _ = std::process::Command::new("ls")
145 .arg(root.join("target"))
146 .stdout(Stdio::inherit())
147 .stderr(Stdio::inherit())
148 .stdin(Stdio::null())
149 .output();
150 }
151 panic!(
152 "cannot find wasmer / wasmer.exe for integration test at '{}'!",
153 ret.display()
154 );
155 }
156 ret
157}
158
159pub fn get_repo_root_path() -> Option<PathBuf> {
160 let mut current_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
161 let mut counter = 0;
162 let mut result = None;
163 'outer: while counter < 50 {
164 counter += 1;
165 if current_dir.join("CHANGELOG.md").exists() && current_dir.join("LICENSE").exists() {
166 result = Some(current_dir.to_path_buf());
167 break 'outer;
168 } else {
169 current_dir = current_dir.parent()?;
170 }
171 }
172 result
173}
174
175pub fn get_wasmer_dir() -> Result<PathBuf, anyhow::Error> {
176 if let Ok(s) = std::env::var("WASMER_DIR") {
177 Ok(Path::new(&s).to_path_buf())
178 } else if let Some(root_dir) = get_repo_root_path().and_then(|root| {
179 if root.join("package").exists() {
180 Some(root.join("package"))
181 } else {
182 None
183 }
184 }) {
185 Ok(root_dir)
186 } else {
187 let home_dir = dirs::home_dir()
188 .ok_or(anyhow::anyhow!("no home dir"))?
189 .join(".wasmer");
190 if home_dir.exists() {
191 Ok(home_dir)
192 } else {
193 Err(anyhow::anyhow!("no .wasmer home dir"))
194 }
195 }
196}