Skip to content
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/SPMBuildCore/BinaryTarget+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ extension Triple.OS {
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
fileprivate var asXCFrameworkPlatformString: String? {
switch self {
case .darwin, .linux, .wasi, .win32, .openbsd, .freebsd, .noneOS:
case .darwin, .wasi, .win32, .openbsd, .freebsd, .noneOS:
return nil // XCFrameworks do not support any of these platforms today.
case .macosx:
return "macos"
Expand All @@ -133,6 +133,8 @@ extension Triple.OS {
return "tvos"
case .watchos:
return "watchos"
case .linux:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to return nil for Android triples. We should move the extension from Triple.OS to Triple and check both the os and environment fields; ensuring the environment field is gnu or musl, or at least not android/androideabi.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jakepetroules ,

Moved and added an android check

return ProcessInfo.processInfo.environment["_SWIFTPM_EXPERIMENTAL_LINUX_XCFRAMEWORK"] == "1" ? "linux" : nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this being an experimental flag that we can make hidden if necessary. This is how we did the prebuilts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just actively trying to make sure SwiftPM doesn't necessitate the need for Environment changes. It's just too many degrees of separation between where they're set and where they're used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dschaefer2 ,

Do you mean to define a hidden boolean flag under GlobalOptions.BuildOptions in Options.swift and then to pass this to BuildParameters via SwiftCommandState and making use of this in:

  1. BuildPlan+Swift.swift
  2. BuildPlan+Product.swift
  3. BuildPlan+Clang.swift

Or is there more locations where changes are required?

Copy link
Member

@dschaefer2 dschaefer2 Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the environment variable is pretty deep in the call tree here. That whole getter has a pretty heavy side effect relying on the name being nil to disallow a platform. Not a choice I would have made :). But let's not change too much.

We should really check at the BuildPlan level wherever we're calling parseXCFramework and only do linux if the flag is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, any preference on what the flag should be named ?

/// Hidden option to allow XCFrameworks on Linux
@Flag(
    name: .customLong("experimental-xcframeworks-on-linux"),
    help: .hidden
)
public var enableXCFrameworksOnLinux: Bool = false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dschaefer2,

I have removed the env variable and added swift-build --experimental-xcframeworks-on-linux, which compiles our product successfully.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. Thanks! I'm wondering if there's a test we can add to make sure it stays working as we make changes in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like testXCFrameworkBinaryTargets(), to create a new test function for Linux ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dschaefer2 ,

I have added a test on BuildPlan for the optional flag validation and also a functional test which compiles a library with Library Evolution; packages this into XCF; builds and runs a test binary on Linux.

default:
return nil // XCFrameworks do not support any of these platforms today.
}
Expand Down