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

Add support for Musl libc #423

Merged
merged 1 commit into from
Jun 22, 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 Sources/TSCBasic/WritableByteStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public extension WritableByteStream {
// Public alias to the old name to not introduce API compatibility.
public typealias OutputByteStream = WritableByteStream

#if os(Android)
#if os(Android) || canImport(Musl)
public typealias FILEPointer = OpaquePointer
#else
public typealias FILEPointer = UnsafeMutablePointer<FILE>
Expand Down
2 changes: 2 additions & 0 deletions Sources/TSCLibc/libc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#if canImport(Glibc)
@_exported import Glibc
#elseif canImport(Musl)
@_exported import Musl
#elseif os(Windows)
@_exported import CRT
@_exported import WinSDK
Expand Down
14 changes: 7 additions & 7 deletions Sources/TSCUtility/FSWatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FSWatch {
self._watcher = NoOpWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
#elseif os(Windows)
self._watcher = RDCWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
var ipaths: [AbsolutePath: Inotify.WatchOptions] = [:]

// FIXME: We need to recurse here.
Expand Down Expand Up @@ -106,7 +106,7 @@ extension NoOpWatcher: _FileWatcher{}
#elseif os(Windows)
extension FSWatch._WatcherDelegate: RDCWatcherDelegate {}
extension RDCWatcher: _FileWatcher {}
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
extension FSWatch._WatcherDelegate: InotifyDelegate {}
extension Inotify: _FileWatcher{}
#elseif os(macOS)
Expand Down Expand Up @@ -296,7 +296,7 @@ public final class RDCWatcher {
}
}

#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)

/// The delegate for receiving inotify events.
public protocol InotifyDelegate {
Expand Down Expand Up @@ -621,7 +621,7 @@ public final class Inotify {
// FIXME: <rdar://problem/45794219> Swift should provide shims for FD_ macros

private func FD_ZERO(_ set: inout fd_set) {
#if os(Android)
#if os(Android) || canImport(Musl)
#if arch(arm)
set.fds_bits = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Expand All @@ -641,7 +641,7 @@ private func FD_ZERO(_ set: inout fd_set) {
private func FD_SET(_ fd: Int32, _ set: inout fd_set) {
let intOffset = Int(fd / 16)
let bitOffset = Int(fd % 16)
#if os(Android)
#if os(Android) || canImport(Musl)
var fd_bits = set.fds_bits
let mask: UInt = 1 << bitOffset
#else
Expand Down Expand Up @@ -685,7 +685,7 @@ private func FD_SET(_ fd: Int32, _ set: inout fd_set) {
#endif
default: break
}
#if os(Android)
#if os(Android) || canImport(Musl)
set.fds_bits = fd_bits
#else
set.__fds_bits = fd_bits
Expand All @@ -695,7 +695,7 @@ private func FD_SET(_ fd: Int32, _ set: inout fd_set) {
private func FD_ISSET(_ fd: Int32, _ set: inout fd_set) -> Bool {
let intOffset = Int(fd / 32)
let bitOffset = Int(fd % 32)
#if os(Android)
#if os(Android) || canImport(Musl)
let fd_bits = set.fds_bits
let mask: UInt = 1 << bitOffset
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/TSCUtility/IndexStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private struct _DLOpenFlags: RawRepresentable, OptionSet {
public static let deepBind: _DLOpenFlags = _DLOpenFlags(rawValue: 0)
#else
public static let first: _DLOpenFlags = _DLOpenFlags(rawValue: 0)
#if os(Linux)
#if os(Linux) && canImport(Glibc)
public static let deepBind: _DLOpenFlags = _DLOpenFlags(rawValue: RTLD_DEEPBIND)
#else
public static let deepBind: _DLOpenFlags = _DLOpenFlags(rawValue: 0)
Expand Down
4 changes: 4 additions & 0 deletions Sources/TSCUtility/InterruptHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

#if !canImport(Musl)

import TSCLibc
import TSCBasic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declarations in this file are deprecated and we're not going to use them when building for Musl.

Expand Down Expand Up @@ -135,3 +137,5 @@ public final class InterruptHandler {
thread.join()
}
}

#endif
2 changes: 1 addition & 1 deletion Sources/TSCUtility/dlopen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct DLOpenFlags: RawRepresentable, OptionSet {
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0)
#else
public static let first: DLOpenFlags = DLOpenFlags(rawValue: 0)
#if os(Linux)
#if os(Linux) && canImport(Glibc)
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: RTLD_DEEPBIND)
#else
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0)
Expand Down