Skip to content

Commit

Permalink
Merge branch 'main' into visionos
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Dec 13, 2024
2 parents 1d75e68 + f64a451 commit 744d954
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 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.

56 changes: 35 additions & 21 deletions src-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ struct SwiftEnv {
}

impl SwiftEnv {
fn new(minimum_macos_version: &str, minimum_ios_version: Option<&str>, minimum_visionos_version: Option<&str>) -> Self {
fn new(
minimum_macos_version: &str,
minimum_ios_version: Option<&str>,
minimum_visionos_version: Option<&str>,
) -> Self {
let rust_target = RustTarget::from_env();
let target = rust_target.swift_target_triple(minimum_macos_version, minimum_ios_version, minimum_visionos_version);
let target = rust_target.swift_target_triple(
minimum_macos_version,
minimum_ios_version,
minimum_visionos_version,
);

let swift_target_info_str = Command::new("swift")
.args(["-target", &target, "-print-target-info"])
Expand Down Expand Up @@ -91,7 +99,8 @@ enum SwiftSDK {
impl SwiftSDK {
fn from_os(os: &RustTargetOS) -> Self {
let target = env::var("TARGET").unwrap();
let simulator = target.ends_with("ios-sim") || target.ends_with("visionos-sim")
let simulator = target.ends_with("ios-sim")
|| target.ends_with("visionos-sim")
|| (target.starts_with("x86_64") && target.ends_with("ios"));

match os {
Expand Down Expand Up @@ -156,9 +165,12 @@ impl RustTarget {
RustTargetOS::VisionOS => minimum_visionos_version.unwrap(),
},
// simulator suffix
matches!(self.sdk, SwiftSDK::IOSSimulator | SwiftSDK::VisionOSSimulator)
.then(|| "-simulator".to_string())
.unwrap_or_default()
matches!(
self.sdk,
SwiftSDK::IOSSimulator | SwiftSDK::VisionOSSimulator
)
.then(|| "-simulator".to_string())
.unwrap_or_default()
)
}

Expand Down Expand Up @@ -209,7 +221,7 @@ impl SwiftLinker {
self.ios_min_version = Some(min_version.to_string());
self
}

/// Instructs the [`SwiftLinker`] to also compile for visionOS
/// using the specified minimum visionOS version.
///
Expand All @@ -236,7 +248,11 @@ impl SwiftLinker {
/// This does not (yet) automatically rebuild your Swift files when they are modified,
/// you'll need to modify/save your `build.rs` file for that.
pub fn link(self) {
let swift_env = SwiftEnv::new(&self.macos_min_version, self.ios_min_version.as_deref(), self.visionos_min_version.as_deref());
let swift_env = SwiftEnv::new(
&self.macos_min_version,
self.ios_min_version.as_deref(),
self.visionos_min_version.as_deref(),
);

#[allow(clippy::uninlined_format_args)]
for path in swift_env.paths.runtime_library_paths {
Expand Down Expand Up @@ -277,9 +293,15 @@ impl SwiftLinker {
arch => arch,
};

let swift_target_triple = rust_target.swift_target_triple(
&self.macos_min_version,
self.ios_min_version.as_deref(),
self.visionos_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 @@ -294,14 +316,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(),
self.visionos_min_version.as_deref(),
),
]);
.args(["-Xswiftc", &swift_target_triple])
.args(["-Xcc", &format!("--target={swift_target_triple}")])
.args(["-Xcxx", &format!("--target={swift_target_triple}")]);

println!("Command `{command:?}`");

Expand All @@ -311,10 +328,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());
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 744d954

Please sign in to comment.