From 44911f699abf81d4bcf1c1ad3afaefba6b84ca26 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Mon, 9 Nov 2020 21:31:47 +0100 Subject: [PATCH] Upgrade to MoltenVK 1.1.0 (#25) --- .github/workflows/ci.yaml | 11 +++--- build.rs | 75 +++++++++++++++------------------------ 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 893b3c6..d3aea0c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,9 +3,9 @@ name: CI jobs: lint: name: Lint - runs-on: macOS-latest + runs-on: macos-latest env: - DEVELOPER_DIR: /Applications/Xcode_11.5.app + DEVELOPER_DIR: /Applications/Xcode_12.1.app steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -35,9 +35,9 @@ jobs: test: name: Test - runs-on: macOS-latest + runs-on: macos-latest env: - DEVELOPER_DIR: /Applications/Xcode_11.5.app + DEVELOPER_DIR: /Applications/Xcode_12.1.app steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -46,4 +46,5 @@ jobs: override: true - uses: actions-rs/cargo@v1 with: - command: test + command: build + diff --git a/build.rs b/build.rs index ab1e79e..bea7d1f 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,9 @@ #[cfg(any(target_os = "macos", target_os = "ios"))] mod mac { - use std::path::{Path, PathBuf}; + use std::path::Path; + + // MoltenVK git tagged release to use + pub static TAG: &str = "v1.1.0"; // Features are not used inside build scripts, so we have to explicitly query them from the // enviroment @@ -18,7 +21,7 @@ mod mac { .any(|f| f == "EXTERNAL") } - pub(crate) fn build_molten>(target_dir: &P) -> &'static str { + pub(crate) fn build_molten>(_target_dir: &P) -> &'static str { use std::{ process::Command, sync::{ @@ -27,11 +30,8 @@ mod mac { }, }; - // MoltenVK git tagged release to use - let tag = "v.1.0.43"; - let checkout_dir = Path::new(&std::env::var("OUT_DIR").expect("Couldn't find OUT_DIR")) - .join(format!("MoltenVK-{}", tag)); + .join(format!("MoltenVK-{}", TAG)); let exit = Arc::new(AtomicBool::new(false)); let wants_exit = exit.clone(); @@ -62,7 +62,7 @@ mod mac { Command::new("git") .arg("clone") .arg("--branch") - .arg(tag.to_owned()) + .arg(TAG.to_owned()) .arg("--depth") .arg("1") .arg("https://github.com/KhronosGroup/MoltenVK.git") @@ -73,20 +73,10 @@ mod mac { .expect("failed to clone MoltenVK") }; - assert!(git_status.success(), "failed to clone MoltenVK"); - - let status = Command::new("sh") - .current_dir(&checkout_dir) - .arg("fetchDependencies") - .spawn() - .expect("failed to spawn fetchDependencies") - .wait() - .expect("failed to fetchDependencies"); - - assert!(status.success(), "failed to fetchDependencies"); + assert!(git_status.success(), "failed to get MoltenVK"); // These (currently) match the identifiers used by moltenvk - let (target_name, dir) = match std::env::var("CARGO_CFG_TARGET_OS") { + let (target_name, _dir) = match std::env::var("CARGO_CFG_TARGET_OS") { Ok(target) => match target.as_ref() { "macos" => ("macos", "macOS"), "ios" => ("ios", "iOS"), @@ -95,9 +85,10 @@ mod mac { Err(e) => panic!("failed to determinte target os '{}'", e), }; - let status = Command::new("make") + let status = Command::new("sh") .current_dir(&checkout_dir) - .arg(target_name) + .arg("fetchDependencies") + .arg(format!("--{}", target_name)) .spawn() .expect("failed to spawn fetchDependencies") .wait() @@ -105,29 +96,18 @@ mod mac { assert!(status.success(), "failed to fetchDependencies"); - let src = { - let mut pb = PathBuf::new(); - pb.push(checkout_dir); - pb.push("Package/Release/MoltenVK"); - pb.push(dir); - pb.push("static/libMoltenVK.a"); - pb - }; + let mut target = target_name.to_owned(); + target.push_str("-debug"); - let target = { - let mut pb = PathBuf::new(); - pb.push(target_dir); - pb.push(target_name); + let status = Command::new("make") + .current_dir(&checkout_dir) + .arg(target) + .spawn() + .expect("failed to build MoltenVK") + .wait() + .expect("failed to build MoltenVK"); - std::fs::create_dir_all(&pb).expect("failed to create output directory"); - - pb.push("libMoltenVK.a"); - pb - }; - - if let Err(e) = std::fs::copy(&src, &target) { - panic!("failed to copy {:?} to {:?}: {}", src, target, e); - } + assert!(status.success(), "failed to build MoltenVK"); exit.store(true, Ordering::Release); handle.join().unwrap(); @@ -142,18 +122,21 @@ fn main() { // The 'external' feature was not enabled. Molten will be built automaticaly. if !is_external_enabled() { - let target_dir = Path::new(&std::env::var("OUT_DIR").unwrap()).join("MoltenVK-build"); - let target_name = build_molten(&target_dir); + let target_dir = Path::new(&std::env::var("OUT_DIR").unwrap()).join(format!( + "MoltenVK-{}/Package/Latest/MoltenVK/MoltenVK.xcframework/{}-{}", + crate::mac::TAG, + std::env::var("CARGO_CFG_TARGET_OS").unwrap(), + std::env::var("CARGO_CFG_TARGET_ARCH").unwrap() + )); + let _target_name = build_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(target_name); pb }; - println!("cargo:rustc-link-search=native={}", project_dir.display()); }