diff --git a/.github/workflows/native_build.yml b/.github/workflows/native_build.yml index 102fa1b6..af4bdd2a 100644 --- a/.github/workflows/native_build.yml +++ b/.github/workflows/native_build.yml @@ -27,9 +27,10 @@ jobs: curl -o C:/cacert.pem https://curl.se/ca/cacert.pem echo "SSL_CERT_FILE=C:/cacert.pem" | Out-File -FilePath $env:GITHUB_ENV -Append if: runner.os == 'Windows' - - run: | - sudo xcode-select -s /Applications/Xcode_15.0.app + - uses: SwiftyLab/setup-swift@latest if: runner.os == 'macOS' + with: + swift-version: '5.9' - name: Test Full RFC Compliance run: cargo test --all-features --verbose --workspace - name: Test Bare Bones diff --git a/mls-rs-crypto-cryptokit/build.rs b/mls-rs-crypto-cryptokit/build.rs index e416be9e..94e91fac 100644 --- a/mls-rs-crypto-cryptokit/build.rs +++ b/mls-rs-crypto-cryptokit/build.rs @@ -1,83 +1,83 @@ -#![cfg(any(target_os = "macos", target_os = "ios"))] +// This script should not run on any platform besides macOS, but making the whole file conditional +// results in `cargo` complaining about there being no `main()` method in build.rs. +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +fn main() {} +#[cfg(any(target_os = "macos", target_os = "ios"))] fn main() { - link_swift(); - link_swift_package("cryptokit-bridge", "./cryptokit-bridge/"); + swift::configure(); + swift::link_package("cryptokit-bridge", "./cryptokit-bridge/"); } -// Copied from https://github.com/Brendonovich/swift-rs -// With get_swift_target_info changed to print the current target -// rather than always trying for the macosx target. +#[cfg(any(target_os = "macos", target_os = "ios"))] +mod swift { + use serde::Deserialize; + use std::{env, process::Command}; -use std::{env, process::Command}; + #[derive(Debug, Deserialize)] + struct SwiftTargetInfo { + #[serde(rename = "unversionedTriple")] + pub unversioned_triple: String, + #[serde(rename = "librariesRequireRPath")] + pub libraries_require_rpath: bool, + } -use serde::Deserialize; + #[derive(Debug, Deserialize)] + struct SwiftPaths { + #[serde(rename = "runtimeLibraryPaths")] + pub runtime_library_paths: Vec, + } -#[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct SwiftTargetInfo { - pub unversioned_triple: String, - #[serde(rename = "librariesRequireRPath")] - pub libraries_require_rpath: bool, -} + #[derive(Debug, Deserialize)] + struct SwiftTarget { + pub target: SwiftTargetInfo, + pub paths: SwiftPaths, + } -#[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct SwiftPaths { - pub runtime_library_paths: Vec, - pub runtime_resource_path: String, -} + fn get_target_info() -> SwiftTarget { + let swift_target_info_str = Command::new("swift") + .args(["-print-target-info"]) + .output() + .unwrap() + .stdout; -#[derive(Debug, Deserialize)] -pub struct SwiftTarget { - pub target: SwiftTargetInfo, - pub paths: SwiftPaths, -} - -pub fn get_swift_target_info() -> SwiftTarget { - let swift_target_info_str = Command::new("swift") - .args(["-print-target-info"]) - .output() - .unwrap() - .stdout; + serde_json::from_slice(&swift_target_info_str).unwrap() + } - serde_json::from_slice(&swift_target_info_str).unwrap() -} + pub fn configure() { + let swift_target_info = get_target_info(); + if swift_target_info.target.libraries_require_rpath { + panic!("Libraries require RPath! Change minimum MacOS value to fix.") + } -pub fn link_swift() { - let swift_target_info = get_swift_target_info(); - if swift_target_info.target.libraries_require_rpath { - panic!("Libraries require RPath! Change minimum MacOS value to fix.") + swift_target_info + .paths + .runtime_library_paths + .iter() + .for_each(|path| { + println!("cargo:rustc-link-search=native={}", path); + }); } - swift_target_info - .paths - .runtime_library_paths - .iter() - .for_each(|path| { - println!("cargo:rustc-link-search=native={}", path); - }); -} + pub fn link_package(package_name: &str, package_root: &str) { + let profile = env::var("PROFILE").unwrap(); -pub fn link_swift_package(package_name: &str, package_root: &str) { - let profile = env::var("PROFILE").unwrap(); - dbg!(&profile); + if !Command::new("swift") + .args(["build", "-c", &profile]) + .current_dir(package_root) + .status() + .unwrap() + .success() + { + panic!("Failed to compile swift package {}", package_name); + } - if !Command::new("swift") - .args(["build", "-c", &profile]) - .current_dir(package_root) - .status() - .unwrap() - .success() - { - panic!("Failed to compile swift package {}", package_name); + let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let swift_target_info = get_target_info(); + println!( + "cargo:rustc-link-search=native={}/{}.build/{}/{}", + manifest_dir, package_root, swift_target_info.target.unversioned_triple, profile + ); + println!("cargo:rustc-link-lib=static={}", package_name); } - - let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let swift_target_info = get_swift_target_info(); - println!( - "cargo:rustc-link-search=native={}/{}.build/{}/{}", - manifest_dir, package_root, swift_target_info.target.unversioned_triple, profile - ); - println!("cargo:rustc-link-lib=static={}", package_name); }