Skip to content

Commit

Permalink
wasm works
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Nov 9, 2023
1 parent c74c1ba commit 3b26b0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
31 changes: 21 additions & 10 deletions src/codegen/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,19 @@ impl Compiler {
let enzyme_lib = Compiler::find_enzyme_lib()?;
let out = self.borrow_output_base_filename();
let object_filename = Compiler::get_object_filename(out);

let pre_enzyme_bitcodefilename = Compiler::get_pre_enzyme_bitcode_filename(out);
let output = Command::new(clang_name)
.arg(pre_enzyme_bitcodefilename.as_str())
let bitcodefilename = Compiler::get_bitcode_filename(out);
let mut command = Command::new(clang_name);
command.arg(bitcodefilename.as_str())
.arg("-c")
.arg(format!("-fplugin={}", enzyme_lib))
.arg("-o").arg(object_filename.as_str())
.output()?;
.arg("-o").arg(object_filename.as_str());

if wasm {
command.arg("-target").arg("wasm32-unknown-emscripten");
}

let output = command.output().unwrap();


if let Some(code) = output.status.code() {
if code != 0 {
Expand All @@ -200,7 +205,7 @@ impl Compiler {
}

// link the object file and our runtime library
let output = if wasm {
let mut command = if wasm {
let emcc_varients = ["emcc"];
let command_name = find_executable(&emcc_varients)?;
let exported_functions = vec![
Expand Down Expand Up @@ -237,27 +242,33 @@ impl Compiler {
command.arg("-s").arg(format!("EXPORTED_FUNCTIONS={}", exported_functions));
command.arg("--no-entry");
}
command.output()
command
} else {
let mut command = Command::new(clang_name);
command.arg("-o").arg(out).arg(out);
command.arg("-o").arg(out).arg(object_filename.as_str());
if standalone {
command.arg("-ldiffeq_runtime");
} else {
command.arg("-ldiffeq_runtime_lib");
}
command.output()
command
};

let output = command.output();

let output = match output {
Ok(output) => output,
Err(e) => {
let args = command.get_args().map(|s| s.to_str().unwrap()).collect::<Vec<_>>().join(" ");
println!("{} {}", command.get_program().to_os_string().to_str().unwrap(), args);
return Err(anyhow!("Error linking in runtime: {}", e));
}
};

if let Some(code) = output.status.code() {
if code != 0 {
let args = command.get_args().map(|s| s.to_str().unwrap()).collect::<Vec<_>>().join(" ");
println!("{} {}", command.get_program().to_os_string().to_str().unwrap(), args);
println!("{}", String::from_utf8_lossy(&output.stderr));
return Err(anyhow!("Error linking in runtime, returned error code {}", code));
}
Expand Down
1 change: 0 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub fn find_runtime_path(libraries: &[&str] ) -> Result<String> {
let mut found = true;
for library in libraries {
let library_path = Path::new(path).join(library);
println!("Checking {:?}", library_path);
if !library_path.exists() {
found = false;
break;
Expand Down

0 comments on commit 3b26b0c

Please sign in to comment.