From 5f6569518e14572f74764b8df694f7ccd5fd0a25 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Wed, 11 Sep 2024 21:58:05 +0100 Subject: [PATCH] Add support for Musl --- Sources/SotoCore/Credential/ConfigFileLoader.swift | 5 ----- Sources/SotoCore/Doc/Environment.swift | 12 ++++++++---- Sources/SotoTestUtils/Environment.swift | 8 ++++++-- Sources/SotoXML/Expat.swift | 8 ++++++-- .../StaticCredential+EnvironmentTests.swift | 8 ++++++-- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Sources/SotoCore/Credential/ConfigFileLoader.swift b/Sources/SotoCore/Credential/ConfigFileLoader.swift index 39bd064d6..d50c2d2fa 100644 --- a/Sources/SotoCore/Credential/ConfigFileLoader.swift +++ b/Sources/SotoCore/Credential/ConfigFileLoader.swift @@ -17,11 +17,6 @@ import INIParser import Logging import NIOCore import NIOPosix -#if os(Linux) -import Glibc -#else -import Foundation.NSString -#endif /// Load settings from AWS credentials and profile configuration files /// https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html diff --git a/Sources/SotoCore/Doc/Environment.swift b/Sources/SotoCore/Doc/Environment.swift index b4f473c6e..525bc7cb9 100644 --- a/Sources/SotoCore/Doc/Environment.swift +++ b/Sources/SotoCore/Doc/Environment.swift @@ -12,14 +12,18 @@ // //===----------------------------------------------------------------------===// -#if os(Linux) +#if canImport(Glibc) import Glibc -#else +#elseif canImport(Musl) +import Musl +#elseif canImport(Darwin) import Darwin.C +#else +#error("Unsupported platform") #endif -internal enum Environment { - internal static subscript(_ name: String) -> String? { +enum Environment { + static subscript(_ name: String) -> String? { guard let value = getenv(name) else { return nil } diff --git a/Sources/SotoTestUtils/Environment.swift b/Sources/SotoTestUtils/Environment.swift index b4f473c6e..f036ebd7d 100644 --- a/Sources/SotoTestUtils/Environment.swift +++ b/Sources/SotoTestUtils/Environment.swift @@ -12,10 +12,14 @@ // //===----------------------------------------------------------------------===// -#if os(Linux) +#if canImport(Glibc) import Glibc -#else +#elseif canImport(Musl) +import Musl +#elseif canImport(Darwin) import Darwin.C +#else +#error("Unsupported platform") #endif internal enum Environment { diff --git a/Sources/SotoXML/Expat.swift b/Sources/SotoXML/Expat.swift index 390f452dd..01f1c3325 100644 --- a/Sources/SotoXML/Expat.swift +++ b/Sources/SotoXML/Expat.swift @@ -18,10 +18,14 @@ // Licensed under Apache License v2.0 http://www.apache.org/licenses/LICENSE-2.0.html // -#if os(Linux) +#if canImport(Glibc) import Glibc -#else +#elseif canImport(Musl) +import Musl +#elseif canImport(Darwin) import Darwin.C +#else +#error("Unsupported platform") #endif @_implementationOnly import CSotoExpat diff --git a/Tests/SotoCoreTests/Credential/StaticCredential+EnvironmentTests.swift b/Tests/SotoCoreTests/Credential/StaticCredential+EnvironmentTests.swift index a187a1d7b..5efc0465d 100644 --- a/Tests/SotoCoreTests/Credential/StaticCredential+EnvironmentTests.swift +++ b/Tests/SotoCoreTests/Credential/StaticCredential+EnvironmentTests.swift @@ -13,10 +13,14 @@ //===----------------------------------------------------------------------===// import XCTest -#if os(Linux) +#if canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl +#elseif canImport(Darwin) +import Darwin.C #else -import Darwin +#error("Unsupported platform") #endif @testable import SotoCore