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 #9

Merged
Merged
6 changes: 6 additions & 0 deletions .github/workflows/gen_bind.yml
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.target.os }}
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jobs:
target: aarch64-apple-darwin
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-ios
- os: macos-latest
target: aarch64-apple-ios-sim
PickledChair marked this conversation as resolved.
Show resolved Hide resolved
- os: macos-latest
target: x86_64-apple-ios
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
56 changes: 49 additions & 7 deletions crates/open_jtalk-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use std::{env, path::Path};
use std::{
env,
path::{Path, PathBuf},
process::Command,
};
fn main() {
let mut cmake_conf = cmake::Config::new("open_jtalk");
let target = env::var("TARGET").unwrap();
let mut include_dirs: Vec<PathBuf> = Vec::new();
let cmake_conf = if target.starts_with("i686") {
let cmake_conf = cmake_conf.define("OPEN_JTALK_X86", "true");

Expand All @@ -26,21 +31,58 @@ fn main() {
cmake_conf.define("CMAKE_SYSTEM_VERSION", "1");
}

// iOS SDKで必要な引数を指定する
if target.contains("ios") {
// iOSとiPhone simulatorは別扱いになる
let sdk = if target.ends_with("sim") || target.starts_with("x86_64") {
"iphonesimulator"
} else {
"iphoneos"
};
let cmake_osx_sysroot = Command::new("xcrun")
.args(["--sdk", sdk, "--show-sdk-path"])
.output()
.expect("Failed to run xcrun command");
let cmake_osx_sysroot = String::from_utf8_lossy(&cmake_osx_sysroot.stdout)
.trim()
.to_string();
cmake_conf.define("CMAKE_OSX_SYSROOT", &cmake_osx_sysroot);
// x86_64アーキテクチャのiPhoneシミュレータではC++のヘッダーのパスが通っていないので、通す
PickledChair marked this conversation as resolved.
Show resolved Hide resolved
if target.starts_with("x86_64") {
let include_dir = PathBuf::from(&cmake_osx_sysroot)
.join("usr")
.join("include")
.join("c++")
.join("v1");
include_dirs.push(include_dir);
}
}

let dst_dir = cmake_conf.build();
let lib_dir = dst_dir.join("lib");
println!("cargo:rustc-link-search={}", lib_dir.display());
println!("cargo:rustc-link-lib=openjtalk");
generate_bindings(dst_dir.join("include"));
generate_bindings(dst_dir.join("include"), include_dirs.iter());
}

#[cfg(not(feature = "generate-bindings"))]
fn generate_bindings(#[allow(unused_variables)] include_dir: impl AsRef<Path>) {}
#[allow(unused_variables)]
fn generate_bindings(
allow_dir: impl AsRef<Path>,
include_dirs: impl Iterator<Item = impl AsRef<Path>>,
) {
}

#[cfg(feature = "generate-bindings")]
fn generate_bindings(include_dir: impl AsRef<Path>) {
use std::path::PathBuf;
let include_dir = include_dir.as_ref();
let clang_args = &[format!("-I{}", include_dir.display())];
fn generate_bindings(
allow_dir: impl AsRef<Path>,
include_dirs: impl Iterator<Item = impl AsRef<Path>>,
) {
let include_dir = allow_dir.as_ref();
let clang_args = include_dirs
.map(|dir| format!("-I{}", dir.as_ref().display()))
.chain([format!("-I{}", include_dir.display())])
.collect::<Vec<_>>();
println!("cargo:rerun-if-changed=wrapper.hpp");
println!("cargo:rerun-if-changed=src/generated/bindings.rs");
let mut bind_builder = bindgen::Builder::default()
Expand Down
12 changes: 12 additions & 0 deletions crates/open_jtalk-sys/src/generated/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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"
));

Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
#[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