mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Tools/BuildSDK - Expose option for selecting build profile, move targets to an enum.
This commit is contained in:
committed by
Stefan Ceriu
parent
5654b23659
commit
05680a4696
@@ -2,6 +2,19 @@ import ArgumentParser
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
|
enum Profile: String, ExpressibleByArgument {
|
||||||
|
case debug = "dbg"
|
||||||
|
case reldbg, release
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Target: String, ExpressibleByArgument, CaseIterable {
|
||||||
|
case iOS = "aarch64-apple-ios"
|
||||||
|
case simulatorARM64 = "aarch64-apple-ios-sim"
|
||||||
|
case simulatorIntel = "x86_64-apple-ios"
|
||||||
|
case macARM64 = "aarch64-apple-darwin"
|
||||||
|
case macIntel = "x86_64-apple-darwin"
|
||||||
|
}
|
||||||
|
|
||||||
struct BuildSDK: ParsableCommand {
|
struct BuildSDK: ParsableCommand {
|
||||||
static var configuration = CommandConfiguration(abstract: "A tool to checkout and build MatrixRustSDK locally for development.")
|
static var configuration = CommandConfiguration(abstract: "A tool to checkout and build MatrixRustSDK locally for development.")
|
||||||
|
|
||||||
@@ -9,7 +22,10 @@ struct BuildSDK: ParsableCommand {
|
|||||||
var branch: String?
|
var branch: String?
|
||||||
|
|
||||||
@Option(help: "The target to build for such as aarch64-apple-ios. Omit this option to build for all targets.")
|
@Option(help: "The target to build for such as aarch64-apple-ios. Omit this option to build for all targets.")
|
||||||
var target: String?
|
var target: Target?
|
||||||
|
|
||||||
|
@Option(help: "The profile to use when building the SDK. Omit this option to build in debug mode.")
|
||||||
|
var profile: Profile = .debug
|
||||||
|
|
||||||
private var parentDirectoryURL: URL { Utilities.projectDirectoryURL.deletingLastPathComponent() }
|
private var parentDirectoryURL: URL { Utilities.projectDirectoryURL.deletingLastPathComponent() }
|
||||||
private var sdkDirectoryURL: URL { parentDirectoryURL.appending(path: "matrix-rust-sdk") }
|
private var sdkDirectoryURL: URL { parentDirectoryURL.appending(path: "matrix-rust-sdk") }
|
||||||
@@ -49,13 +65,10 @@ struct BuildSDK: ParsableCommand {
|
|||||||
guard target == nil else { return }
|
guard target == nil else { return }
|
||||||
guard let output = try Utilities.zsh("rustup show") else { throw Error.rustupOutputFailure }
|
guard let output = try Utilities.zsh("rustup show") else { throw Error.rustupOutputFailure }
|
||||||
|
|
||||||
var requiredTargets = [
|
var requiredTargets = Target.allCases.reduce(into: [String: Bool]()) { partialResult, target in
|
||||||
"aarch64-apple-darwin": false,
|
partialResult[target.rawValue] = false
|
||||||
"aarch64-apple-ios": false,
|
}
|
||||||
"aarch64-apple-ios-sim": false,
|
|
||||||
"x86_64-apple-darwin": false,
|
|
||||||
"x86_64-apple-ios": false
|
|
||||||
]
|
|
||||||
output.enumerateLines { line, _ in
|
output.enumerateLines { line, _ in
|
||||||
if requiredTargets.keys.contains(line) {
|
if requiredTargets.keys.contains(line) {
|
||||||
requiredTargets[line] = true
|
requiredTargets[line] = true
|
||||||
@@ -80,9 +93,10 @@ struct BuildSDK: ParsableCommand {
|
|||||||
|
|
||||||
/// Build the Rust SDK as an XCFramework with the debug profile.
|
/// Build the Rust SDK as an XCFramework with the debug profile.
|
||||||
func buildFramework() throws {
|
func buildFramework() throws {
|
||||||
var buildCommand = "cargo xtask swift build-framework --profile dbg"
|
var buildCommand = "cargo xtask swift build-framework"
|
||||||
|
buildCommand.append(" --profile \(profile.rawValue)")
|
||||||
if let target {
|
if let target {
|
||||||
buildCommand.append(" --only-target \(target)")
|
buildCommand.append(" --only-target \(target.rawValue)")
|
||||||
}
|
}
|
||||||
try Utilities.zsh(buildCommand, workingDirectoryURL: sdkDirectoryURL)
|
try Utilities.zsh(buildCommand, workingDirectoryURL: sdkDirectoryURL)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user