Skip to content

Commit 0bfa71b

Browse files
committed
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
1 parent 634301f commit 0bfa71b

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "swift-rs"
3-
version = "1.0.6"
3+
version = "1.0.7"
44
description = "Call Swift from Rust with ease!"
55
authors = ["The swift-rs contributors"]
66
license = "MIT OR Apache-2.0"

example/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-rs/build.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,12 @@ impl SwiftLinker {
253253
arch => arch,
254254
};
255255

256+
let swift_target_triple = rust_target
257+
.swift_target_triple(&self.macos_min_version, self.ios_min_version.as_deref());
258+
256259
command
257260
// Build the package (duh)
258-
.args(["build"])
261+
.arg("build")
259262
// SDK path for regular compilation (idk)
260263
.args(["--sdk", sdk_path.trim()])
261264
// Release/Debug configuration
@@ -270,24 +273,17 @@ impl SwiftLinker {
270273
// Override target triple for each swiftc instance.
271274
// Necessary for iOS compilation.
272275
.args(["-Xswiftc", "-target"])
273-
.args([
274-
"-Xswiftc",
275-
&rust_target.swift_target_triple(
276-
&self.macos_min_version,
277-
self.ios_min_version.as_deref(),
278-
),
279-
]);
276+
.args(["-Xswiftc", &swift_target_triple])
277+
.args(["-Xcc", &format!("--target={swift_target_triple}")])
278+
.args(["-Xcxx", &format!("--target={swift_target_triple}")]);
280279

281280
if !command.status().unwrap().success() {
282281
panic!("Failed to compile swift package {}", package.name);
283282
}
284283

285284
let search_path = out_path
286285
// swift build uses this output folder no matter what is the target
287-
.join(format!(
288-
"{}-apple-macosx",
289-
arch
290-
))
286+
.join(format!("{}-apple-macosx", arch))
291287
.join(configuration);
292288

293289
println!("cargo:rerun-if-changed={}", package_path.display());

src-rs/types/data.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type Data = SRArray<u8>;
2626
pub struct SRData(SRObject<Data>);
2727

2828
impl SRData {
29-
///
3029
pub fn as_slice(&self) -> &[u8] {
3130
self
3231
}

0 commit comments

Comments
 (0)