Is there currently a way to bundle Swift code? Ri...
# swift-export
s
Is there currently a way to bundle Swift code? Right now, I’m using the following workaround:
Copy code
tasks.matching { task -> task.name.contains("GenerateSPMPackage") }.configureEach {
    val swiftBundleFileSystem = project.objects.newInstance<SwiftBundlingFileSystem>()

    val swiftSourceDir = layout.projectDirectory.dir("src/iosMain/swift")

    inputs.dir(swiftSourceDir).withPathSensitivity(PathSensitivity.RELATIVE)

    doLast {
        if (!swiftSourceDir.asFile.isDirectory) {
            logger.warn("Swift source directory $swiftSourceDir does not exist or is not a directory; Skipping Swift Bundling.")
            return@doLast
        }

        val moduleName = inputs.properties["swiftApiModuleName"] as? String
        if (moduleName.isNullOrBlank()) {
            logger.warn("Missing 'swiftApiModuleName' on ${name}; Skipping Swift Bundling.")
            return@doLast
        }

        val sourcesDir = outputs.files.find { dir -> dir.name == "Sources" }
        if (sourcesDir == null) {
            logger.warn("Could not locate 'Sources' in outputs of ${name}; Skipping Swift Bundling.")
            return@doLast
        }

        val destDir = sourcesDir.resolve(moduleName)

        swiftBundleFileSystem.fs.copy {
            from(swiftSourceDir) {
                include("**/*.swift")
                includeEmptyDirs = false
            }
            into(destDir)
        }
    }
}

interface SwiftBundlingFileSystem {
    @get:Inject val fs: FileSystemOperations
}
a
a way to bundle Swift code
Can you please elaborate what you are trying to do? If you mean this - then no, swift export currently supports only direct source based integration. Please vote for the ticket to highlight your interest in it.
s
@Artem Olkov I meant a similar functionality to what's described here: Swift code bundling
a
No, that functionality is not available at the moment and I don't have a public timeline to share with you here. Please vote for the ticket. If it's no bother for you - please add a description of your usecase. KT-81797 Bundling Swift Source code with swift export
👍 1