fix(sys): do not require -fapple-link-rtlib

it really is that shrimple
This commit is contained in:
Carson M.
2025-04-20 10:55:08 -05:00
parent d522ef123e
commit 9b316809bf
13 changed files with 29 additions and 51 deletions

View File

@@ -216,40 +216,6 @@ See [Runtime dylib loading](/setup/linking#runtime-dylib-loading) for more infor
### CUDA
`ort` provides binaries for CUDA 12 with cuDNN 9.x only. Make sure the correct version of CUDA & cuDNN are installed and available on the `PATH`.
### CoreML
Statically linking to CoreML (the default behavior when using downloaded binaries) requires an additional Rust flag in order to link properly. You'll need to provide the flag `-C link-arg=-fapple-link-rtlib` to `rustc`. You can do this via a build script, an entry in [`.cargo/config.toml`](https://doc.rust-lang.org/cargo/reference/config.html), or an environment variable.
<Tabs items={['Build script', 'Cargo config', 'Environment variable']}>
<Tabs.Tab title="Build script">
Add the following to the `build.rs` script of any **binary** crate that uses `ort`.
```rust filename="build.rs" copy
fn main() {
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos"))]
println!("cargo:rustc-link-arg=-fapple-link-rtlib");
}
```
Library crates do not need this flag, and the usage of it in a library crate will not transitively apply to any binary crates dependent on it.
</Tabs.Tab>
<Tabs.Tab title="Cargo config">
See [Configuration: Hierarchical structure](https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure) for more information on where the configuration file can be placed.
```toml filename=".cargo/config.toml" copy
[target.aarch64-apple-darwin]
rustflags = ["-Clink-arg=-fapple-link-rtlib"]
[target.x86_64-apple-darwin]
rustflags = ["-Clink-arg=-fapple-link-rtlib"]
```
</Tabs.Tab>
<Tabs.Tab title="Environment variable">
```shell copy
$ RUSTFLAGS="-Clink-arg=-fapple-link-rtlib" cargo build
```
</Tabs.Tab>
</Tabs>
### WebGPU
The WebGPU EP is **experimental** and may produce incorrect results/crashes; these issues should be reported upstream as there's unfortunately nothing we can do about them.

View File

@@ -28,8 +28,5 @@ Recent versions of `ort` require `ndarray` `0.16`, whereas older versions (and t
To fix this, upgrade your `ndarray` dependency to `0.16`; the new release features no breaking changes, although `.into_shape()` is deprecated; see [`ndarray`'s release notes](https://github.com/rust-ndarray/ndarray/releases/tag/0.16.0) for more information.
## Undefined symbols: `___isPlatformVersionAtLeast`, referenced from...
If you run into this issue compiling with CoreML for macOS/iOS, you'll need to add a `rustc` flag to your crate to get it to link properly. See [Execution providers > CoreML](/perf/execution-providers#coreml) for instructions on how to do so.
## Unresolved external symbol `__std_*`
If you encounter these errors when linking on Windows, make sure your Visual Studio 2022 installation is up to date; at least version **17.11** is required when using default pyke binaries.

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-async-gpt2-api"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../", features = [ "fetch-models" ] }

View File

@@ -1,5 +0,0 @@
fn main() {
// Need this for CoreML. See: https://ort.pyke.io/perf/execution-providers#coreml
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-arg=-fapple-link-rtlib");
}

View File

@@ -1,4 +1,5 @@
[package]
publish = false
name = "example-cudarc"
version = "0.1.0"
edition = "2021"

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-custom-ops"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../" }

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-gpt2"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../", features = [ "fetch-models" ] }

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-model-info"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../" }

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-modnet"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../", features = [ "fetch-models" ] }

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-phi-3-vision"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../" }

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-sentence-transformers"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../", features = [ "fetch-models" ] }

View File

@@ -3,7 +3,6 @@ publish = false
name = "example-training"
version = "0.0.0"
edition = "2021"
build = "../build.rs"
[dependencies]
ort = { path = "../../", features = [ "training" ] }

View File

@@ -1,6 +1,7 @@
use std::{
env,
path::{Path, PathBuf}
path::{Path, PathBuf},
process::Command
};
#[allow(unused)]
@@ -144,6 +145,28 @@ fn add_search_dir<P: AsRef<Path>>(base: P) {
}
}
fn macos_rtlib_search_dir() -> Option<String> {
let output = Command::new(std::env::var("CC").unwrap_or_else(|_| "clang".to_string()))
.arg("--print-search-dirs")
.output()
.ok()?;
if !output.status.success() {
return None;
}
let stdout = String::from_utf8_lossy(&output.stdout);
for line in stdout.lines() {
if line.contains("libraries: =") {
let path = line.split('=').nth(1)?;
if !path.is_empty() {
return Some(format!("{path}/lib/darwin"));
}
}
}
None
}
fn static_link_prerequisites(using_pyke_libs: bool) {
let target_triple = env::var("TARGET").unwrap();
@@ -164,6 +187,10 @@ fn static_link_prerequisites(using_pyke_libs: bool) {
if target_triple.contains("apple") {
println!("cargo:rustc-link-lib=framework=Foundation");
if let Some(dir) = macos_rtlib_search_dir() {
println!("cargo:rustc-link-search={dir}");
println!("cargo:rustc-link-lib=clang_rt.osx");
}
}
if target_triple.contains("windows") && using_pyke_libs {
println!("cargo:rustc-link-lib=dxguid");