Skip to content

Tests: Run packageInitExecutable test on all platforms for native build system #8527

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 1 commit into from
Apr 23, 2025
Merged
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
55 changes: 32 additions & 23 deletions IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ private struct SwiftPMTests {
}

@Test(
.requireHostOS(.windows, when: false),
.requireThreadSafeWorkingDirectory,
arguments: [BuildSystemProvider.native]
)
func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
try _packageInitExecutable(buildSystemProvider)
}

@Test(
.skipHostOS(.windows),
.requireThreadSafeWorkingDirectory,
.bug(
"https://github.com/swiftlang/swift-package-manager/issues/8416",
Expand All @@ -85,30 +93,31 @@ private struct SwiftPMTests {
"https://github.com/swiftlang/swift-package-manager/issues/8514",
"[Windows] Integration test SwiftPMTests.packageInitExecutable with --build-system swiftbuild is skipped"
),
arguments: BuildSystemProvider.allCases
arguments: [BuildSystemProvider.swiftbuild]
)
func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
// Executable
do {
try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
try localFileSystem.createDirectory(packagePath)
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
try sh(swiftBuild, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue)

try withKnownIssue("Error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory") {
// The 'native' build system uses 'swiftc' as the linker driver, which adds an RUNPATH to the swift runtime libraries in the SDK.
// 'swiftbuild' directly calls clang, which does not add the extra RUNPATH, so runtime libraries cannot be found.
let (stdout, stderr) = try sh(
swiftRun, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue
)
#expect(!stderr.contains("error:"))
#expect(stdout.contains("Hello, world!"))
} when: {
buildSystemProvider == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux
}
func packageInitExecutablSkipWindows(_ buildSystemProvider: BuildSystemProvider) throws {
try _packageInitExecutable(buildSystemProvider)
}

private func _packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
try localFileSystem.createDirectory(packagePath)
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
try sh(swiftBuild, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue)

try withKnownIssue("Error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory") {
// The 'native' build system uses 'swiftc' as the linker driver, which adds an RUNPATH to the swift runtime libraries in the SDK.
// 'swiftbuild' directly calls clang, which does not add the extra RUNPATH, so runtime libraries cannot be found.
let (stdout, stderr) = try sh(
swiftRun, "--package-path", packagePath, "--build-system", buildSystemProvider.rawValue
)
#expect(!stderr.contains("error:"))
#expect(stdout.contains("Hello, world!"))
} when: {
buildSystemProvider == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux
}
}
}
}

@Test(
Expand Down