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

Initial iOS support #83

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions .travis-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e
if [ `uname` = Darwin ]
then
rustup target add x86_64-apple-ios aarch64-apple-ios;
cargo build --target x86_64-apple-ios
cargo build --target aarch64-apple-ios
RUNTIME_ID=$(xcrun simctl list runtimes | grep iOS | cut -d ' ' -f 7 | tail -1)
export SIM_ID=$(xcrun simctl create My-iphone7 com.apple.CoreSimulator.SimDeviceType.iPhone-7 $RUNTIME_ID)
xcrun simctl boot $SIM_ID
cargo install cargo-dinghy
cargo dinghy test --target x86_64-apple-ios
fi
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sudo: false
os:
- linux
- osx
- osx_image: xcode12
rust:
- stable
- nightly
Expand All @@ -23,6 +24,7 @@ before_script:
script:
- travis_wait cargo build --verbose
- cargo test --verbose
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ./.travis-ios.sh; fi

notifications:
email:
Expand Down
45 changes: 43 additions & 2 deletions shaderc-sys/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,34 @@ static SHADERC_SHARED_LIB: &str = "shaderc_shared";
static SHADERC_STATIC_LIB_FILE: &str = "libshaderc_combined.a";
static SHADERC_STATIC_LIB_FILE_MSVC: &str = "shaderc_combined.lib";

fn build_shaderc(shaderc_dir: &PathBuf, use_ninja: bool) -> PathBuf {
fn sdk_path() -> Option<PathBuf> {
let target = std::env::var("TARGET").unwrap();
use std::process::Command;

// tvOS (and the simulator) could be added here in the future.
let sdk = if target == "x86_64-apple-ios" || target == "i386-apple-ios" {
"iphonesimulator"
} else if target == "aarch64-apple-ios"
|| target == "armv7-apple-ios"
|| target == "armv7s-apple-ios"
{
"iphoneos"
} else {
return None;
};

let output = if let Ok(out) = Command::new("xcrun")
.args(&["--sdk", sdk, "--show-sdk-path"])
.output() {
out.stdout
} else {
return None;
};
let prefix_str = std::str::from_utf8(&output).expect("invalid output from `xcrun`");
Some(PathBuf::from(prefix_str.trim_end().to_string()))
}

fn build_shaderc(shaderc_dir: &PathBuf, use_ninja: bool, target_os: String) -> PathBuf {
let mut config = cmake::Config::new(shaderc_dir);
config
.profile("Release")
Expand All @@ -36,6 +63,13 @@ fn build_shaderc(shaderc_dir: &PathBuf, use_ninja: bool) -> PathBuf {
if use_ninja {
config.generator("Ninja");
}

if target_os == "ios" {
if let Some(path) = sdk_path() {
config.define("CMAKE_OSX_SYSROOT", path);
}
}

config.build()
}

Expand Down Expand Up @@ -244,6 +278,13 @@ fn main() {
println!("cargo:rustc-link-lib=dylib=c++");
return;
}
("ios", _) => {
println!("cargo:warning=MacOS static builds experimental");
println!("cargo:rustc-link-search=native={}", search_dir_str);
println!("cargo:rustc-link-lib={}={}", kind, lib_name);
println!("cargo:rustc-link-lib=dylib=c++");
return;
}
(_, _) => {
println!("cargo:warning=Platform unsupported for linking against system installed shaderc libraries");
}
Expand Down Expand Up @@ -274,7 +315,7 @@ fn main() {
build_shaderc_msvc(&shaderc_dir)
} else {
let has_ninja = finder.maybe_have("ninja").is_some();
build_shaderc(&shaderc_dir, has_ninja)
build_shaderc(&shaderc_dir, has_ninja, target_os)
};

lib_path.push("lib");
Expand Down