I am currently writing a swift package that statically links against a C library, but I am running into issues when trying to depend on it in an Xcode project.
- Bundling the C library as a XCFramework and declaring it a
binaryTargetworks fine, but the package cannot depend on multiple XCFrameworks that declare modules because it leads to file conflicts of the module.modulemap files. This only seems to be a problem when building via Xcode, and not when using SwiftPM directly - Bundling the C library as an artifactbundle and declaring it a
binaryTargetworks great with swift packages, but when I try include a package that depends (directly or indirectly via intermediate packages) on such a binary target the module(s) declared by the artifactbundle cannot be resolved
For reference:
Package.swift:
// swift-tools-version: 6.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "LuaJITSwift",
products: [
.library(
name: "LuaJITSwift",
type: .static,
targets: ["LuaJITSwift"]
),
],
targets: [
.binaryTarget(
name: "LuaJIT",
path: "LuaJIT.artifactbundle"
),
.target(
name: "LuaJITSwift",
dependencies: ["LuaJIT"]
),
.testTarget(
name: "LuaJITSwiftTests",
dependencies: ["LuaJITSwift"],
)
],
swiftLanguageModes: [.v6]
)
LuaJIT.artifactbundle/info.json:
{
"schemaVersion": "1.0",
"artifacts": {
"luaJIT": {
"version": "2.1",
"type": "staticLibrary",
"variants": [
{
"path": "luaJIT/macos-arm64/libluajit.a",
"supportedTriples": [
"arm64-apple-macos"
],
"staticLibraryMetadata": {
"headerPaths": [
"luaJIT/macos-arm64/include"
],
"moduleMapPath": "luaJIT/macos-arm64/include/module.modulemap"
}
},
{
"path": "luaJIT/macos-x86_64/libluajit.a",
"supportedTriples": [
"x86_64-apple-macos"
],
"staticLibraryMetadata": {
"headerPaths": [
"luaJIT/macos-x86_64/include"
],
"moduleMapPath": "luaJIT/macos-x86_64/include/module.modulemap"
}
}
]
}
}
}
module.modulemap:
module LuaJIT {
header "lua.h"
header "luaconf.h"
header "luajit.h"
header "lualib.h"
header "lauxlib.h"
export *
}
Which works fine on its own and with other SwiftPM packages, but when included in an Xcode project results in
