From 0bfa71b092c289e3c23ccbb7c7571227fe1ea665 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Thu, 22 Aug 2024 14:41:55 -0300 Subject: [PATCH] fix(build): set Swift target triple This fixes some issues when building a Swift package for iOS This fix was written by @guillemcordoba Co-authored-by: guillemcordoba --- Cargo.toml | 2 +- example/Cargo.lock | 2 +- src-rs/build.rs | 20 ++++++++------------ src-rs/types/data.rs | 1 - 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d0172b..6b1bfda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swift-rs" -version = "1.0.6" +version = "1.0.7" description = "Call Swift from Rust with ease!" authors = ["The swift-rs contributors"] license = "MIT OR Apache-2.0" diff --git a/example/Cargo.lock b/example/Cargo.lock index a11f528..4f1c538 100644 --- a/example/Cargo.lock +++ b/example/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "swift-rs" -version = "1.0.5" +version = "1.0.7" dependencies = [ "base64", "serde", diff --git a/src-rs/build.rs b/src-rs/build.rs index 394b9eb..41abd7a 100644 --- a/src-rs/build.rs +++ b/src-rs/build.rs @@ -253,9 +253,12 @@ impl SwiftLinker { arch => arch, }; + let swift_target_triple = rust_target + .swift_target_triple(&self.macos_min_version, self.ios_min_version.as_deref()); + command // Build the package (duh) - .args(["build"]) + .arg("build") // SDK path for regular compilation (idk) .args(["--sdk", sdk_path.trim()]) // Release/Debug configuration @@ -270,13 +273,9 @@ impl SwiftLinker { // Override target triple for each swiftc instance. // Necessary for iOS compilation. .args(["-Xswiftc", "-target"]) - .args([ - "-Xswiftc", - &rust_target.swift_target_triple( - &self.macos_min_version, - self.ios_min_version.as_deref(), - ), - ]); + .args(["-Xswiftc", &swift_target_triple]) + .args(["-Xcc", &format!("--target={swift_target_triple}")]) + .args(["-Xcxx", &format!("--target={swift_target_triple}")]); if !command.status().unwrap().success() { panic!("Failed to compile swift package {}", package.name); @@ -284,10 +283,7 @@ impl SwiftLinker { let search_path = out_path // swift build uses this output folder no matter what is the target - .join(format!( - "{}-apple-macosx", - arch - )) + .join(format!("{}-apple-macosx", arch)) .join(configuration); println!("cargo:rerun-if-changed={}", package_path.display()); diff --git a/src-rs/types/data.rs b/src-rs/types/data.rs index e982235..addcca0 100644 --- a/src-rs/types/data.rs +++ b/src-rs/types/data.rs @@ -26,7 +26,6 @@ type Data = SRArray; pub struct SRData(SRObject); impl SRData { - /// pub fn as_slice(&self) -> &[u8] { self }