From 874118ceeda86e72fdf136189afeee39fcfde00e Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:01:03 +0900 Subject: [PATCH 01/11] Add option frameworkModuleMapGenerationPolicy --- Sources/ScipioKit/BuildOptions.swift | 13 ++++++- .../PIF/FrameworkComponentsCollector.swift | 38 ++++++++++++------- Sources/ScipioKit/Runner.swift | 3 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Sources/ScipioKit/BuildOptions.swift b/Sources/ScipioKit/BuildOptions.swift index 89b582a9..f90c4e2c 100644 --- a/Sources/ScipioKit/BuildOptions.swift +++ b/Sources/ScipioKit/BuildOptions.swift @@ -9,7 +9,8 @@ struct BuildOptions: Hashable, Codable, Sendable { sdks: Set, extraFlags: ExtraFlags?, extraBuildParameters: ExtraBuildParameters?, - enableLibraryEvolution: Bool + enableLibraryEvolution: Bool, + frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy ) { self.buildConfiguration = buildConfiguration self.isDebugSymbolsEmbedded = isDebugSymbolsEmbedded @@ -18,6 +19,7 @@ struct BuildOptions: Hashable, Codable, Sendable { self.extraFlags = extraFlags self.extraBuildParameters = extraBuildParameters self.enableLibraryEvolution = enableLibraryEvolution + self.frameworkModuleMapGenerationPolicy = frameworkModuleMapGenerationPolicy } let buildConfiguration: BuildConfiguration @@ -27,6 +29,7 @@ struct BuildOptions: Hashable, Codable, Sendable { let extraFlags: ExtraFlags? let extraBuildParameters: ExtraBuildParameters? let enableLibraryEvolution: Bool + let frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy } public struct ExtraFlags: Hashable, Codable, Sendable { @@ -48,6 +51,14 @@ public struct ExtraFlags: Hashable, Codable, Sendable { } } +/// A model indicates modulemap generation policy +public enum FrameworkModuleMapGenerationPolicy: Codable, Sendable, Hashable, Equatable { + // Generate modulemap automatically + case autoGenerated + // Pass the custom modulemap for each distributed framework + case custom(URL) +} + public typealias ExtraBuildParameters = [String: String] public enum BuildConfiguration: String, Codable, Sendable { diff --git a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift index f5f2dcc8..20233ee0 100644 --- a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift +++ b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift @@ -48,19 +48,14 @@ struct FrameworkComponentsCollector { } func collectComponents(sdk: SDK) throws -> FrameworkComponents { - let modulemapGenerator = ModuleMapGenerator( - descriptionPackage: descriptionPackage, - fileSystem: fileSystem - ) - - // xcbuild automatically generates modulemaps. However, these are not for frameworks. - // Therefore, it's difficult to contain this generated modulemaps to final XCFrameworks. - // So generate modulemap for frameworks manually - let frameworkModuleMapPath = try modulemapGenerator.generate( - resolvedTarget: buildProduct.target, - sdk: sdk, - buildConfiguration: buildOptions.buildConfiguration - ) + let frameworkModuleMapPath: AbsolutePath? + switch buildOptions.frameworkModuleMapGenerationPolicy { + case .autoGenerated: + frameworkModuleMapPath = try generateFrameworkModuleMap() + case .custom(let url): + logger.info("📝 Using custom modulemap \(url.path()) for \(buildProduct.target.name)") + frameworkModuleMapPath = url.absolutePath + } let targetName = buildProduct.target.c99name let generatedFrameworkPath = generatedFrameworkPath() @@ -99,6 +94,23 @@ struct FrameworkComponentsCollector { return components } + private func generateFrameworkModuleMap() throws -> AbsolutePath? { + let modulemapGenerator = ModuleMapGenerator( + descriptionPackage: descriptionPackage, + fileSystem: fileSystem + ) + + // xcbuild automatically generates modulemaps. However, these are not for frameworks. + // Therefore, it's difficult to contain this generated modulemaps to final XCFrameworks. + // So generate modulemap for frameworks manually + let frameworkModuleMapPath = try modulemapGenerator.generate( + resolvedTarget: buildProduct.target, + sdk: sdk, + buildConfiguration: buildOptions.buildConfiguration + ) + return frameworkModuleMapPath + } + private func generatedFrameworkPath() -> AbsolutePath { descriptionPackage.productsDirectory( buildConfiguration: buildOptions.buildConfiguration, diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index f7922557..56a112a6 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -281,7 +281,8 @@ extension Runner.Options.BuildOptions { sdks: Set(sdks), extraFlags: extraFlags, extraBuildParameters: extraBuildParameters, - enableLibraryEvolution: enableLibraryEvolution + enableLibraryEvolution: enableLibraryEvolution, + frameworkModuleMapGenerationPolicy: .autoGenerated ) } From bf9f6a2700dcad4bc3130208227bc9d905274de6 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:03:33 +0900 Subject: [PATCH 02/11] Add generation policy to CLI options --- Sources/ScipioKit/Runner.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index 56a112a6..81140d48 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -130,6 +130,7 @@ extension Runner { public var extraFlags: ExtraFlags? public var extraBuildParameters: [String: String]? public var enableLibraryEvolution: Bool + public var frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy public init( buildConfiguration: BuildConfiguration = .release, @@ -139,7 +140,8 @@ extension Runner { frameworkType: FrameworkType = .dynamic, extraFlags: ExtraFlags? = nil, extraBuildParameters: [String: String]? = nil, - enableLibraryEvolution: Bool = false + enableLibraryEvolution: Bool = false, + frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy = .autoGenerated ) { self.buildConfiguration = buildConfiguration self.platforms = platforms @@ -149,6 +151,7 @@ extension Runner { self.extraFlags = extraFlags self.extraBuildParameters = extraBuildParameters self.enableLibraryEvolution = enableLibraryEvolution + self.frameworkModuleMapGenerationPolicy = frameworkModuleMapGenerationPolicy } } public struct TargetBuildOptions { @@ -160,6 +163,7 @@ extension Runner { public var extraFlags: ExtraFlags? public var extraBuildParameters: [String: String]? public var enableLibraryEvolution: Bool? + public var frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy public init( buildConfiguration: BuildConfiguration? = nil, @@ -169,7 +173,8 @@ extension Runner { frameworkType: FrameworkType? = nil, extraFlags: ExtraFlags? = nil, extraBuildParameters: [String: String]? = nil, - enableLibraryEvolution: Bool? = nil + enableLibraryEvolution: Bool? = nil, + frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy = .autoGenerated ) { self.buildConfiguration = buildConfiguration self.platforms = platforms @@ -179,6 +184,7 @@ extension Runner { self.extraBuildParameters = extraBuildParameters self.extraFlags = extraFlags self.enableLibraryEvolution = enableLibraryEvolution + self.frameworkModuleMapGenerationPolicy = frameworkModuleMapGenerationPolicy } } From 8ac915f9ae6759c9184f3c2dc6b0fb841b1a1388 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:09:06 +0900 Subject: [PATCH 03/11] Update documentation --- Sources/ScipioKit/Runner.swift | 1 + Sources/scipio/scipio.docc/build-pipeline.md | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index 81140d48..c452f2b0 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -130,6 +130,7 @@ extension Runner { public var extraFlags: ExtraFlags? public var extraBuildParameters: [String: String]? public var enableLibraryEvolution: Bool + /// An option indicates use custom modulemaps for distribution public var frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy public init( diff --git a/Sources/scipio/scipio.docc/build-pipeline.md b/Sources/scipio/scipio.docc/build-pipeline.md index 200c0706..625cdf7e 100644 --- a/Sources/scipio/scipio.docc/build-pipeline.md +++ b/Sources/scipio/scipio.docc/build-pipeline.md @@ -200,6 +200,19 @@ This matrix can override build options of the specific targets to base build opt Of-course, you are also pass `extraFlags` or `extraBuildParameters` per product. +#### Passing custom modulemap + +Scipio attempt to generate modulemap automatically distributed in the XCFramework. However, if you want to custom modulemap, you can pass `frameworkModuleMapGenerationPolicy` to the build options. In general, this option should be used `buildOptionsMatrix`. + +```swift +buildOptionsMatrix: [ + "MyResourceFramework": .init( + frameworkModuleMapGenerationPolicy: .custom(URL(filePath: "path/to/module.modulemap")) + ), +] + +``` + ### Use Custom Cache Storage In CLI version of Scipio, you can only use Project cache or Local disk cache as a cache storage backend. From 461a8a6af4f8852e4e6de46264daea2a5524f0cb Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:24:19 +0900 Subject: [PATCH 04/11] Fix frameworkGenerationPolicy --- .../Producer/PIF/FrameworkComponentsCollector.swift | 2 +- Sources/ScipioKit/Runner.swift | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift index 20233ee0..d74a4ebe 100644 --- a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift +++ b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift @@ -53,7 +53,7 @@ struct FrameworkComponentsCollector { case .autoGenerated: frameworkModuleMapPath = try generateFrameworkModuleMap() case .custom(let url): - logger.info("📝 Using custom modulemap \(url.path()) for \(buildProduct.target.name)") + logger.info("📝 Using custom modulemap \(url.path()) for \(buildProduct.target.name)(\(sdk.displayName))") frameworkModuleMapPath = url.absolutePath } diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index c452f2b0..ca929827 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -164,7 +164,7 @@ extension Runner { public var extraFlags: ExtraFlags? public var extraBuildParameters: [String: String]? public var enableLibraryEvolution: Bool? - public var frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy + public var frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy? public init( buildConfiguration: BuildConfiguration? = nil, @@ -175,7 +175,7 @@ extension Runner { extraFlags: ExtraFlags? = nil, extraBuildParameters: [String: String]? = nil, enableLibraryEvolution: Bool? = nil, - frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy = .autoGenerated + frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy? = nil ) { self.buildConfiguration = buildConfiguration self.platforms = platforms @@ -289,7 +289,7 @@ extension Runner.Options.BuildOptions { extraFlags: extraFlags, extraBuildParameters: extraBuildParameters, enableLibraryEvolution: enableLibraryEvolution, - frameworkModuleMapGenerationPolicy: .autoGenerated + frameworkModuleMapGenerationPolicy: frameworkModuleMapGenerationPolicy ) } @@ -332,7 +332,8 @@ extension Runner.Options.BuildOptions { frameworkType: fetch(\.frameworkType, by: \.frameworkType), extraFlags: mergedExtraFlags, extraBuildParameters: mergedExtraBuildParameters, - enableLibraryEvolution: fetch(\.enableLibraryEvolution, by: \.enableLibraryEvolution) + enableLibraryEvolution: fetch(\.enableLibraryEvolution, by: \.enableLibraryEvolution), + frameworkModuleMapGenerationPolicy: fetch(\.frameworkModuleMapGenerationPolicy, by: \.frameworkModuleMapGenerationPolicy) ) } } From 02497edf098ebd4a2ce8a2c77624a336833620a2 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:34:50 +0900 Subject: [PATCH 05/11] Rename to FrameworkModuleMapGenerator --- .../ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift | 2 +- Sources/ScipioKit/Producer/PIF/ModuleMapGenerator.swift | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift index d74a4ebe..2718a76e 100644 --- a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift +++ b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift @@ -95,7 +95,7 @@ struct FrameworkComponentsCollector { } private func generateFrameworkModuleMap() throws -> AbsolutePath? { - let modulemapGenerator = ModuleMapGenerator( + let modulemapGenerator = FrameworkModuleMapGenerator( descriptionPackage: descriptionPackage, fileSystem: fileSystem ) diff --git a/Sources/ScipioKit/Producer/PIF/ModuleMapGenerator.swift b/Sources/ScipioKit/Producer/PIF/ModuleMapGenerator.swift index aec91b45..9c8fc949 100644 --- a/Sources/ScipioKit/Producer/PIF/ModuleMapGenerator.swift +++ b/Sources/ScipioKit/Producer/PIF/ModuleMapGenerator.swift @@ -3,7 +3,8 @@ import TSCBasic import PackageGraph import PackageModel -struct ModuleMapGenerator { +// A generator to generate modulemaps which are distributed in the XCFramework +struct FrameworkModuleMapGenerator { private struct Context { var resolvedTarget: ScipioResolvedModule var sdk: SDK From 9cd2085a63a988ed4ce89188b2b7194b6aaf69f3 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:36:06 +0900 Subject: [PATCH 06/11] Resolve SwiftLint violations --- .../ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift index 2718a76e..1999b76e 100644 --- a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift +++ b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift @@ -50,7 +50,7 @@ struct FrameworkComponentsCollector { func collectComponents(sdk: SDK) throws -> FrameworkComponents { let frameworkModuleMapPath: AbsolutePath? switch buildOptions.frameworkModuleMapGenerationPolicy { - case .autoGenerated: + case .autoGenerated: frameworkModuleMapPath = try generateFrameworkModuleMap() case .custom(let url): logger.info("📝 Using custom modulemap \(url.path()) for \(buildProduct.target.name)(\(sdk.displayName))") From 3d021204b4bd61d828cea28911dab758214b93eb Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 11:59:36 +0900 Subject: [PATCH 07/11] Fix CI --- Sources/ScipioKit/Runner.swift | 2 +- Tests/ScipioKitTests/CacheSystemTests.swift | 4 +++- Tests/ScipioKitTests/RunnerTests.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index ca929827..a10a1e79 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -130,7 +130,7 @@ extension Runner { public var extraFlags: ExtraFlags? public var extraBuildParameters: [String: String]? public var enableLibraryEvolution: Bool - /// An option indicates use custom modulemaps for distribution + /// An option indicates use custom modulemaps for distributionb public var frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy public init( diff --git a/Tests/ScipioKitTests/CacheSystemTests.swift b/Tests/ScipioKitTests/CacheSystemTests.swift index 66eeca6e..c16357a7 100644 --- a/Tests/ScipioKitTests/CacheSystemTests.swift +++ b/Tests/ScipioKitTests/CacheSystemTests.swift @@ -29,7 +29,9 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault sdks: [.iOS], extraFlags: .init(swiftFlags: ["-D", "SOME_FLAG"]), extraBuildParameters: ["SWIFT_OPTIMIZATION_LEVEL": "-Osize"], - enableLibraryEvolution: true), + enableLibraryEvolution: true, + frameworkModuleMapGenerationPolicy: .autoGenerated + ), clangVersion: "clang-1400.0.29.102", xcodeVersion: .init(xcodeVersion: "15.4", xcodeBuildVersion: "15F31d") ) diff --git a/Tests/ScipioKitTests/RunnerTests.swift b/Tests/ScipioKitTests/RunnerTests.swift index 906dbb85..9e830dbe 100644 --- a/Tests/ScipioKitTests/RunnerTests.swift +++ b/Tests/ScipioKitTests/RunnerTests.swift @@ -715,6 +715,7 @@ extension BuildOptions { sdks: [.iOS], extraFlags: nil, extraBuildParameters: nil, - enableLibraryEvolution: true + enableLibraryEvolution: true, + frameworkModuleMapGenerationPolicy: .autoGenerated ) } From 76bcdb581b9dce69d34cba7b4599e54bf8cf652f Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 30 Jul 2024 12:17:50 +0900 Subject: [PATCH 08/11] Fix fixture --- Tests/ScipioKitTests/CacheSystemTests.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/ScipioKitTests/CacheSystemTests.swift b/Tests/ScipioKitTests/CacheSystemTests.swift index c16357a7..1e73533a 100644 --- a/Tests/ScipioKitTests/CacheSystemTests.swift +++ b/Tests/ScipioKitTests/CacheSystemTests.swift @@ -53,6 +53,11 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault "SOME_FLAG" ] }, + "frameworkModuleMapGenerationPolicy" : { + "autoGenerated" : { + + } + }, "frameworkType" : "dynamic", "isDebugSymbolsEmbedded" : false, "sdks" : [ From 69ac91511b3292598589ad5ff5e580b63b4d8497 Mon Sep 17 00:00:00 2001 From: giginet Date: Wed, 31 Jul 2024 17:05:46 +0900 Subject: [PATCH 09/11] Use file contents for cacheKey --- Sources/ScipioKit/BuildOptions.swift | 9 ++++--- .../PIF/FrameworkComponentsCollector.swift | 17 +++++++++---- Sources/ScipioKit/Runner.swift | 25 ++++++++++++------- Tests/ScipioKitTests/CacheSystemTests.swift | 7 +----- Tests/ScipioKitTests/RunnerTests.swift | 2 +- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Sources/ScipioKit/BuildOptions.swift b/Sources/ScipioKit/BuildOptions.swift index f90c4e2c..87b3cf81 100644 --- a/Sources/ScipioKit/BuildOptions.swift +++ b/Sources/ScipioKit/BuildOptions.swift @@ -10,7 +10,7 @@ struct BuildOptions: Hashable, Codable, Sendable { extraFlags: ExtraFlags?, extraBuildParameters: ExtraBuildParameters?, enableLibraryEvolution: Bool, - frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy + customFrameworkModuleMapContents: Data? ) { self.buildConfiguration = buildConfiguration self.isDebugSymbolsEmbedded = isDebugSymbolsEmbedded @@ -19,7 +19,7 @@ struct BuildOptions: Hashable, Codable, Sendable { self.extraFlags = extraFlags self.extraBuildParameters = extraBuildParameters self.enableLibraryEvolution = enableLibraryEvolution - self.frameworkModuleMapGenerationPolicy = frameworkModuleMapGenerationPolicy + self.customFrameworkModuleMapContents = customFrameworkModuleMapContents } let buildConfiguration: BuildConfiguration @@ -29,7 +29,10 @@ struct BuildOptions: Hashable, Codable, Sendable { let extraFlags: ExtraFlags? let extraBuildParameters: ExtraBuildParameters? let enableLibraryEvolution: Bool - let frameworkModuleMapGenerationPolicy: FrameworkModuleMapGenerationPolicy + /// A custom framework modulemap contents + /// - Note: It have to store the actual file contents rather than its path, + /// because the cache key should change when the file contents change. + let customFrameworkModuleMapContents: Data? } public struct ExtraFlags: Hashable, Codable, Sendable { diff --git a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift index 1999b76e..c56fa9c4 100644 --- a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift +++ b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift @@ -49,12 +49,11 @@ struct FrameworkComponentsCollector { func collectComponents(sdk: SDK) throws -> FrameworkComponents { let frameworkModuleMapPath: AbsolutePath? - switch buildOptions.frameworkModuleMapGenerationPolicy { - case .autoGenerated: + if let customFrameworkModuleMapContents = buildOptions.customFrameworkModuleMapContents { + logger.info("📝 Using custom modulemap for \(buildProduct.target.name)(\(sdk.displayName))") + frameworkModuleMapPath = try copyModuleMapContentsToBuildArtifacts(customFrameworkModuleMapContents) + } else { frameworkModuleMapPath = try generateFrameworkModuleMap() - case .custom(let url): - logger.info("📝 Using custom modulemap \(url.path()) for \(buildProduct.target.name)(\(sdk.displayName))") - frameworkModuleMapPath = url.absolutePath } let targetName = buildProduct.target.c99name @@ -94,6 +93,14 @@ struct FrameworkComponentsCollector { return components } + /// Copy content data to the build artifacts + private func copyModuleMapContentsToBuildArtifacts(_ data: Data) throws -> ScipioAbsolutePath { + let generatedModuleMapPath = try descriptionPackage.generatedModuleMapPath(of: buildProduct.target, sdk: sdk) + + try fileSystem.writeFileContents(generatedModuleMapPath.spmAbsolutePath, data: data) + return generatedModuleMapPath + } + private func generateFrameworkModuleMap() throws -> AbsolutePath? { let modulemapGenerator = FrameworkModuleMapGenerator( descriptionPackage: descriptionPackage, diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index a10a1e79..436971c8 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -84,7 +84,7 @@ public struct Runner { throw Error.invalidPackage(packageDirectory) } - let buildOptions = options.buildOptionsContainer.makeBuildOptions(descriptionPackage: descriptionPackage) + let buildOptions = try options.buildOptionsContainer.makeBuildOptions(descriptionPackage: descriptionPackage) guard !buildOptions.sdks.isEmpty else { throw Error.platformNotSpecified } @@ -95,7 +95,7 @@ public struct Runner { try fileSystem.createDirectory(outputDir.absolutePath, recursive: true) - let buildOptionsMatrix = options.buildOptionsContainer.makeBuildOptionsMatrix(descriptionPackage: descriptionPackage) + let buildOptionsMatrix = try options.buildOptionsContainer.makeBuildOptionsMatrix(descriptionPackage: descriptionPackage) let producer = FrameworkProducer( descriptionPackage: descriptionPackage, @@ -275,12 +275,19 @@ extension Runner.Options.Platform { } extension Runner.Options.BuildOptions { - fileprivate func makeBuildOptions(descriptionPackage: DescriptionPackage) -> BuildOptions { + fileprivate func makeBuildOptions(descriptionPackage: DescriptionPackage, fileSystem: any FileSystem = localFileSystem) throws -> BuildOptions { let sdks = detectSDKsToBuild( platforms: platforms, package: descriptionPackage, isSimulatorSupported: isSimulatorSupported ) + let customFrameworkModuleMapContents: Data? = switch frameworkModuleMapGenerationPolicy { + case .autoGenerated: + nil + case .custom(let url): + try fileSystem.readFileContents(url.absolutePath.spmAbsolutePath) + } + return BuildOptions( buildConfiguration: buildConfiguration, isDebugSymbolsEmbedded: isDebugSymbolsEmbedded, @@ -289,7 +296,7 @@ extension Runner.Options.BuildOptions { extraFlags: extraFlags, extraBuildParameters: extraBuildParameters, enableLibraryEvolution: enableLibraryEvolution, - frameworkModuleMapGenerationPolicy: frameworkModuleMapGenerationPolicy + customFrameworkModuleMapContents: customFrameworkModuleMapContents ) } @@ -339,13 +346,13 @@ extension Runner.Options.BuildOptions { } extension Runner.Options.BuildOptionsContainer { - fileprivate func makeBuildOptions(descriptionPackage: DescriptionPackage) -> BuildOptions { - baseBuildOptions.makeBuildOptions(descriptionPackage: descriptionPackage) + fileprivate func makeBuildOptions(descriptionPackage: DescriptionPackage) throws -> BuildOptions { + try baseBuildOptions.makeBuildOptions(descriptionPackage: descriptionPackage) } - fileprivate func makeBuildOptionsMatrix(descriptionPackage: DescriptionPackage) -> [String: BuildOptions] { - buildOptionsMatrix.mapValues { runnerOptions in - baseBuildOptions.overridden(by: runnerOptions) + fileprivate func makeBuildOptionsMatrix(descriptionPackage: DescriptionPackage) throws -> [String: BuildOptions] { + try buildOptionsMatrix.mapValues { runnerOptions in + try baseBuildOptions.overridden(by: runnerOptions) .makeBuildOptions(descriptionPackage: descriptionPackage) } } diff --git a/Tests/ScipioKitTests/CacheSystemTests.swift b/Tests/ScipioKitTests/CacheSystemTests.swift index 1e73533a..e2589da2 100644 --- a/Tests/ScipioKitTests/CacheSystemTests.swift +++ b/Tests/ScipioKitTests/CacheSystemTests.swift @@ -30,7 +30,7 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault extraFlags: .init(swiftFlags: ["-D", "SOME_FLAG"]), extraBuildParameters: ["SWIFT_OPTIMIZATION_LEVEL": "-Osize"], enableLibraryEvolution: true, - frameworkModuleMapGenerationPolicy: .autoGenerated + customFrameworkModuleMapContents: nil ), clangVersion: "clang-1400.0.29.102", xcodeVersion: .init(xcodeVersion: "15.4", xcodeBuildVersion: "15F31d") @@ -53,11 +53,6 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault "SOME_FLAG" ] }, - "frameworkModuleMapGenerationPolicy" : { - "autoGenerated" : { - - } - }, "frameworkType" : "dynamic", "isDebugSymbolsEmbedded" : false, "sdks" : [ diff --git a/Tests/ScipioKitTests/RunnerTests.swift b/Tests/ScipioKitTests/RunnerTests.swift index 9e830dbe..4bf9b4b1 100644 --- a/Tests/ScipioKitTests/RunnerTests.swift +++ b/Tests/ScipioKitTests/RunnerTests.swift @@ -716,6 +716,6 @@ extension BuildOptions { extraFlags: nil, extraBuildParameters: nil, enableLibraryEvolution: true, - frameworkModuleMapGenerationPolicy: .autoGenerated + customFrameworkModuleMapContents: nil ) } From ec8e7af76051ea18b8af8290df94333f2f81ec7f Mon Sep 17 00:00:00 2001 From: giginet Date: Wed, 31 Jul 2024 17:17:11 +0900 Subject: [PATCH 10/11] Update tests to pass custom modulemap --- Tests/ScipioKitTests/CacheSystemTests.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/ScipioKitTests/CacheSystemTests.swift b/Tests/ScipioKitTests/CacheSystemTests.swift index e2589da2..ba75601b 100644 --- a/Tests/ScipioKitTests/CacheSystemTests.swift +++ b/Tests/ScipioKitTests/CacheSystemTests.swift @@ -9,6 +9,12 @@ Target: arm64-apple-darwin21.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin """ + private let customModuleMap = """ + framework module MyTarget { + umbrella header "umbrella.h" + export * + } + """.data(using: .utf8)! func testParseClangVersion() async throws { let hook = { arguments in @@ -30,7 +36,7 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault extraFlags: .init(swiftFlags: ["-D", "SOME_FLAG"]), extraBuildParameters: ["SWIFT_OPTIMIZATION_LEVEL": "-Osize"], enableLibraryEvolution: true, - customFrameworkModuleMapContents: nil + customFrameworkModuleMapContents: customModuleMap ), clangVersion: "clang-1400.0.29.102", xcodeVersion: .init(xcodeVersion: "15.4", xcodeBuildVersion: "15F31d") @@ -43,6 +49,7 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault { "buildOptions" : { "buildConfiguration" : "release", + "customFrameworkModuleMapContents" : "ZnJhbWV3b3JrIG1vZHVsZSBNeVRhcmdldCB7CiAgICB1bWJyZWxsYSBoZWFkZXIgInVtYnJlbGxhLmgiCiAgICBleHBvcnQgKgp9", "enableLibraryEvolution" : true, "extraBuildParameters" : { "SWIFT_OPTIMIZATION_LEVEL" : "-Osize" From cca2a67e509c957db8a8b0c78cada7a65738b568 Mon Sep 17 00:00:00 2001 From: giginet Date: Thu, 1 Aug 2024 12:05:53 +0900 Subject: [PATCH 11/11] Resolve SwiftPM warnings --- Tests/ScipioKitTests/CacheSystemTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ScipioKitTests/CacheSystemTests.swift b/Tests/ScipioKitTests/CacheSystemTests.swift index ba75601b..dfdcb660 100644 --- a/Tests/ScipioKitTests/CacheSystemTests.swift +++ b/Tests/ScipioKitTests/CacheSystemTests.swift @@ -14,7 +14,7 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault umbrella header "umbrella.h" export * } - """.data(using: .utf8)! + """ func testParseClangVersion() async throws { let hook = { arguments in @@ -36,7 +36,7 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault extraFlags: .init(swiftFlags: ["-D", "SOME_FLAG"]), extraBuildParameters: ["SWIFT_OPTIMIZATION_LEVEL": "-Osize"], enableLibraryEvolution: true, - customFrameworkModuleMapContents: customModuleMap + customFrameworkModuleMapContents: Data(customModuleMap.utf8) ), clangVersion: "clang-1400.0.29.102", xcodeVersion: .init(xcodeVersion: "15.4", xcodeBuildVersion: "15F31d")