Skip to content

Commit 09e4511

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 09e4511

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

Package.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,32 @@ let package = Package(
274274
dependencies: ["SwiftIDEUtils", "SwiftParser", "SwiftSyntax"],
275275
exclude: ["Inputs"]
276276
),
277+
278+
// MARK: Build target
279+
// This is a fake target that depends on all targets in the package.
280+
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.
281+
282+
.target(
283+
name: "SwiftSyntax-all",
284+
dependencies: [
285+
"_InstructionCounter",
286+
"_SwiftSyntaxTestSupport",
287+
"SwiftBasicFormat",
288+
"SwiftCompilerPlugin",
289+
"SwiftCompilerPluginMessageHandling",
290+
"SwiftDiagnostics",
291+
"SwiftIDEUtils",
292+
"SwiftSyntax",
293+
"SwiftSyntaxBuilder",
294+
"SwiftSyntaxMacros",
295+
"SwiftSyntaxMacrosTestSupport",
296+
"SwiftParser",
297+
"SwiftParserDiagnostics",
298+
"SwiftOperators",
299+
"SwiftRefactor",
300+
"swift-parser-cli",
301+
]
302+
),
277303
]
278304
)
279305

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)