Skip to content

Commit

Permalink
fix(build): set Swift target triple
Browse files Browse the repository at this point in the history
This fixes some issues when building a Swift package for iOS

This fix was written by @guillemcordoba

Co-authored-by: guillemcordoba
  • Loading branch information
lucasfernog committed Aug 22, 2024
1 parent 634301f commit 0bfa71b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions src-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -270,24 +273,17 @@ 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);
}

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());
Expand Down
1 change: 0 additions & 1 deletion src-rs/types/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Data = SRArray<u8>;
pub struct SRData(SRObject<Data>);

impl SRData {
///
pub fn as_slice(&self) -> &[u8] {
self
}
Expand Down

0 comments on commit 0bfa71b

Please sign in to comment.