fix: wasm docs.rs build

This commit is contained in:
Carson M.
2026-01-20 14:35:24 -06:00
parent 6bdeaaa294
commit f82559a456
6 changed files with 16 additions and 14 deletions

View File

@@ -97,13 +97,15 @@ ort-sys = { version = "=2.0.0-rc.11", path = "ort-sys", default-features = false
smallvec = { version = "1.15", default-features = false, features = [ "const_generics" ] }
ndarray = { version = "0.17", default-features = false, optional = true }
libloading = { version = "0.9", optional = true }
ureq = { version = "3.1", optional = true, default-features = false }
sha2 = { version = "0.10", optional = true }
tracing = { version = "0.1", optional = true, default-features = false }
half = { version = "2.1", default-features = false, optional = true }
num-complex = { version = "0.4", default-features = false, optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ureq = { version = "3.1", optional = true, default-features = false }
sha2 = { version = "0.10", optional = true }
libloading = { version = "0.9", optional = true }
[dev-dependencies]
anyhow = "1.0"
ureq = { version = "3", default-features = false, features = [ "native-tls" ] }

View File

@@ -580,7 +580,7 @@ pub fn init() -> EnvironmentBuilder {
/// and you *must* call `.commit()` on the builder returned by this function.
///
/// [`Session`]: crate::session::Session
#[cfg(feature = "load-dynamic")]
#[cfg(all(feature = "load-dynamic", not(target_arch = "wasm32")))]
#[cfg_attr(docsrs, doc(cfg(feature = "load-dynamic")))]
#[must_use = "commit() must be called in order for the environment to take effect"]
pub fn init_from<P: AsRef<std::path::Path>>(path: P) -> Result<EnvironmentBuilder> {

View File

@@ -450,7 +450,7 @@ pub const CUDNN_DYLIBS: &[&str] = &[
/// let _ = ep::cuda::preload_dylibs(None, Some(cudnn_root));
/// ```
#[cfg_attr(docsrs, doc(cfg(any(feature = "preload-dylibs", feature = "load-dynamic"))))]
#[cfg(feature = "preload-dylibs")]
#[cfg(all(feature = "preload-dylibs", not(target_arch = "wasm32")))]
pub fn preload_dylibs(cuda_root_dir: Option<&std::path::Path>, cudnn_root_dir: Option<&std::path::Path>) -> Result<()> {
use crate::util::preload_dylib;
if let Some(cuda_root_dir) = cuda_root_dir {

View File

@@ -276,7 +276,7 @@ impl core::error::Error for RegisterError {}
#[allow(unused)]
macro_rules! define_ep_register {
($symbol:ident($($id:ident: $type:ty),*) -> $rt:ty) => {
#[cfg(feature = "load-dynamic")]
#[cfg(all(feature = "load-dynamic", not(target_arch = "wasm32")))]
#[allow(non_snake_case)]
let $symbol = unsafe {
let dylib = $crate::G_ORT_LIB.get().expect("dylib not yet initialized");
@@ -291,7 +291,7 @@ macro_rules! define_ep_register {
}
}
};
#[cfg(not(feature = "load-dynamic"))]
#[cfg(not(all(feature = "load-dynamic", not(target_arch = "wasm32"))))]
unsafe extern "C" {
fn $symbol($($id: $type),*) -> $rt;
}

View File

@@ -58,7 +58,7 @@ use core::{ffi::CStr, ptr::NonNull, str};
pub use ort_sys as sys;
#[cfg(feature = "load-dynamic")]
#[cfg(all(feature = "load-dynamic", not(target_arch = "wasm32")))]
pub use self::environment::init_from;
pub(crate) use self::logging::{debug, error, info, trace, warning as warn};
#[cfg(test)]
@@ -76,10 +76,10 @@ pub use self::{
/// the API.
pub const MINOR_VERSION: u32 = ort_sys::ORT_API_VERSION;
#[cfg(feature = "load-dynamic")]
#[cfg(all(feature = "load-dynamic", not(target_arch = "wasm32")))]
pub(crate) static G_ORT_LIB: OnceLock<libloading::Library> = OnceLock::new();
#[cfg(feature = "load-dynamic")]
#[cfg(all(feature = "load-dynamic", not(target_arch = "wasm32")))]
pub(crate) fn load_dylib_from_path(path: &std::path::Path) -> Result<bool> {
let mut inserter = Some(|| -> crate::Result<libloading::Library> {
use core::cmp::Ordering;
@@ -156,19 +156,19 @@ static G_ORT_API: OnceLock<ApiPointer> = OnceLock::new();
/// - Loading the ONNX Runtime dynamic library fails if the `load-dynamic` feature is enabled.
#[inline]
pub fn api() -> &'static ort_sys::OrtApi {
#[cfg(feature = "alternative-backend")]
#[cfg(any(feature = "alternative-backend", target_arch = "wasm32"))]
let ptr = G_ORT_API
.get()
.expect(
"attempted to use `ort` APIs before initializing a backend\nwhen the `alternative-backend` feature is enabled, `ort::set_api` must be called first to configure the `OrtApi` used by the library"
)
.0;
#[cfg(not(feature = "alternative-backend"))]
#[cfg(not(any(feature = "alternative-backend", target_arch = "wasm32")))]
let ptr = G_ORT_API.get_or_init(setup_api).0;
unsafe { ptr.as_ref() }
}
#[cfg(not(feature = "alternative-backend"))]
#[cfg(not(any(feature = "alternative-backend", target_arch = "wasm32")))]
#[cold]
fn setup_api() -> ApiPointer {
#[cfg(feature = "load-dynamic")]

View File

@@ -53,7 +53,7 @@ pub use self::ndarray::ArrayExt;
/// let _ = ort::util::preload_dylib(application_dir.join("DirectML.dll"));
/// ```
#[cfg_attr(docsrs, doc(cfg(any(feature = "preload-dylibs", feature = "load-dynamic"))))]
#[cfg(feature = "preload-dylibs")]
#[cfg(all(feature = "preload-dylibs", not(target_arch = "wasm32")))]
pub fn preload_dylib<P: libloading::AsFilename>(path: P) -> Result<(), libloading::Error> {
let library = unsafe { libloading::Library::new(path) }?;
// Do not run `FreeLibrary` so the library remains in the loaded modules list.