It sounds like the OP has a binaryTarget not a C target like you do in Half.
I was able to get this working without a module map by including an intermediate "dummy" C target. My swift target depends on a C target that has bridge.c and include/bridge.h and then the dummy C target depends on the binaryTarget that represents my xcframework.
Here is a look at the directory structure:
FooSwift on main [+?] via π¦ v5.4.2
β― tree
.
βββ LICENSE
βββ Libs
β βββ FooRust.xcframework
β βββ Info.plist
β βββ ios-arm64
β β βββ Headers
β β β βββ libfoo.h
β β βββ libfoo-ios.a
β βββ ios-arm64_x86_64-maccatalyst
β β βββ Headers
β β β βββ libfoo.h
β β βββ libfoo-ios-macabi.a
β βββ ios-arm64_x86_64-simulator
β β βββ Headers
β β β βββ libfoo.h
β β βββ libfoo-ios-sim.a
β βββ macos-arm64_x86_64
β βββ Headers
β β βββ libfoo.h
β βββ libfoo-macos.a
βββ Package.swift
βββ README.md
βββ Sources
β βββ C
β β βββ bridge.c
β β βββ include
β β βββ bridge.h
β βββ FooSwift
β βββ Foo.swift
βββ Tests
βββ LinuxMain.swift
βββ Foo-Tests
βββ Foo_Tests.swift
βββ XCTestManifests.swift
16 directories, 18 files
and here's the package manifest:
FooSwift on main [+?] via π¦ v5.4.2
β― cat Package.swift
// swift-tools-version:5.4
import PackageDescription
let package = Package(
name: "FooSwift",
platforms: [
.iOS(SupportedPlatform.IOSVersion.v14),
.macOS(SupportedPlatform.MacOSVersion.v11),
],
products: [
.library(
name: "FooSwift",
targets: ["FooSwift"]),
],
targets: [
.target(
name: "FooSwift",
dependencies: ["C"],
path: "Sources/FooSwift",
sources: ["Uno.swift"]),
.target(
name: "C",
dependencies: ["FooStatic"],
path: "Sources/C"),
.binaryTarget(
name: "FooStatic",
path: "Libs/FooRust.xcframework"),
.testTarget(
name: "Foo-Tests",
dependencies: ["FooSwift"]),
]
)
You treat the intermediate C target as your "bridge" and in bridge.h you simply:
#include "libfoo.h"
My bridge.c file is essentially empty:
include "bridge.h"
void __dummy() {}