8000 Support building for iOS simulator by kabiroberai · Pull Request #74 · xtool-org/xtool · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support building for iOS simulator #74

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

Merged
merged 1 commit into from
May 22, 2025
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
5 changes: 2 additions & 3 deletions Sources/PackLib/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ public struct BuildSettings: Sendable {

public init(
configuration: BuildConfiguration,
triple: String,
packagePath: String = ".",
options: [String] = []
) async throws {
self.packagePath = packagePath
self.configuration = configuration
self.options = options

// TODO: allow customizing?
self.triple = "arm64-apple-ios"
self.triple = triple

// on macOS we don't explicitly install a Swift SDK but
// SwiftPM vends "implicit" Darwin SDKs as of Swift 6.1,
Expand Down
60 changes: 59 additions & 1 deletion Sources/XToolSupport/DevCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ struct PackOperation {
}
}

static let defaultTriple = "arm64-apple-ios"

var triple: String?
var buildOptions = BuildOptions(configuration: .debug)
var xcode = false

Expand All @@ -39,6 +42,7 @@ struct PackOperation {

let buildSettings = try await BuildSettings(
configuration: buildOptions.configuration,
triple: triple ?? Self.defaultTriple,
options: []
)

Expand Down Expand Up @@ -90,8 +94,16 @@ struct DevBuildCommand: AsyncParsableCommand {
help: "Output a .ipa file instead of a .app"
) var ipa = false

@Option(
help: ArgumentHelp(
"Custom target triple to build for",
discussion: "Defaults to '\(PackOperation.defaultTriple)'"
)
) var triple: String?

func run() async throws {
let url = try await PackOperation(
triple: triple,
buildOptions: packOptions
).run()

Expand Down Expand Up @@ -136,10 +148,39 @@ struct DevRunCommand: AsyncParsableCommand {

@OptionGroup var packOptions: PackOperation.BuildOptions

#if os(macOS)
@Flag(
name: .shortAndLong,
help: "Target the iOS Simulator"
) var simulator = false

var triple: String? {
if simulator {
#if arch(arm64)
return "arm64-apple-ios-simulator"
#elseif arch(x86_64)
return "x86_64-apple-ios-simulator"
#else
#error("Unsupported architecture")
#endif
}
return nil
}
#else
var triple: String? { nil }
#endif

@OptionGroup var connectionOptions: ConnectionOptions

func run() async throws {
let output = try await PackOperation(buildOptions: packOptions).run()
let output = try await PackOperation(triple: triple, buildOptions: packOptions).run()

#if os(macOS)
if simulator {
try await SimInstallOperation(path: output).run()
return
}
#endif

let token = try AuthToken.saved()

Expand Down Expand Up @@ -175,3 +216,20 @@ struct DevCommand: AsyncParsableCommand {
}

extension BuildConfiguration: ExpressibleByArgument {}

#if os(macOS)
struct SimInstallOperation {
var path: URL

// TODO: allow customizing this
var simulator = "booted"

func run() async throws {
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/xcrun")
process.arguments = ["simctl", "install", simulator, path.path]
try await process.runUntilExit()
print("Installed to simulator")
}
}
#endif
Loading
0