Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support iOS #19

Merged
merged 22 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/gen_bind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
triple: x86_64-apple-darwin
- os: macos-latest
triple: aarch64-apple-darwin
- os: macos-latest
triple: aarch64-apple-ios
- os: macos-latest
triple: aarch64-apple-ios-sim
- os: macos-latest
triple: x86_64-apple-ios
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
31 changes: 31 additions & 0 deletions onnxruntime-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const ORT_RELEASE_BASE_URL: &str = "https://github.com/microsoft/onnxruntime/rel
const ORT_MAVEN_RELEASE_BASE_URL: &str =
"https://repo1.maven.org/maven2/com/microsoft/onnxruntime/onnxruntime-android";

/// Base Url from which to download ios pre-build releases/
const ORT_IOS_RELEASE_BASE_URL: &str =
"https://github.com/VOICEVOX/onnxruntime-builder/releases/download";

/// onnxruntime repository/
const ORT_REPOSITORY_URL: &str = "https://github.com/microsoft/onnxruntime.git";

/// Environment variable selecting which strategy to use for finding the library
/// Possibilities:
/// * "download": Download a pre-built library from upstream. This is the default if `ORT_STRATEGY` is not set.
Expand Down Expand Up @@ -382,6 +389,7 @@ enum Os {
Linux,
MacOs,
Android,
IOs,
}

impl Os {
Expand All @@ -391,6 +399,7 @@ impl Os {
Os::Linux => "tgz",
Os::MacOs => "tgz",
Os::Android => "aar",
Os::IOs => "tgz",
}
}
}
Expand All @@ -404,6 +413,7 @@ impl FromStr for Os {
"macos" => Ok(Os::MacOs),
"linux" => Ok(Os::Linux),
"android" => Ok(Os::Android),
"ios" => Ok(Os::IOs),
_ => Err(format!("Unsupported os: {}", s)),
}
}
Expand All @@ -416,6 +426,7 @@ impl OnnxPrebuiltArchive for Os {
Os::Linux => Cow::from("linux"),
Os::MacOs => Cow::from("osx"),
Os::Android => Cow::from("android"),
Os::IOs => Cow::from("ios"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rustの命名規則だとIosの方がいいんですが、2行上でnbigaouette氏(オリジナルのonnxruntime-rsの作者)がMacOsと書いちゃっているので統一感のためにここは致し方なし...?

In UpperCamelCase, acronyms and contractions of compound words count as one word

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的には仕方ないかなと思いました・・・!
本当はMacosが良いんだろうなとも思います。が、まあ直しちゃうとコンフリクトが出てしまうので・・・ 😇

}
}
}
Expand Down Expand Up @@ -489,6 +500,22 @@ impl OnnxPrebuiltArchive for Triplet {
"x64",
self.accelerator.as_onnx_str(),
)),
// onnxruntime-ios-arm64-1.8.1.tgz
// Note aarch64 simulator have a '-sim' in the target, but x86_64 does not; both have '-sim' for onnxruntime
(Os::IOs, Architecture::Arm64, Accelerator::None) => {
let os = if env::var("TARGET").unwrap().ends_with("sim") {
format!("{}-sim", self.os.as_onnx_str())
} else {
format!("{}", self.os.as_onnx_str())
};
Cow::from(format!("{}-{}", os, "arm64"))
}
// onnxruntime-ios-sim-x86_64-1.8.1.tgz
(Os::IOs, Architecture::X86_64, Accelerator::None) => Cow::from(format!(
"{}-sim-{}",
self.os.as_onnx_str(),
self.arch.as_onnx_str()
)),
_ => {
panic!(
"Unsupported prebuilt triplet: {:?}, {:?}, {:?}. Please use {}=system and {}=/path/to/onnxruntime",
Expand Down Expand Up @@ -521,6 +548,10 @@ fn prebuilt_archive_url() -> (PathBuf, String) {
ORT_VERSION,
TRIPLET.os.archive_extension()
),
Os::IOs => format!(
"{}/{}/{}",
ORT_IOS_RELEASE_BASE_URL, ORT_VERSION, prebuilt_archive
),
_ => format!(
"{}/v{}/{}",
ORT_RELEASE_BASE_URL, ORT_VERSION, prebuilt_archive
Expand Down
12 changes: 12 additions & 0 deletions onnxruntime-sys/src/generated/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ include!(concat!(
"/src/generated/macos/aarch64/bindings.rs"
));

#[cfg(all(target_os = "ios", target_arch = "aarch64"))]
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/generated/ios/aarch64/bindings.rs"
));

#[cfg(all(target_os = "ios", target_arch = "x86_64"))]
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/generated/ios/x86_64/bindings.rs"
));

#[cfg(all(target_os = "windows", target_arch = "x86"))]
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
Expand Down
Loading