diff --git a/Generator/Sources/SwiftWinRT/Writing/ABIModule.swift b/Generator/Sources/SwiftWinRT/Writing/ABIModule.swift index 4dfc4f9..175012c 100644 --- a/Generator/Sources/SwiftWinRT/Writing/ABIModule.swift +++ b/Generator/Sources/SwiftWinRT/Writing/ABIModule.swift @@ -6,13 +6,11 @@ import WindowsMetadata internal func writeABIModule(_ module: Module, directoryPath: String, generateCMakeLists: Bool) throws { let includeDirectoryPath = "\(directoryPath)\\include" + let includeSWRTDirectoryPath = "\(includeDirectoryPath)\\SWRT" - try writeABIFile(module: module, toPath: "\(includeDirectoryPath)\\\(module.name).h") - // FIXME: Support transitive references? - for referencedModule in module.references { - guard !referencedModule.isEmpty else { continue } - try writeABIFile(module: referencedModule, toPath: "\(includeDirectoryPath)\\\(referencedModule.name).h") - } + try writeABIFile(module: module, toPath: "\(includeSWRTDirectoryPath)\\\(module.name).h") + + try writeModulemapFile(module: module, toPath: "\(includeDirectoryPath)\\module.modulemap") if generateCMakeLists { let cmakeListsWriter = CMakeListsWriter(output: FileTextOutputStream( @@ -32,7 +30,7 @@ fileprivate func writeABIFile(module: Module, toPath path: String) throws { for referencedModule in module.references { guard !referencedModule.isEmpty else { continue } - cHeaderWriter.writeInclude(pathSpec: "\(referencedModule.name).h", kind: .doubleQuotes) + cHeaderWriter.writeInclude(pathSpec: "SWRT/\(referencedModule.name).h", kind: .doubleQuotes) } // Declare enums @@ -130,3 +128,11 @@ fileprivate func getSortedInterfaces(module: Module) throws -> [BoundType] { interfacesByMangledName.sort { $0.key < $1.key } return Array(interfacesByMangledName.values) } + +fileprivate func writeModulemapFile(module: Module, toPath path: String) throws { + let output = IndentedTextOutputStream(inner: FileTextOutputStream(path: path, directoryCreation: .ancestors)) + output.writeIndentedBlock(header: "module \(module.abiModuleName) {", footer: "}") { + output.writeFullLine("header \"SWRT/\(module.name).h\"") + output.writeFullLine("export *") + } +} diff --git a/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift b/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift index ef2b124..6f73e4f 100644 --- a/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift +++ b/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift @@ -22,22 +22,23 @@ func writeSwiftPackageFile( package.targets.append(abiModuleTarget) // Swift module - var swiftModuleTarget: SwiftPackage.Target = .target(name: module.name) - swiftModuleTarget.path = "\(module.name)/Module" - swiftModuleTarget.dependencies.append(.product(name: "WindowsRuntime", package: "swift-winrt")) + var projectionModuleTarget: SwiftPackage.Target = .target(name: module.name) + projectionModuleTarget.path = "\(module.name)/Projection" + projectionModuleTarget.dependencies.append(.product(name: "WindowsRuntime", package: "swift-winrt")) for referencedModule in module.references { guard !referencedModule.isEmpty else { continue } - swiftModuleTarget.dependencies.append(.target(name: referencedModule.name)) + abiModuleTarget.dependencies.append(.target(name: referencedModule.abiModuleName)) + projectionModuleTarget.dependencies.append(.target(name: referencedModule.name)) } - swiftModuleTarget.dependencies.append(.target(name: module.abiModuleName)) + projectionModuleTarget.dependencies.append(.target(name: module.abiModuleName)) - package.targets.append(swiftModuleTarget) + package.targets.append(projectionModuleTarget) // Define a product for the module var moduleProduct: SwiftPackage.Product = .library(name: module.name, type: dynamicLibraries ? .dynamic : nil, targets: []) - moduleProduct.targets.append(swiftModuleTarget.name) + moduleProduct.targets.append(projectionModuleTarget.name) moduleProduct.targets.append(abiModuleTarget.name) // Namespace modules diff --git a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift index abf19b1..79cb03d 100644 --- a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift +++ b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift @@ -39,7 +39,7 @@ fileprivate func writeModuleFiles( try writeABIModule(module, directoryPath: "\(directoryPath)\\ABI", generateCMakeLists: generateCMakeLists) try writeSwiftModuleFiles( - module, directoryPath: "\(directoryPath)\\Module", + module, directoryPath: "\(directoryPath)\\Projection", generateCMakeLists: generateCMakeLists, dynamicLibrary: dynamicLibrary) if !module.flattenNamespaces { @@ -51,7 +51,7 @@ fileprivate func writeModuleFiles( path: "\(directoryPath)\\CMakeLists.txt", directoryCreation: .ancestors)) writer.writeAddSubdirectory("ABI") - writer.writeAddSubdirectory("Module") + writer.writeAddSubdirectory("Projection") if !module.flattenNamespaces { writer.writeAddSubdirectory("Namespaces") }