Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other platform sdks from generated xcode project. #52

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Foundation

/// An apple SDK platform name to build for.
enum AppleSDKPlatform: String, CaseIterable {
case macosx
case iphoneos
case iphonesimulator
case xros
case xrsimulator
case appletvos
case appletvsimulator
case linux

/// The platform's name.
var name: String {
rawValue
}

/// The Apple SDK's platform name (e.g. for `iphoneos` it's `iOS`).
var platform: Platform {
switch self {
case .macosx:
return .macOS
case .iphoneos:
return .iOS
case .iphonesimulator:
return .iOSSimulator
case .xros:
return .visionOS
case .xrsimulator:
return .visionOSSimulator
case .appletvos:
return .tvOS
case .appletvsimulator:
return .tvOSSimulator
case .linux:
return .linux
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ enum Platform: String, CaseIterable {
#endif
}
}

extension Platform: Equatable {
public static func ==(lhs: Platform, rhs: AppleSDKPlatform) -> Bool {
lhs == rhs.platform
}
}
2 changes: 1 addition & 1 deletion Sources/swift-bundler/Bundler/XcodeSupportGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ enum XcodeSupportGenerator {
"export PATH=`zsh --login -c '[ -f /etc/zshrc ] && . /etc/zshrc; [ -f ~/.zshrc ] && . ~/.zshrc; echo $PATH'`"
let command = "swift-bundler bundle"
let arguments =
"\(app) -d \(packagePath) --products-directory ${BUILT_PRODUCTS_DIR} -o '\(escapedOutputPath)' --skip-build --built-with-xcode"
"\(app) -d \(packagePath) --products-directory ${BUILT_PRODUCTS_DIR} -o '\(escapedOutputPath)' --skip-build --built-with-xcode --platform ${TARGET_DEVICE_PLATFORM_NAME}"
let createBundle = "\(fixPath); \(command) \(arguments)"
.replacingOccurrences(of: "&", with: "&")

Expand Down
5 changes: 5 additions & 0 deletions Sources/swift-bundler/Commands/BundleArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ struct BundleArguments: ParsableArguments {
return "The platform to build for \(possibleValues). (default: macOS)"
}(),
transform: { string in
// also support getting a platform by its apple sdk equivalent.
if let appleSDK = AppleSDKPlatform(rawValue: string) {
return appleSDK.platform
}

guard let platform = Platform(rawValue: string) else {
throw CLIError.invalidPlatform(string)
}
Expand Down
Loading