Skip to content
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

Update default toolchain version to 5.8 channel snapshot #398

Merged
merged 3 commits into from
May 8, 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && ap
rm -r /var/lib/apt/lists/*

ENV CARTON_ROOT=/root/.carton
ENV CARTON_DEFAULT_TOOLCHAIN=wasm-5.7.1-RELEASE
ENV CARTON_DEFAULT_TOOLCHAIN=wasm-5.8.0-RELEASE

RUN mkdir -p $CARTON_ROOT/sdk && \
mkdir -p $CARTON_ROOT/sdk/$CARTON_DEFAULT_TOOLCHAIN && \
Expand Down
2 changes: 1 addition & 1 deletion Sources/CartonHelpers/DefaultToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.

public let defaultToolchainVersion = "wasm-5.7.1-RELEASE"
public let defaultToolchainVersion = "wasm-5.8.0-RELEASE"
47 changes: 32 additions & 15 deletions Sources/CartonKit/Model/Template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension Template {
) throws {
try fileSystem.writeFileContents(project.path.appending(component: "Package.swift")) {
var content = """
// swift-tools-version:5.6
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "\(project.name)",\n
Expand All @@ -111,11 +111,15 @@ extension Template {
.executableTarget(
name: "\(project.name)",
dependencies: [
"\(project.name)Library",
\(targetDepencencies.map(\.description).joined(separator: ",\n"))
]),
.target(
name: "\(project.name)Library",
dependencies: []),
.testTarget(
name: "\(project.name)Tests",
dependencies: ["\(project.name)"]),
name: "\(project.name)LibraryTests",
dependencies: ["\(project.name)Library"]),
]
)
"""
Expand All @@ -135,8 +139,15 @@ extension Templates {
project: Project,
_ terminal: InteractiveWriter
) async throws {
// FIXME: We now create an intermediate library target to work around
// an issue that prevents us from testing executable targets on Wasm.
// See https://github.com/swiftwasm/swift/issues/5375
try fileSystem.changeCurrentWorkingDirectory(to: project.path)
try await createPackage(type: .executable, fileSystem: fileSystem, project: project, terminal)
try await createPackage(
type: .library, fileSystem: fileSystem,
project: Project(name: project.name + "Library", path: project.path, inPlace: true),
terminal
)
try createManifest(
fileSystem: fileSystem,
project: project,
Expand All @@ -151,6 +162,17 @@ extension Templates {
],
terminal
)
let sources = project.path.appending(component: "Sources")
let executableTarget = sources.appending(component: project.name)
// Create the executable target
try fileSystem.createDirectory(executableTarget)
try fileSystem.writeFileContents(executableTarget.appending(component: "main.swift")) {
"""
import \(project.name.spm_mangledToC99ExtendedIdentifier())Library
print("Hello, world!")
"""
.write(to: $0)
}
}
}
}
Expand All @@ -166,9 +188,9 @@ extension Templates {
) async throws {
try fileSystem.changeCurrentWorkingDirectory(to: project.path)
try await createPackage(
type: .executable,
type: .library,
fileSystem: fileSystem,
project: project,
project: Project(name: project.name + "Library", path: project.path, inPlace: true),
terminal)
try createManifest(
fileSystem: fileSystem,
Expand All @@ -186,18 +208,13 @@ extension Templates {
terminal
)

let sources = project.path.appending(
components: "Sources",
project.name
)

for source in try fileSystem.getDirectoryContents(sources) {
try fileSystem.removeFileTree(sources.appending(components: source))
}
let sources = project.path.appending(component: "Sources")
let executableTarget = sources.appending(component: project.name)

try fileSystem.writeFileContents(sources.appending(components: "App.swift")) {
try fileSystem.writeFileContents(executableTarget.appending(components: "App.swift")) {
"""
import TokamakDOM
import \(project.name.spm_mangledToC99ExtendedIdentifier())Library

@main
struct TokamakApp: App {
Expand Down
6 changes: 2 additions & 4 deletions Sources/SwiftToolchain/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,11 @@ public final class Toolchain {
}

public func runPackageInit(name: String, type: PackageType, inPlace: Bool) async throws {
var initArgs = [
let initArgs = [
swiftPath.pathString, "package", "init",
"--type", type.rawValue,
"--name", name
]
if !inPlace {
initArgs.append(contentsOf: ["--name", name])
}
try await TSCBasic.Process.run(initArgs, terminal)
}

Expand Down
49 changes: 10 additions & 39 deletions Tests/CartonCommandTests/InitCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,24 @@ final class InitCommandTests: XCTestCase {

// Confirm that the files are actually in the folder
XCTAssertTrue(packageDirectory.ls().contains("Package.swift"), "Package.swift does not exist")
XCTAssertTrue(packageDirectory.ls().contains("README.md"), "README.md does not exist")
XCTAssertTrue(packageDirectory.ls().contains(".gitignore"), ".gitignore does not exist")
XCTAssertTrue(packageDirectory.ls().contains("Sources"), "Sources does not exist")
XCTAssertTrue(
packageDirectory.ls().contains("Sources/\(package)"),
"Sources/\(package) does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Sources/\(package)/\(package).swift"),
"Sources/\(package)/\(package).swift does not exist"
packageDirectory.ls().contains("Sources/\(package)/main.swift"),
"Sources/\(package)/main.swift does not exist"
)
XCTAssertTrue(packageDirectory.ls().contains("Tests"), "Tests does not exist")
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests"),
"Tests/\(package)Tests does not exist"
packageDirectory.ls().contains("Tests/\(package)LibraryTests"),
"Tests/\(package)LibraryTests does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests/\(package)Tests.swift"),
"Tests/\(package)Tests/\(package)Tests.swift does not exist"
packageDirectory.ls().contains("Tests/\(package)LibraryTests/\(package)LibraryTests.swift"),
"Tests/\(package)LibraryTests/\(package)LibraryTests.swift does not exist"
)
}
}
Expand All @@ -67,7 +66,6 @@ final class InitCommandTests: XCTestCase {

// Confirm that the files are actually in the folder
XCTAssertTrue(packageDirectory.ls().contains("Package.swift"), "Package.swift does not exist")
XCTAssertTrue(packageDirectory.ls().contains("README.md"), "README.md does not exist")
XCTAssertTrue(packageDirectory.ls().contains(".gitignore"), ".gitignore does not exist")
XCTAssertTrue(packageDirectory.ls().contains("Sources"), "Sources does not exist")
XCTAssertTrue(
Expand All @@ -80,40 +78,13 @@ final class InitCommandTests: XCTestCase {
)
XCTAssertTrue(packageDirectory.ls().contains("Tests"), "Tests does not exist")
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests"),
"Tests/\(package)Tests does not exist"
packageDirectory.ls().contains("Tests/\(package)LibraryTests"),
"Tests/\(package)LibraryTests does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests/\(package)Tests.swift"),
"Tests/\(package)Tests/\(package)Tests.swift does not exist"
packageDirectory.ls().contains("Tests/\(package)LibraryTests/\(package)LibraryTests.swift"),
"Tests/\(package)LibraryTests/\(package)LibraryTests.swift does not exist"
)

let actualTemplateSource = try String(
contentsOfFile:
packageDirectory
.appending(components: "Sources", package, "App.swift").pathString)

XCTAssertEqual(expectedTemplateSource, actualTemplateSource, "Template Sources do not match")
}
}

let expectedTemplateSource =
"""
import TokamakDOM

@main
struct TokamakApp: App {
var body: some Scene {
WindowGroup("Tokamak App") {
ContentView()
}
}
}

struct ContentView: View {
var body: some View {
Text("Hello, world!")
}
}
"""
}