Skip to content

Change all library types to automatic #1545

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 2 commits into from
May 2, 2023
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
40 changes: 28 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ let package = Package(
.macCatalyst(.v13),
],
products: [
.library(name: "SwiftCompilerPlugin", type: .static, targets: ["SwiftCompilerPlugin"]),
.library(name: "SwiftCompilerPluginMessageHandling", type: .static, targets: ["SwiftCompilerPluginMessageHandling"]),
.library(name: "SwiftDiagnostics", type: .static, targets: ["SwiftDiagnostics"]),
.library(name: "SwiftIDEUtils", type: .static, targets: ["SwiftIDEUtils"]),
.library(name: "SwiftOperators", type: .static, targets: ["SwiftOperators"]),
.library(name: "SwiftParser", type: .static, targets: ["SwiftParser"]),
.library(name: "SwiftParserDiagnostics", type: .static, targets: ["SwiftParserDiagnostics"]),
.library(name: "SwiftRefactor", type: .static, targets: ["SwiftRefactor"]),
.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]),
.library(name: "SwiftSyntaxBuilder", type: .static, targets: ["SwiftSyntaxBuilder"]),
.library(name: "SwiftSyntaxMacros", type: .static, targets: ["SwiftSyntaxMacros"]),
.library(name: "SwiftSyntaxMacrosTestSupport", type: .static, targets: ["SwiftSyntaxMacrosTestSupport"]),
.library(name: "SwiftCompilerPlugin", targets: ["SwiftCompilerPlugin"]),
.library(name: "SwiftCompilerPluginMessageHandling", targets: ["SwiftCompilerPluginMessageHandling"]),
.library(name: "SwiftDiagnostics", targets: ["SwiftDiagnostics"]),
.library(name: "SwiftIDEUtils", targets: ["SwiftIDEUtils"]),
.library(name: "SwiftOperators", targets: ["SwiftOperators"]),
.library(name: "SwiftParser", targets: ["SwiftParser"]),
.library(name: "SwiftParserDiagnostics", targets: ["SwiftParserDiagnostics"]),
.library(name: "SwiftRefactor", targets: ["SwiftRefactor"]),
.library(name: "SwiftSyntax", targets: ["SwiftSyntax"]),
.library(name: "SwiftSyntaxBuilder", targets: ["SwiftSyntaxBuilder"]),
.library(name: "SwiftSyntaxMacros", targets: ["SwiftSyntaxMacros"]),
.library(name: "SwiftSyntaxMacrosTestSupport", targets: ["SwiftSyntaxMacrosTestSupport"]),
],
targets: [
// MARK: - Internal helper targets
Expand Down Expand Up @@ -277,6 +277,22 @@ let package = Package(
]
)

// This is a fake target that depends on all targets in the package.
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.

package.targets.append(
.target(
name: "SwiftSyntax-all",
dependencies: package.targets.compactMap {
if $0.type == .test {
return nil
} else {
return .byName(name: $0.name)
}
}
)
)

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Building standalone.
package.dependencies += [
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSyntax-all/empty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This is a fake target that depends on all targets in the package.
// We need to define it manually because the `SwiftSyntax-Package` target doesn't exist for `swift build`.
17 changes: 9 additions & 8 deletions build-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,19 @@ def __get_swiftpm_invocation(self, package_dir: str) -> List[str]:

def buildProduct(self, product_name: str) -> None:
print("** Building product " + product_name + " **")
self.__build(PACKAGE_DIR, product_name)
self.__build(PACKAGE_DIR, product_name, is_product=True)

def buildTarget(self, target_name: str) -> None:
print("** Building target " + target_name + " **")
self.__build(PACKAGE_DIR, target_name, is_product=False)

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

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

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

# Build examples
builder.buildExample("AddOneToIntegerLiterals")
Expand Down