Skip to content

Commit a4d2e79

Browse files
committed
Build targets instead of products from build-script.py
We can’t build library products if they have library type `automatic`. Instead build their targets. While doing that, I defined a fake target that depends on all targets in the SwiftSyntax package. This way, we can build all targets concurrently, before we were only building `SwiftSyntax` and `SwiftSyntaxBuilder` sequentially. All other targets only got build when running tests.
1 parent 1acbfc3 commit a4d2e79

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Package.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ let package = Package(
277277
]
278278
)
279279

280+
// This is a fake target that depends on all targets in the package.
281+
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.
282+
283+
package.targets.append(
284+
.target(
285+
name: "SwiftSyntax-all",
286+
dependencies: package.targets.compactMap {
287+
if $0.type == .test {
288+
return nil
289+
} else {
290+
return .byName(name: $0.name)
291+
}
292+
}
293+
)
294+
)
295+
280296
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
281297
// Building standalone.
282298
package.dependencies += [

Sources/SwiftSyntax-all/empty.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is a fake target that depends on all targets in the package.
2+
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.

build-script.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,19 @@ def __get_swiftpm_invocation(self, package_dir: str) -> List[str]:
215215

216216
def buildProduct(self, product_name: str) -> None:
217217
print("** Building product " + product_name + " **")
218-
self.__build(PACKAGE_DIR, product_name)
218+
self.__build(PACKAGE_DIR, product_name, is_product=True)
219+
220+
def buildTarget(self, target_name: str) -> None:
221+
print("** Building target " + target_name + " **")
222+
self.__build(PACKAGE_DIR, target_name, is_product=False)
219223

220224
def buildExample(self, example_name: str) -> None:
221225
print("** Building example " + example_name + " **")
222-
self.__build(EXAMPLES_DIR, example_name)
226+
self.__build(EXAMPLES_DIR, example_name, is_product=True)
223227

224-
def __build(self, package_dir: str, product_name: str) -> None:
228+
def __build(self, package_dir: str, name: str, is_product: bool) -> None:
225229
command = list(self.__get_swiftpm_invocation(package_dir))
226-
command.extend(["--product", product_name])
230+
command.extend(["--product" if is_product else "--target", name])
227231

228232
env = dict(os.environ)
229233
env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1"
@@ -499,10 +503,7 @@ def build_command(args: argparse.Namespace) -> None:
499503
verbose=args.verbose,
500504
disable_sandbox=args.disable_sandbox,
501505
)
502-
# Until rdar://53881101 is implemented, we cannot request a build of multiple
503-
# targets simultaneously. For now, just build one product after the other.
504-
builder.buildProduct("SwiftSyntax")
505-
builder.buildProduct("SwiftSyntaxBuilder")
506+
builder.buildTarget("SwiftSyntax-all")
506507

507508
# Build examples
508509
builder.buildExample("AddOneToIntegerLiterals")

0 commit comments

Comments
 (0)