diff --git a/build.rs b/build.rs index b50dae3..d999384 100644 --- a/build.rs +++ b/build.rs @@ -316,6 +316,7 @@ fn add_search_dir>(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) } @@ -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"] { @@ -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"); diff --git a/src/sys.rs b/src/sys.rs index 6fe2336..dc05ac9 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -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;