2019-06-26 00:37:46 +10:00
|
|
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
|
|
|
mod mac {
|
2020-11-10 07:31:47 +11:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
// MoltenVK git tagged release to use
|
2020-11-14 09:10:57 +11:00
|
|
|
pub static VERSION: &str = "1.1.0";
|
2019-06-26 00:37:46 +10:00
|
|
|
|
|
|
|
// Features are not used inside build scripts, so we have to explicitly query them from the
|
|
|
|
// enviroment
|
2020-11-14 09:10:57 +11:00
|
|
|
pub(crate) fn is_feature_enabled(feature: &str) -> bool {
|
2019-06-26 00:37:46 +10:00
|
|
|
std::env::vars()
|
|
|
|
.filter_map(|(flag, _)| {
|
2020-03-23 21:53:19 +11:00
|
|
|
const NAME: &str = "CARGO_FEATURE_";
|
2019-06-26 00:37:46 +10:00
|
|
|
if flag.starts_with(NAME) {
|
|
|
|
let feature = flag.split(NAME).nth(1).expect("").to_string();
|
|
|
|
println!("{:?}", feature);
|
|
|
|
return Some(feature);
|
|
|
|
}
|
|
|
|
None
|
|
|
|
})
|
2020-11-14 09:10:57 +11:00
|
|
|
.any(|f| f == feature)
|
2019-06-26 00:37:46 +10:00
|
|
|
}
|
|
|
|
|
2020-11-10 07:31:47 +11:00
|
|
|
pub(crate) fn build_molten<P: AsRef<Path>>(_target_dir: &P) -> &'static str {
|
2019-06-26 00:37:46 +10:00
|
|
|
use std::{
|
|
|
|
process::Command,
|
|
|
|
sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-29 02:46:57 +11:00
|
|
|
let checkout_dir = Path::new(&std::env::var("OUT_DIR").expect("Couldn't find OUT_DIR"))
|
2020-11-14 09:10:57 +11:00
|
|
|
.join(format!("MoltenVK-{}", VERSION));
|
2019-06-26 02:46:31 +10:00
|
|
|
|
2019-06-26 00:37:46 +10:00
|
|
|
let exit = Arc::new(AtomicBool::new(false));
|
|
|
|
let wants_exit = exit.clone();
|
|
|
|
|
|
|
|
// Periodically emit log messages so that Travis doesn't make a sad
|
|
|
|
let handle = std::thread::spawn(move || {
|
|
|
|
let mut counter = 0;
|
|
|
|
while !wants_exit.load(Ordering::Acquire) {
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
|
|
counter += 100;
|
|
|
|
|
|
|
|
if counter >= 30 * 1000 {
|
|
|
|
counter = 0;
|
|
|
|
println!("still building MoltenVK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-29 08:41:11 +10:00
|
|
|
let git_status = if Path::new(&checkout_dir).exists() {
|
2019-06-26 00:37:46 +10:00
|
|
|
Command::new("git")
|
2019-06-29 08:41:11 +10:00
|
|
|
.current_dir(&checkout_dir)
|
2019-06-26 00:37:46 +10:00
|
|
|
.arg("pull")
|
|
|
|
.spawn()
|
|
|
|
.expect("failed to spawn git")
|
|
|
|
.wait()
|
|
|
|
.expect("failed to pull MoltenVK")
|
2019-06-21 18:44:36 +10:00
|
|
|
} else {
|
2019-06-26 00:37:46 +10:00
|
|
|
Command::new("git")
|
|
|
|
.arg("clone")
|
2019-10-29 02:46:57 +11:00
|
|
|
.arg("--branch")
|
2020-11-14 09:10:57 +11:00
|
|
|
.arg(format!("v{}", VERSION.to_owned()))
|
2019-10-29 02:46:57 +11:00
|
|
|
.arg("--depth")
|
|
|
|
.arg("1")
|
2019-06-26 00:37:46 +10:00
|
|
|
.arg("https://github.com/KhronosGroup/MoltenVK.git")
|
2019-06-29 08:41:11 +10:00
|
|
|
.arg(&checkout_dir)
|
2019-06-26 00:37:46 +10:00
|
|
|
.spawn()
|
|
|
|
.expect("failed to spawn git")
|
|
|
|
.wait()
|
|
|
|
.expect("failed to clone MoltenVK")
|
|
|
|
};
|
|
|
|
|
2020-11-10 07:31:47 +11:00
|
|
|
assert!(git_status.success(), "failed to get MoltenVK");
|
2019-06-26 00:37:46 +10:00
|
|
|
|
|
|
|
// These (currently) match the identifiers used by moltenvk
|
2020-11-10 07:31:47 +11:00
|
|
|
let (target_name, _dir) = match std::env::var("CARGO_CFG_TARGET_OS") {
|
2019-06-26 00:37:46 +10:00
|
|
|
Ok(target) => match target.as_ref() {
|
|
|
|
"macos" => ("macos", "macOS"),
|
|
|
|
"ios" => ("ios", "iOS"),
|
|
|
|
target => panic!("unknown target '{}'", target),
|
|
|
|
},
|
|
|
|
Err(e) => panic!("failed to determinte target os '{}'", e),
|
|
|
|
};
|
|
|
|
|
2020-11-10 07:31:47 +11:00
|
|
|
let status = Command::new("sh")
|
2019-06-29 08:41:11 +10:00
|
|
|
.current_dir(&checkout_dir)
|
2020-11-10 07:31:47 +11:00
|
|
|
.arg("fetchDependencies")
|
|
|
|
.arg(format!("--{}", target_name))
|
2019-06-26 00:37:46 +10:00
|
|
|
.spawn()
|
|
|
|
.expect("failed to spawn fetchDependencies")
|
|
|
|
.wait()
|
|
|
|
.expect("failed to fetchDependencies");
|
|
|
|
|
|
|
|
assert!(status.success(), "failed to fetchDependencies");
|
|
|
|
|
2020-11-10 07:31:47 +11:00
|
|
|
let status = Command::new("make")
|
|
|
|
.current_dir(&checkout_dir)
|
2020-11-10 22:42:12 +11:00
|
|
|
.arg(target_name)
|
2020-11-10 07:31:47 +11:00
|
|
|
.spawn()
|
|
|
|
.expect("failed to build MoltenVK")
|
|
|
|
.wait()
|
|
|
|
.expect("failed to build MoltenVK");
|
2019-06-26 00:37:46 +10:00
|
|
|
|
2020-11-10 07:31:47 +11:00
|
|
|
assert!(status.success(), "failed to build MoltenVK");
|
2019-06-26 00:37:46 +10:00
|
|
|
|
|
|
|
exit.store(true, Ordering::Release);
|
|
|
|
handle.join().unwrap();
|
|
|
|
target_name
|
|
|
|
}
|
2020-11-14 09:10:57 +11:00
|
|
|
|
|
|
|
pub(crate) fn download_prebuilt_molten<P: AsRef<Path>>(target_dir: &P) {
|
|
|
|
use std::process::{Command, Stdio};
|
|
|
|
|
|
|
|
std::fs::create_dir_all(&target_dir).expect("Couldn't create directory");
|
|
|
|
|
2020-11-15 09:56:28 +11:00
|
|
|
let previous_path = std::env::current_dir().expect("Couldn't get current directory");
|
|
|
|
|
2020-11-14 09:10:57 +11:00
|
|
|
std::env::set_current_dir(&target_dir).expect("Couldn't change current directory");
|
|
|
|
|
|
|
|
let curl = Command::new("curl")
|
|
|
|
.arg("-s")
|
|
|
|
.arg(format!(
|
|
|
|
"https://api.github.com/repos/EmbarkStudios/ash-molten/releases/tags/MoltenVK-{}",
|
|
|
|
VERSION
|
|
|
|
))
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("Couldn't launch curl");
|
|
|
|
|
|
|
|
let curl_out = curl.stdout.expect("Failed to open curl stdout");
|
|
|
|
|
|
|
|
let grep = Command::new("grep")
|
|
|
|
.arg("browser_download_url.*zip")
|
|
|
|
.stdin(Stdio::from(curl_out))
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("Couldn't launch grep");
|
|
|
|
|
|
|
|
let grep_out = grep.stdout.expect("Failed to open grep stdout");
|
|
|
|
|
|
|
|
let cut = Command::new("cut")
|
|
|
|
.args(&["-d", ":", "-f", "2,3"])
|
|
|
|
.stdin(Stdio::from(grep_out))
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("Couldn't launch cut");
|
|
|
|
|
|
|
|
let cut_out = cut.stdout.expect("Failed to open grep stdout");
|
|
|
|
|
|
|
|
let tr = Command::new("tr")
|
|
|
|
.args(&["-d", "\""])
|
|
|
|
.stdin(Stdio::from(cut_out))
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("Couldn't launch cut");
|
|
|
|
|
|
|
|
let tr_out = tr.stdout.expect("Failed to open grep stdout");
|
|
|
|
|
|
|
|
let output = Command::new("xargs")
|
|
|
|
.args(&["-n", "1", "curl", "-LO", "--silent"])
|
|
|
|
.stdin(Stdio::from(tr_out))
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("Couldn't launch cut")
|
|
|
|
.wait_with_output()
|
|
|
|
.expect("failed to wait on xargs");
|
|
|
|
|
|
|
|
assert!(output.status.success());
|
|
|
|
|
|
|
|
for path in std::fs::read_dir(&target_dir).expect("Couldn't read dir") {
|
|
|
|
let path = path.unwrap().path();
|
|
|
|
if let Some("zip") = path.extension().and_then(std::ffi::OsStr::to_str) {
|
|
|
|
let status = Command::new("unzip")
|
|
|
|
.arg("-o")
|
|
|
|
.arg(path.to_owned())
|
|
|
|
.arg("-x")
|
|
|
|
.arg("__MACOSX/*")
|
|
|
|
.spawn()
|
|
|
|
.expect("Couldn't launch unzip")
|
|
|
|
.wait()
|
|
|
|
.expect("failed to wait on unzip");
|
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
}
|
2020-11-15 09:56:28 +11:00
|
|
|
|
|
|
|
std::env::set_current_dir(&previous_path).expect("Couldn't change current directory");
|
2020-11-14 09:10:57 +11:00
|
|
|
}
|
2019-06-17 19:22:17 +10:00
|
|
|
}
|
2019-06-26 00:37:46 +10:00
|
|
|
|
|
|
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
2019-06-05 18:22:29 +10:00
|
|
|
fn main() {
|
2019-06-26 00:37:46 +10:00
|
|
|
use crate::mac::*;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2019-06-17 19:22:17 +10:00
|
|
|
// The 'external' feature was not enabled. Molten will be built automaticaly.
|
2020-11-14 09:10:57 +11:00
|
|
|
let external_enabled = is_feature_enabled("EXTERNAL");
|
|
|
|
let pre_built_enabled = is_feature_enabled("PRE_BUILT");
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
!(external_enabled && pre_built_enabled),
|
|
|
|
"external and prebuild cannot be active at the same time"
|
|
|
|
);
|
|
|
|
|
|
|
|
if !external_enabled && !pre_built_enabled {
|
|
|
|
let target_dir = Path::new(&std::env::var("OUT_DIR").unwrap())
|
|
|
|
.join(format!("MoltenVK-{}", crate::mac::VERSION,));
|
2020-11-10 07:31:47 +11:00
|
|
|
let _target_name = build_molten(&target_dir);
|
2019-06-29 08:41:11 +10:00
|
|
|
|
2019-06-26 02:46:31 +10:00
|
|
|
let project_dir = {
|
|
|
|
let mut pb = PathBuf::from(
|
|
|
|
std::env::var("CARGO_MANIFEST_DIR").expect("unable to find env:CARGO_MANIFEST_DIR"),
|
|
|
|
);
|
|
|
|
pb.push(target_dir);
|
2020-11-14 09:10:57 +11:00
|
|
|
pb.push(format!(
|
|
|
|
"Package/Latest/MoltenVK/MoltenVK.xcframework/{}-{}",
|
|
|
|
std::env::var("CARGO_CFG_TARGET_OS").unwrap(),
|
|
|
|
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap()
|
|
|
|
));
|
|
|
|
|
2019-06-26 02:46:31 +10:00
|
|
|
pb
|
|
|
|
};
|
2020-11-14 09:10:57 +11:00
|
|
|
|
|
|
|
println!("cargo:rustc-link-search=native={}", project_dir.display());
|
|
|
|
} else if pre_built_enabled {
|
|
|
|
let target_dir = Path::new(&std::env::var("OUT_DIR").unwrap())
|
|
|
|
.join(format!("Prebuilt-MoltenVK-{}", crate::mac::VERSION));
|
|
|
|
|
|
|
|
download_prebuilt_molten(&target_dir);
|
|
|
|
|
|
|
|
let project_dir = {
|
|
|
|
let mut pb = PathBuf::from(
|
|
|
|
std::env::var("CARGO_MANIFEST_DIR").expect("unable to find env:CARGO_MANIFEST_DIR"),
|
|
|
|
);
|
|
|
|
pb.push(target_dir);
|
|
|
|
pb.push(format!(
|
|
|
|
"{}-{}",
|
|
|
|
std::env::var("CARGO_CFG_TARGET_OS").unwrap(),
|
|
|
|
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap()
|
|
|
|
));
|
|
|
|
|
|
|
|
pb
|
|
|
|
};
|
2019-06-26 02:46:31 +10:00
|
|
|
println!("cargo:rustc-link-search=native={}", project_dir.display());
|
|
|
|
}
|
2019-06-26 00:37:46 +10:00
|
|
|
|
2019-06-05 18:22:29 +10:00
|
|
|
println!("cargo:rustc-link-lib=framework=Metal");
|
|
|
|
println!("cargo:rustc-link-lib=framework=AppKit");
|
|
|
|
println!("cargo:rustc-link-lib=framework=QuartzCore");
|
|
|
|
println!("cargo:rustc-link-lib=framework=IOKit");
|
|
|
|
println!("cargo:rustc-link-lib=framework=IOSurface");
|
|
|
|
println!("cargo:rustc-link-lib=dylib=c++");
|
2019-06-26 02:46:31 +10:00
|
|
|
println!("cargo:rustc-link-lib=static=MoltenVK");
|
2019-06-26 00:37:46 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
|
|
|
|
fn main() {
|
|
|
|
eprintln!("ash-molten requires either 'macos' or 'ios' target");
|
2019-06-05 18:22:29 +10:00
|
|
|
}
|