Skip to content

Commit

Permalink
support iOS (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
HyodaKazuaki authored Apr 15, 2023
1 parent 55bf1ed commit c322c6a
Show file tree
Hide file tree
Showing 5 changed files with 14,931 additions and 0 deletions.
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"),
}
}
}
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

0 comments on commit c322c6a

Please sign in to comment.