diff --git a/Cargo.toml b/Cargo.toml index ff8fddf..efc7183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,12 +21,10 @@ strip = true codegen-units = 1 [package.metadata.docs.rs] -features = [ "half", "fetch-models", "copy-dylibs", "disable-build-script" ] +features = [ "half", "fetch-models", "copy-dylibs" ] [features] default = [ "half", "fetch-models", "copy-dylibs" ] -# used to prevent issues with docs.rs -disable-build-script = [] profiling = [ "widestring" ] @@ -35,9 +33,6 @@ generate-bindings = [ "bindgen" ] copy-dylibs = [] # ONNX compile flags -prefer-compile-strategy = [] -prefer-system-strategy = [] -prefer-dynamic-libs = [] minimal-build = [] experimental = [] mimalloc = [] diff --git a/README.md b/README.md index b2f1252..68c0676 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,7 @@ See [the docs](https://docs.rs/ort) and [`examples/`](https://github.com/pykeio/ - `fetch-models`: Enables fetching models from the ONNX Model Zoo; not recommended for production. - `generate-bindings`: Update/generate ONNX Runtime bindings with `bindgen`. Requires [libclang](https://clang.llvm.org/doxygen/group__CINDEX.html). - `copy-dylibs`: Copy dynamic libraries to the Cargo `target` folder. -- `prefer-system-strategy`: Uses the `system` compile [strategy](#strategies) by default; requires users to provide ONNX Runtime libraries. - - `prefer-dynamic-libs`: By default, if the path pointed to by `ORT_LIB_LOCATION` contains static libraries, `ort` will link to them rather than dynamic libraries. This feature prefers linking to dynamic libraries instead. -- `prefer-compile-strategy`: Uses the `compile` [strategy](#strategies) by default; will take a *very* long time, but allows for easy static linking, avoiding [the DLL hell](#shared-library-hell). - - *These features only apply when using the compile strategy:* +- **Compile strategy features** - *These features only apply when using the compile strategy.* - `compile-static`: Compiles ONNX Runtime as a static library. - `mimalloc`: Uses the (usually) faster mimalloc memory allocation library instead of the platform default. - `experimental`: Compiles Microsoft experimental operators. diff --git a/build.rs b/build.rs index 116ea15..60e2b12 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,4 @@ -#![allow(dead_code)] +#![allow(unused)] use std::{ borrow::Cow, @@ -312,10 +312,7 @@ fn prepare_libort_dir() -> (PathBuf, bool) { println!("cargo:rerun-if-env-changed={}", ORT_ENV_STRATEGY); - match strategy - .as_ref() - .map_or_else(|_| if cfg!(feature = "prefer-compile-strategy") { "compile" } else { "download" }, String::as_str) - { + match strategy.as_ref().map_or("download", String::as_str) { "download" => { if target.contains("macos") { incompatible_providers![cuda, onednn, openvino, openmp, vitis_ai, tvm, tensorrt, migraphx, directml, winml, acl, armnn, rocm]; @@ -498,12 +495,6 @@ fn prepare_libort_dir() -> (PathBuf, bool) { } } -#[cfg(not(feature = "generate-bindings"))] -fn generate_bindings(_include_dir: &Path) { - println!("[ort] bindings not generated automatically; using committed bindings instead."); - println!("[ort] enable the `generate-bindings` feature to generate fresh bindings."); -} - #[cfg(feature = "generate-bindings")] fn generate_bindings(include_dir: &Path) { let clang_args = &[ @@ -538,23 +529,22 @@ fn generate_bindings(include_dir: &Path) { bindings.write_to_file(&generated_file).expect("Couldn't write bindings!"); } -#[cfg(feature = "disable-build-script")] -fn main() {} - -#[cfg(not(feature = "disable-build-script"))] fn main() { - let (install_dir, needs_link) = prepare_libort_dir(); + if !std::env::var("DOCS_RS").is_ok() { + let (install_dir, needs_link) = prepare_libort_dir(); - let include_dir = install_dir.join("include"); - let lib_dir = install_dir.join("lib"); + let include_dir = install_dir.join("include"); + let lib_dir = install_dir.join("lib"); - if needs_link { - println!("cargo:rustc-link-lib=onnxruntime"); - println!("cargo:rustc-link-search=native={}", lib_dir.display()); + if needs_link { + println!("cargo:rustc-link-lib=onnxruntime"); + println!("cargo:rustc-link-search=native={}", lib_dir.display()); + } + + println!("cargo:rerun-if-env-changed={}", ORT_ENV_STRATEGY); + println!("cargo:rerun-if-env-changed={}", ORT_ENV_SYSTEM_LIB_LOCATION); + + #[cfg(feature = "generate-bindings")] + generate_bindings(&include_dir); } - - println!("cargo:rerun-if-env-changed={}", ORT_ENV_STRATEGY); - println!("cargo:rerun-if-env-changed={}", ORT_ENV_SYSTEM_LIB_LOCATION); - - generate_bindings(&include_dir); }