Add -Xswiftc option for each build commands (#300)
This commit is contained in:
parent
02e64225f8
commit
4ca0cdf939
|
@ -10,8 +10,9 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && ap
|
|||
libncurses5 \
|
||||
libsqlite3-0 \
|
||||
libsqlite3-dev \
|
||||
libxkbcommon0 \
|
||||
curl unzip \
|
||||
&& export WASMER_DIR=/usr/local && curl https://get.wasmer.io -sSfL | sh && \
|
||||
&& export WASMER_DIR=/usr/local && curl https://get.wasmer.io -sSfL | sh -s "2.2.1" && \
|
||||
rm -r /var/lib/apt/lists/*
|
||||
|
||||
ENV CARTON_ROOT=/root/.carton
|
||||
|
|
|
@ -39,6 +39,9 @@ struct Bundle: AsyncParsableCommand {
|
|||
@Flag(help: "When specified, build in the debug mode.")
|
||||
var debug = false
|
||||
|
||||
@OptionGroup()
|
||||
var buildOptions: BuildOptions
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
abstract: "Produces an optimized app bundle for distribution."
|
||||
)
|
||||
|
@ -46,7 +49,7 @@ struct Bundle: AsyncParsableCommand {
|
|||
func buildFlavor() -> BuildFlavor {
|
||||
BuildFlavor(
|
||||
isRelease: !debug, environment: .browser,
|
||||
sanitize: nil
|
||||
sanitize: nil, swiftCompilerFlags: buildOptions.swiftCompilerFlags
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,9 @@ struct Dev: AsyncParsableCommand {
|
|||
@Flag(name: .long, help: "Skip automatically opening app in system browser.")
|
||||
var skipAutoOpen = false
|
||||
|
||||
@OptionGroup()
|
||||
var buildOptions: BuildOptions
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
abstract: "Watch the current directory, host the app, rebuild on change."
|
||||
)
|
||||
|
@ -62,7 +65,8 @@ struct Dev: AsyncParsableCommand {
|
|||
let defaultSanitize: SanitizeVariant? = release ? nil : .stackOverflow
|
||||
return BuildFlavor(
|
||||
isRelease: release, environment: .browser,
|
||||
sanitize: sanitize ?? defaultSanitize
|
||||
sanitize: sanitize ?? defaultSanitize,
|
||||
swiftCompilerFlags: buildOptions.swiftCompilerFlags
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2022 Carton contributors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import ArgumentParser
|
||||
|
||||
struct BuildOptions: ParsableArguments {
|
||||
@Option(name: .customLong("Xswiftc", withSingleDash: true),
|
||||
parsing: .unconditionalSingleValue,
|
||||
help: "Pass flag through to all Swift compiler invocations")
|
||||
var swiftCompilerFlags: [String] = []
|
||||
|
||||
init() {}
|
||||
}
|
|
@ -66,10 +66,13 @@ struct Test: AsyncParsableCommand {
|
|||
)
|
||||
var host = "127.0.0.1"
|
||||
|
||||
@OptionGroup()
|
||||
var buildOptions: BuildOptions
|
||||
|
||||
func buildFlavor() -> BuildFlavor {
|
||||
BuildFlavor(
|
||||
isRelease: release, environment: environment.destination,
|
||||
sanitize: sanitize
|
||||
sanitize: sanitize, swiftCompilerFlags: buildOptions.swiftCompilerFlags
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,17 @@ public struct BuildFlavor {
|
|||
public var isRelease: Bool
|
||||
public var environment: DestinationEnvironment
|
||||
public var sanitize: SanitizeVariant?
|
||||
public var swiftCompilerFlags: [String]
|
||||
|
||||
public init(isRelease: Bool, environment: DestinationEnvironment, sanitize: SanitizeVariant?) {
|
||||
public init(
|
||||
isRelease: Bool,
|
||||
environment: DestinationEnvironment,
|
||||
sanitize: SanitizeVariant?,
|
||||
swiftCompilerFlags: [String]
|
||||
) {
|
||||
self.isRelease = isRelease
|
||||
self.environment = environment
|
||||
self.sanitize = sanitize
|
||||
self.swiftCompilerFlags = swiftCompilerFlags
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,6 +265,10 @@ public final class Toolchain {
|
|||
builderArguments.append(contentsOf: ["-Xlinker", "-licuuc", "-Xlinker", "-licui18n"])
|
||||
}
|
||||
|
||||
builderArguments.append(contentsOf: flavor.swiftCompilerFlags.flatMap {
|
||||
["-Xswiftc", $0]
|
||||
})
|
||||
|
||||
try await Builder(
|
||||
arguments: builderArguments,
|
||||
mainWasmPath: mainWasmPath,
|
||||
|
@ -317,6 +321,10 @@ public final class Toolchain {
|
|||
builderArguments.append(contentsOf: ["-Xlinker", "-licuuc", "-Xlinker", "-licui18n"])
|
||||
}
|
||||
|
||||
builderArguments.append(contentsOf: flavor.swiftCompilerFlags.flatMap {
|
||||
["-Xswiftc", $0]
|
||||
})
|
||||
|
||||
try await Builder(
|
||||
arguments: builderArguments,
|
||||
mainWasmPath: testBundlePath,
|
||||
|
|
|
@ -57,4 +57,24 @@ final class BundleCommandTests: XCTestCase {
|
|||
try bundleDirectory.delete()
|
||||
try packageDirectory.appending(component: ".build").delete()
|
||||
}
|
||||
|
||||
func testWithXswiftc() throws {
|
||||
let package = "Milk"
|
||||
let packageDirectory = testFixturesDirectory.appending(component: package)
|
||||
|
||||
let bundle = "Bundle"
|
||||
let bundleDirectory = packageDirectory.appending(component: bundle)
|
||||
|
||||
// it's ok if there is nothing to delete
|
||||
do { try bundleDirectory.delete() } catch {}
|
||||
|
||||
AssertExecuteCommand(
|
||||
command: "carton bundle -Xswiftc --fake-swiftc-options",
|
||||
cwd: packageDirectory.url,
|
||||
expected: "error: unknown argument: '--fake-swiftc-options'",
|
||||
expectedContains: true
|
||||
)
|
||||
|
||||
try packageDirectory.appending(component: ".build").delete()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue