Make lucet-wasi-sdk work with a standard LLVM install
@@ -5,6 +5,8 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use tempfile::TempDir;
+const WASI_TARGET: &str = "wasm32-unknown-wasi";
+
#[derive(Debug, Fail)]
pub enum CompileError {
#[fail(display = "File not found: {}", _0)]
@@ -50,6 +52,18 @@ fn wasi_sdk() -> PathBuf {
Path::new(&env::var("WASI_SDK").unwrap_or("/opt/wasi-sdk".to_owned())).to_path_buf()
}
+fn wasi_sysroot() -> PathBuf {
+ match env::var("WASI_SYSROOT") {
+ Ok(wasi_sysroot) => Path::new(&wasi_sysroot).to_path_buf(),
+ Err(_) => {
+ let mut path = wasi_sdk();
+ path.push("share");
+ path.push("sysroot");
+ path
+ }
+ }
+}
+
fn wasm_clang() -> PathBuf {
match env::var("CLANG") {
Ok(clang) => Path::new(&clang).to_path_buf(),
@@ -127,6 +141,8 @@ impl Compile {
))?;
}
let mut cmd = Command::new(clang);
+ cmd.arg(format!("--target={}", WASI_TARGET));
+ cmd.arg(format!("--sysroot={}", wasi_sysroot().display()));
cmd.arg("-c");
cmd.arg(self.input.clone());
cmd.arg("-o");
