Skip to content

Commit

Permalink
feat: support for WASM targets, closes #75
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Sep 29, 2023
1 parent 165c59f commit 092907a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ fn add_search_dir<P: AsRef<Path>>(base: P) {
fn system_strategy() -> (PathBuf, bool) {
let lib_dir = PathBuf::from(env::var(ORT_ENV_SYSTEM_LIB_LOCATION).expect("[ort] system strategy requires ORT_LIB_LOCATION env var to be set"));

let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap().to_lowercase();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap().to_lowercase();
let platform_format_lib = |a: &str| {
if target_os.contains("windows") { format!("{}.lib", a) } else { format!("lib{}.a", a) }
Expand Down Expand Up @@ -362,6 +363,15 @@ fn system_strategy() -> (PathBuf, bool) {
}
}

if target_arch == "wasm32" {
for lib in &["webassembly", "providers_js"] {
let lib_path = lib_dir.join(platform_format_lib(&format!("onnxruntime_{lib}")));
if lib_path.exists() {
println!("cargo:rustc-link-lib=static=onnxruntime_{lib}");
}
}
}

let protobuf_build = transform_dep(external_lib_dir.join("protobuf-build"), &profile);
add_search_dir(&protobuf_build);
for lib in ["protobuf-lited", "protobuf-lite", "protobuf"] {
Expand All @@ -379,10 +389,12 @@ fn system_strategy() -> (PathBuf, bool) {
add_search_dir(transform_dep(external_lib_dir.join("google_nsync-build"), &profile));
println!("cargo:rustc-link-lib=static=nsync_cpp");

add_search_dir(transform_dep(external_lib_dir.join("pytorch_cpuinfo-build"), &profile));
add_search_dir(transform_dep(external_lib_dir.join("pytorch_cpuinfo-build").join("deps").join("clog"), &profile));
println!("cargo:rustc-link-lib=static=cpuinfo");
println!("cargo:rustc-link-lib=static=clog");
if target_arch != "wasm32" {
add_search_dir(transform_dep(external_lib_dir.join("pytorch_cpuinfo-build"), &profile));
add_search_dir(transform_dep(external_lib_dir.join("pytorch_cpuinfo-build").join("deps").join("clog"), &profile));
println!("cargo:rustc-link-lib=static=cpuinfo");
println!("cargo:rustc-link-lib=static=clog");
}

add_search_dir(transform_dep(external_lib_dir.join("re2-build"), &profile));
println!("cargo:rustc-link-lib=static=re2");
Expand Down
2 changes: 1 addition & 1 deletion src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub type ortchar = c_ushort;
#[cfg(not(target_os = "windows"))]
pub type ortchar = c_char;

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[cfg(any(target_arch = "x86_64", target_arch = "x86", target_arch = "wasm32"))]
pub type size_t = usize;
#[cfg(all(target_arch = "aarch64", target_os = "windows"))]
pub type size_t = c_ulonglong;
Expand Down

0 comments on commit 092907a

Please sign in to comment.