From 4db18f700bc090187e733d9e2e5f137c6a59986a Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Wed, 8 May 2024 13:25:24 +0100 Subject: [PATCH] Support compiling against Musl libc --- Sources/Backtrace/Backtrace.swift | 6 ++++++ Sources/Backtrace/Demangle.swift | 6 ++++++ Sources/Sample/main.swift | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/Sources/Backtrace/Backtrace.swift b/Sources/Backtrace/Backtrace.swift index b69b450..61b5548 100644 --- a/Sources/Backtrace/Backtrace.swift +++ b/Sources/Backtrace/Backtrace.swift @@ -28,7 +28,13 @@ public enum Backtrace { #elseif os(Linux) import CBacktrace +#if canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl +#else +#error("Unsupported runtime") +#endif typealias CBacktraceErrorCallback = @convention(c) (_ data: UnsafeMutableRawPointer?, _ msg: UnsafePointer?, _ errnum: CInt) -> Void typealias CBacktraceFullCallback = @convention(c) (_ data: UnsafeMutableRawPointer?, _ pc: UInt, _ filename: UnsafePointer?, _ lineno: CInt, _ function: UnsafePointer?) -> CInt diff --git a/Sources/Backtrace/Demangle.swift b/Sources/Backtrace/Demangle.swift index 5993e41..089af97 100644 --- a/Sources/Backtrace/Demangle.swift +++ b/Sources/Backtrace/Demangle.swift @@ -13,7 +13,13 @@ //===----------------------------------------------------------------------===// #if os(Linux) +#if canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl +#else +#error("Unsupported runtime") +#endif #elseif os(Windows) #if swift(<5.4) #error("unsupported Swift version") diff --git a/Sources/Sample/main.swift b/Sources/Sample/main.swift index 994bf55..e28613b 100644 --- a/Sources/Sample/main.swift +++ b/Sources/Sample/main.swift @@ -16,7 +16,13 @@ import Backtrace #if canImport(Darwin) import Darwin #elseif os(Linux) +#if canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl +#else +#error("Unsupported runtime") +#endif #endif #if swift(<5.9) || os(Windows)