diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index 0b52cee..b2b0125 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift @@ -73,6 +73,11 @@ extension SwiftSDKGenerator { // But not in all containers, so don't fail if it does not exist. if case .ubuntu = targetDistribution { subpaths += [("\(targetTriple.archName)-linux-gnu", false)] + + // Custom subpath for armv7 + if targetTriple.archName == "armv7" { + subpaths += [("arm-linux-gnueabihf", false)] + } } for (subpath, failIfNotExists) in subpaths { @@ -104,13 +109,16 @@ extension SwiftSDKGenerator { func copyTargetSwift(from distributionPath: FilePath, sdkDirPath: FilePath) async throws { logger.info("Copying Swift core libraries for the target triple into Swift SDK bundle...") - for (pathWithinPackage, pathWithinSwiftSDK) in [ - ("lib/swift", sdkDirPath.appending("usr/lib")), - ("lib/swift_static", sdkDirPath.appending("usr/lib")), - ("lib/clang", sdkDirPath.appending("usr/lib")), - ("include", sdkDirPath.appending("usr")), + for (pathWithinPackage, pathWithinSwiftSDK, ignoreIfMissing) in [ + ("lib/swift", sdkDirPath.appending("usr/lib"), false), + ("lib/swift_static", sdkDirPath.appending("usr/lib"), false), + ("lib/clang", sdkDirPath.appending("usr/lib"), true), + ("include", sdkDirPath.appending("usr"), false), ] { - try await rsync(from: distributionPath.appending(pathWithinPackage), to: pathWithinSwiftSDK) + try await rsync( + from: distributionPath.appending(pathWithinPackage), + to: pathWithinSwiftSDK, ignoreIfMissing: ignoreIfMissing + ) } } } @@ -120,6 +128,7 @@ extension Triple { switch self.archName { case "x86_64": return "/lib64/ld-linux-x86-64.so.2" case "aarch64": return "/lib/ld-linux-aarch64.so.1" + case "armv7": return "/lib/ld-linux-armhf.so.3" default: fatalError("unsupported architecture \(self.archName)") } } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift index c4ec429..07f93e3 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift @@ -26,6 +26,7 @@ public extension Triple.Arch { case .aarch64: return "arm64" case .x86_64: return "amd64" case .wasm32: return "wasm32" + case .arm: return "armhf" default: fatalError("\(self) is not supported yet") } } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift index 0db1d5e..714d054 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift @@ -158,9 +158,10 @@ public actor SwiftSDKGenerator { try Data(contentsOf: URL(fileURLWithPath: path.string)) } - func rsync(from source: FilePath, to destination: FilePath) async throws { + func rsync(from source: FilePath, to destination: FilePath, ignoreIfMissing: Bool = false) async throws { try self.createDirectoryIfNeeded(at: destination) - try await Shell.run("rsync -a \(source) \(destination)", shouldLogCommands: self.isVerbose) + let ignoreMissingArgs = ignoreIfMissing ? "--ignore-missing-args" : "" + try await Shell.run("rsync -a \(ignoreMissingArgs) \(source) \(destination)", shouldLogCommands: self.isVerbose) } func rsyncContents(from source: FilePath, to destination: FilePath) async throws { diff --git a/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift b/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift index 8459a96..fd7e1c3 100644 --- a/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift +++ b/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift @@ -33,6 +33,7 @@ extension Triple.Arch { case .aarch64: return "aarch64" case .x86_64: return "x86_64" case .wasm32: return "wasm32" + case .arm: return "arm" default: fatalError("\(self) is not supported yet") } } diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift index ffa9266..c1b4a34 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift @@ -158,7 +158,7 @@ public struct LinuxRecipe: SwiftSDKRecipe { self.linuxDistribution .release )_\( - self.mainTargetTriple.arch!.linuxConventionName + self.mainTargetTriple.archName ) """ } @@ -217,6 +217,12 @@ public struct LinuxRecipe: SwiftSDKRecipe { engine: QueryEngine, httpClient client: some HTTPClientProtocol ) async throws -> SwiftSDKProduct { + if self.linuxDistribution.name == .rhel && self.mainTargetTriple.archName == "armv7" { + throw GeneratorError.distributionDoesNotSupportArchitecture( + self.linuxDistribution, targetArchName: self.mainTargetTriple.archName + ) + } + let sdkDirPath = self.sdkDirPath(paths: generator.pathsConfiguration) if !generator.isIncremental { try await generator.removeRecursively(at: sdkDirPath) diff --git a/Sources/SwiftSDKGenerator/SystemUtils/GeneratorError.swift b/Sources/SwiftSDKGenerator/SystemUtils/GeneratorError.swift index 9960c1e..2ecae65 100644 --- a/Sources/SwiftSDKGenerator/SystemUtils/GeneratorError.swift +++ b/Sources/SwiftSDKGenerator/SystemUtils/GeneratorError.swift @@ -22,6 +22,7 @@ enum GeneratorError: Error { case unknownCPUArchitecture(String) case unknownLLDVersion(String) case distributionSupportsOnlyDockerGenerator(LinuxDistribution) + case distributionDoesNotSupportArchitecture(LinuxDistribution, targetArchName: String) case fileDoesNotExist(FilePath) case fileDownloadFailed(URL, String) case ubuntuPackagesDecompressionFailure @@ -50,6 +51,10 @@ extension GeneratorError: CustomStringConvertible { Target Linux distribution \(linuxDistribution) supports Swift SDK generation only when `--with-docker` flag is \ passed. """ + case let .distributionDoesNotSupportArchitecture(linuxDistribution, targetArchName): + return """ + Target Linux distribution \(linuxDistribution) does not support the target architecture: \(targetArchName) + """ case let .fileDoesNotExist(filePath): return "Expected to find a file at path `\(filePath)`." case let .fileDownloadFailed(url, status):