Skip to content

Commit 1f41b0f

Browse files
committed
Change executable and tool templates to use main.swift
The recent changes to templates switched these templates away from using `@main` which seems to not be compatible with Xcode's build system. The only non-`@main` way for executables that is supported is naming the primary source file "main.swift", so that is what this PR does.
1 parent 760ec39 commit 1f41b0f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Sources/Workspace/InitPackage.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,12 @@ public final class InitPackage {
290290
: sources.appending(component: "\(pkgname)")
291291
try makeDirectories(moduleDir)
292292

293-
let sourceFileName = "\(typeName).swift"
293+
let sourceFileName: String
294+
if packageType == .executable || packageType == .tool {
295+
sourceFileName = "main.swift"
296+
} else {
297+
sourceFileName = "\(typeName).swift"
298+
}
294299
let sourceFile = try AbsolutePath(validating: sourceFileName, relativeTo: moduleDir)
295300

296301
let content: String

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ final class PackageToolTests: CommandsTestCase {
718718
XCTAssertMatch(contents, .prefix("// swift-tools-version:\(version < .v5_4 ? "" : " ")\(versionSpecifier)\n"))
719719

720720
XCTAssertFileExists(manifest)
721-
XCTAssertEqual(try fs.getDirectoryContents(path.appending(component: "Sources")), ["Foo.swift"])
721+
XCTAssertEqual(try fs.getDirectoryContents(path.appending(component: "Sources")), ["main.swift"])
722722
}
723723
}
724724

@@ -749,7 +749,7 @@ final class PackageToolTests: CommandsTestCase {
749749
XCTAssertMatch(contents, .prefix("// swift-tools-version:\(version < .v5_4 ? "" : " ")\(versionSpecifier)\n"))
750750

751751
XCTAssertFileExists(manifest)
752-
XCTAssertEqual(try fs.getDirectoryContents(path.appending(component: "Sources")), ["CustomName.swift"])
752+
XCTAssertEqual(try fs.getDirectoryContents(path.appending(component: "Sources")), ["main.swift"])
753753
}
754754
}
755755

0 commit comments

Comments
 (0)