Skip to content

Commit

Permalink
enable llvm-jit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lum1n0us committed Feb 7, 2024
1 parent 91073df commit 2eac9b9
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 13 deletions.
1 change: 1 addition & 0 deletions language-bindings/rust/crates/wamr-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.0"
edition = "2021"
license = "Apache-2.0 WITH LLVM-exception"
authors = ["Sven Pfennig <s.pfennig@reply.de>"]
links = "vmlib"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
112 changes: 99 additions & 13 deletions language-bindings/rust/crates/wamr-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ extern crate bindgen;
extern crate cmake;

use cmake::Config;
use std::{env, path::PathBuf};
use std::{env, path::Path, path::PathBuf};

fn main() {
let wamr_root = "../../../../";
let llvm_dir = format!("{wamr_root}core/deps/llvm/build");
let dst = Config::new(wamr_root)
.define("LLVM_DIR", llvm_dir)
let wamr_root = Path::new("../../../../").canonicalize().unwrap();
assert!(wamr_root.exists());

let llvm_dir = wamr_root.join("core/deps/llvm/build");
assert!(llvm_dir.exists());

let dst = Config::new(&wamr_root)
// running mode
.define("WAMR_BUILD_AOT", "1")
.define("WAMR_BUILD_INTERP", "1")
.define("WAMR_BUILD_FAST_INTERP", "1")
// .define("WAMR_BUILD_JIT", "1")
.define("WAMR_BUILD_JIT", "1")
// mvp
.define("WAMR_BUILD_BULK_MEMORY", "1")
.define("WAMR_BUILD_REF_TYPES", "1")
Expand All @@ -26,19 +30,101 @@ fn main() {
.define("WAMR_BUILD_LIBC_WASI", "1")
// `nostdlib`
.define("WAMR_BUILD_LIBC_BUILTIN", "1")
.build_target("iwasm_static")
.build();

println!(
"cargo:rustc-link-search=native={}",
dst.join("build").display()
);
println!("cargo:rustc-link-lib=vmlib");
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=static=vmlib");

// //TODO: support macos?
println!("cargo:rustc-link-lib=dylib=dl");
println!("cargo:rustc-link-lib=dylib=m");
println!("cargo:rustc-link-lib=dylib=rt");
println!("cargo:rustc-link-lib=dylib=stdc++");
println!("cargo:rustc-link-lib=dylib=z");

println!("cargo:libdir={}/lib", llvm_dir.display());
println!("cargo:rustc-link-search=native={}/lib", llvm_dir.display());
println!("cargo:rustc-link-lib=static=LLVMXRay");
println!("cargo:rustc-link-lib=static=LLVMLibDriver");
println!("cargo:rustc-link-lib=static=LLVMDlltoolDriver");
println!("cargo:rustc-link-lib=static=LLVMCoverage");
println!("cargo:rustc-link-lib=static=LLVMLineEditor");
println!("cargo:rustc-link-lib=static=LLVMX86Disassembler");
println!("cargo:rustc-link-lib=static=LLVMX86AsmParser");
println!("cargo:rustc-link-lib=static=LLVMX86CodeGen");
println!("cargo:rustc-link-lib=static=LLVMX86Desc");
println!("cargo:rustc-link-lib=static=LLVMX86Info");
println!("cargo:rustc-link-lib=static=LLVMOrcJIT");
println!("cargo:rustc-link-lib=static=LLVMMCJIT");
println!("cargo:rustc-link-lib=static=LLVMJITLink");
println!("cargo:rustc-link-lib=static=LLVMInterpreter");
println!("cargo:rustc-link-lib=static=LLVMExecutionEngine");
println!("cargo:rustc-link-lib=static=LLVMRuntimeDyld");
println!("cargo:rustc-link-lib=static=LLVMOrcTargetProcess");
println!("cargo:rustc-link-lib=static=LLVMOrcShared");
println!("cargo:rustc-link-lib=static=LLVMDWP");
println!("cargo:rustc-link-lib=static=LLVMSymbolize");
println!("cargo:rustc-link-lib=static=LLVMDebugInfoPDB");
println!("cargo:rustc-link-lib=static=LLVMDebugInfoGSYM");
println!("cargo:rustc-link-lib=static=LLVMOption");
println!("cargo:rustc-link-lib=static=LLVMObjectYAML");
println!("cargo:rustc-link-lib=static=LLVMMCA");
println!("cargo:rustc-link-lib=static=LLVMMCDisassembler");
println!("cargo:rustc-link-lib=static=LLVMLTO");
println!("cargo:rustc-link-lib=static=LLVMPasses");
println!("cargo:rustc-link-lib=static=LLVMCFGuard");
println!("cargo:rustc-link-lib=static=LLVMCoroutines");
println!("cargo:rustc-link-lib=static=LLVMObjCARCOpts");
println!("cargo:rustc-link-lib=static=LLVMipo");
println!("cargo:rustc-link-lib=static=LLVMVectorize");
println!("cargo:rustc-link-lib=static=LLVMLinker");
println!("cargo:rustc-link-lib=static=LLVMInstrumentation");
println!("cargo:rustc-link-lib=static=LLVMFrontendOpenMP");
println!("cargo:rustc-link-lib=static=LLVMFrontendOpenACC");
println!("cargo:rustc-link-lib=static=LLVMExtensions");
println!("cargo:rustc-link-lib=static=LLVMDWARFLinker");
println!("cargo:rustc-link-lib=static=LLVMGlobalISel");
println!("cargo:rustc-link-lib=static=LLVMMIRParser");
println!("cargo:rustc-link-lib=static=LLVMAsmPrinter");
println!("cargo:rustc-link-lib=static=LLVMDebugInfoMSF");
println!("cargo:rustc-link-lib=static=LLVMDebugInfoDWARF");
println!("cargo:rustc-link-lib=static=LLVMSelectionDAG");
println!("cargo:rustc-link-lib=static=LLVMCodeGen");
println!("cargo:rustc-link-lib=static=LLVMIRReader");
println!("cargo:rustc-link-lib=static=LLVMAsmParser");
println!("cargo:rustc-link-lib=static=LLVMInterfaceStub");
println!("cargo:rustc-link-lib=static=LLVMFileCheck");
println!("cargo:rustc-link-lib=static=LLVMFuzzMutate");
println!("cargo:rustc-link-lib=static=LLVMTarget");
println!("cargo:rustc-link-lib=static=LLVMScalarOpts");
println!("cargo:rustc-link-lib=static=LLVMInstCombine");
println!("cargo:rustc-link-lib=static=LLVMAggressiveInstCombine");
println!("cargo:rustc-link-lib=static=LLVMTransformUtils");
println!("cargo:rustc-link-lib=static=LLVMBitWriter");
println!("cargo:rustc-link-lib=static=LLVMAnalysis");
println!("cargo:rustc-link-lib=static=LLVMProfileData");
println!("cargo:rustc-link-lib=static=LLVMObject");
println!("cargo:rustc-link-lib=static=LLVMTextAPI");
println!("cargo:rustc-link-lib=static=LLVMMCParser");
println!("cargo:rustc-link-lib=static=LLVMMC");
println!("cargo:rustc-link-lib=static=LLVMDebugInfoCodeView");
println!("cargo:rustc-link-lib=static=LLVMBitReader");
println!("cargo:rustc-link-lib=static=LLVMCore");
println!("cargo:rustc-link-lib=static=LLVMRemarks");
println!("cargo:rustc-link-lib=static=LLVMBitstreamReader");
println!("cargo:rustc-link-lib=static=LLVMBinaryFormat");
println!("cargo:rustc-link-lib=static=LLVMTableGen");
println!("cargo:rustc-link-lib=static=LLVMSupport");
println!("cargo:rustc-link-lib=static=LLVMDemangle");

let wamr_header = wamr_root.join("core/iwasm/include/wasm_export.h");
assert!(wamr_header.exists());

let wamr_header = format!("{wamr_root}core/iwasm/include/wasm_export.h");
let bindings = bindgen::Builder::default()
.ctypes_prefix("::core::ffi")
.use_core()
.header(wamr_header)
.header(wamr_header.into_os_string().into_string().unwrap())
.derive_default(true)
.generate()
.expect("Unable to generate bindings");
Expand Down

0 comments on commit 2eac9b9

Please sign in to comment.