Skip to content

Commit

Permalink
Attempt to address CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bifurcation committed Apr 17, 2024
1 parent 90ce423 commit 75323ad
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 68 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/native_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
132 changes: 66 additions & 66 deletions mls-rs-crypto-cryptokit/build.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

#[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<String>,
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);
}

0 comments on commit 75323ad

Please sign in to comment.