Skip to content
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
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,30 @@ jobs:
- run: ./Vendor/checkout-dependency
- run: ./build-exec swift test

build-musl:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- swift: 6.0.1-jammy
musl-swift-sdk-download: "https://download.swift.org/swift-6.0.1-release/static-sdk/swift-6.0.1-RELEASE/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz"
musl-swift-sdk-checksum: "d4f46ba40e11e697387468e18987ee622908bc350310d8af54eb5e17c2ff5481"
steps:
- uses: actions/checkout@v4
- name: Configure container
run: |
docker run -dit --name build-container -v $PWD:/workspace -w /workspace swift:${{ matrix.swift }}
echo 'docker exec -i build-container "$@"' > ./build-exec
chmod +x ./build-exec

- name: Install Static Linux SDK
run: ./build-exec swift sdk install "${{ matrix.musl-swift-sdk-download }}" --checksum "${{ matrix.musl-swift-sdk-checksum }}"

- name: Build (x86_64-swift-linux-musl)
run: ./build-exec swift build --swift-sdk x86_64-swift-linux-musl
- name: Build (aarch64-swift-linux-musl)
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl

build-windows:
runs-on: windows-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion Sources/SystemExtras/Clock.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif os(Windows)
import CSystem
import ucrt
Expand Down
5 changes: 4 additions & 1 deletion Sources/SystemExtras/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif os(Windows)
import CSystem
import ucrt
Expand Down
6 changes: 5 additions & 1 deletion Sources/SystemExtras/FileAtOperations.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif os(Windows)
import ucrt
import WinSDK
Expand Down
6 changes: 5 additions & 1 deletion Sources/SystemExtras/FileOperations.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif os(Windows)
import ucrt
import WinSDK
Expand Down
6 changes: 5 additions & 1 deletion Sources/SystemExtras/Syscalls.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif os(Windows)
import ucrt
import WinSDK
Expand Down
70 changes: 63 additions & 7 deletions Sources/SystemExtras/Vendor/Exports.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Copyright (c) 2020 - 2024 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand All @@ -14,12 +14,20 @@

#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
import CSystem
import Glibc
#elseif os(Windows)
import CSystem
import ucrt
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(WASILibc)
import WASILibc
#elseif canImport(Android)
import CSystem
import Android
#else
#error("Unsupported Platform")
#endif
Expand Down Expand Up @@ -47,11 +55,26 @@ internal var system_errno: CInt {
_ = ucrt._set_errno(newValue)
}
}
#else
#elseif canImport(Glibc)
internal var system_errno: CInt {
get { Glibc.errno }
set { Glibc.errno = newValue }
}
#elseif canImport(Musl)
internal var system_errno: CInt {
get { Musl.errno }
set { Musl.errno = newValue }
}
#elseif canImport(WASILibc)
internal var system_errno: CInt {
get { WASILibc.errno }
set { WASILibc.errno = newValue }
}
#elseif canImport(Android)
internal var system_errno: CInt {
get { Android.errno }
set { Android.errno = newValue }
}
#endif

// MARK: C stdlib decls
Expand All @@ -62,7 +85,10 @@ internal func system_strerror(_ __errnum: Int32) -> UnsafeMutablePointer<Int8>!
strerror(__errnum)
}

internal func system_strlen(_ s: UnsafePointer<Int8>) -> Int {
internal func system_strlen(_ s: UnsafePointer<CChar>) -> Int {
strlen(s)
}
internal func system_strlen(_ s: UnsafeMutablePointer<CChar>) -> Int {
strlen(s)
}

Expand All @@ -80,7 +106,17 @@ internal func system_platform_strlen(_ s: UnsafePointer<CInterop.PlatformChar>)
#endif
}

// Interop between String and platform string
// memset for raw buffers
// FIXME: Do we really not have something like this in the stdlib already?
internal func system_memset(
_ buffer: UnsafeMutableRawBufferPointer,
to byte: UInt8
) {
guard buffer.count > 0 else { return }
memset(buffer.baseAddress!, CInt(byte), buffer.count)
}

// Interop between String and platfrom string
extension String {
internal func _withPlatformString<Result>(
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
Expand Down Expand Up @@ -130,6 +166,24 @@ extension String {
// TLS
#if os(Windows)
internal typealias _PlatformTLSKey = DWORD
#elseif os(WASI) && (swift(<6.1) || !_runtime(_multithreaded))
// Mock TLS storage for single-threaded WASI
internal final class _PlatformTLSKey {
fileprivate init() {}
}
private final class TLSStorage: @unchecked Sendable {
var storage = [ObjectIdentifier: UnsafeMutableRawPointer]()
}
private let sharedTLSStorage = TLSStorage()

func pthread_setspecific(_ key: _PlatformTLSKey, _ p: UnsafeMutableRawPointer?) -> Int {
sharedTLSStorage.storage[ObjectIdentifier(key)] = p
return 0
}

func pthread_getspecific(_ key: _PlatformTLSKey) -> UnsafeMutableRawPointer? {
sharedTLSStorage.storage[ObjectIdentifier(key)]
}
#else
internal typealias _PlatformTLSKey = pthread_key_t
#endif
Expand All @@ -141,6 +195,8 @@ internal func makeTLSKey() -> _PlatformTLSKey {
fatalError("Unable to create key")
}
return raw
#elseif os(WASI) && (swift(<6.1) || !_runtime(_multithreaded))
return _PlatformTLSKey()
#else
var raw = pthread_key_t()
guard 0 == pthread_key_create(&raw, nil) else {
Expand Down
4 changes: 3 additions & 1 deletion Sources/WASI/WASI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import WasmTypes

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import ucrt
#else
Expand Down