Skip to content

Add a fallback extension none os dylibs #8022

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
Oct 4, 2024
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
21 changes: 19 additions & 2 deletions Sources/Basics/Triple+Basics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extension Triple {
/// The file extension for dynamic libraries (eg. `.dll`, `.so`, or `.dylib`)
public var dynamicLibraryExtension: String {
guard let os = self.os else {
fatalError("Cannot create dynamic libraries unknown os.")
fatalError("Cannot create dynamic libraries for unknown os.")
}

switch os {
Expand All @@ -146,7 +146,24 @@ extension Triple {
case .wasi:
return ".wasm"
default:
fatalError("Cannot create dynamic libraries for os \"\(os)\".")
break
}

guard let objectFormat = self.objectFormat else {
fatalError("Cannot create dynamic libraries for unknown object format.")
}

switch objectFormat {
case .coff:
return ".coff"
case .elf:
return ".elf"
case .macho:
return ".macho"
case .wasm:
return ".wasm"
case .xcoff:
return ".xcoff"
}
}

Expand Down
22 changes: 22 additions & 0 deletions Tests/BasicsTests/TripleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,33 @@ final class TripleTests: XCTestCase {
func testWASI() throws {
let wasi = try Triple("wasm32-unknown-wasi")



// WASI dynamic libraries are only experimental,
// but SwiftPM requires this property not to crash.
_ = wasi.dynamicLibraryExtension
}

func testNoneOSDynamicLibrary() throws {
// Dynamic libraries aren't actually supported for OS none, but swiftpm
// wants an extension to avoid crashing during build planning.
try XCTAssertEqual(
Triple("armv7em-unknown-none-coff").dynamicLibraryExtension,
".coff")
try XCTAssertEqual(
Triple("armv7em-unknown-none-elf").dynamicLibraryExtension,
".elf")
try XCTAssertEqual(
Triple("armv7em-unknown-none-macho").dynamicLibraryExtension,
".macho")
try XCTAssertEqual(
Triple("armv7em-unknown-none-wasm").dynamicLibraryExtension,
".wasm")
try XCTAssertEqual(
Triple("armv7em-unknown-none-xcoff").dynamicLibraryExtension,
".xcoff")
}

func testIsRuntimeCompatibleWith() throws {
try XCTAssertTrue(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-macosx")))
try XCTAssertTrue(Triple("x86_64-unknown-linux").isRuntimeCompatible(with: Triple("x86_64-unknown-linux")))
Expand Down