From b88f17ed425c339d016ea5333fab2be3d8ff31fa Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 9 Jan 2022 10:53:58 +0800 Subject: [PATCH] switch to clang-unwrapped, build IRRT with wasm32 --- flake.nix | 2 +- nac3core/build.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 5a51737b..1701e0c7 100644 --- a/flake.nix +++ b/flake.nix @@ -177,7 +177,7 @@ name = "nac3-dev-shell"; buildInputs = with pkgs; [ packages.x86_64-linux.llvm-nac3 - clang_13 + llvmPackages_13.clang-unwrapped # for IRRT lld_13 cargo cargo-insta diff --git a/nac3core/build.rs b/nac3core/build.rs index c4dcfc8e..c3bff8eb 100644 --- a/nac3core/build.rs +++ b/nac3core/build.rs @@ -6,10 +6,16 @@ use std::{ }; fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); const FILE: &str = "src/codegen/irrt/irrt.c"; println!("cargo:rerun-if-changed={}", FILE); + + /* + * HACK: Sadly, clang doesn't let us emit generic LLVM bitcode. + * Compiling for WASM32 and filtering the output with regex is the closest we can get. + */ + const FLAG: &[&str] = &[ + "--target=wasm32", FILE, "-O3", "-emit-llvm", @@ -46,7 +52,7 @@ fn main() { let mut llvm_as = Command::new("llvm-as") .stdin(Stdio::piped()) .arg("-o") - .arg(&format!("{}/irrt.bc", out_dir)) + .arg(&format!("{}/irrt.bc", env::var("OUT_DIR").unwrap())) .spawn() .unwrap(); llvm_as.stdin.as_mut().unwrap().write_all(filtered_output.as_bytes()).unwrap();