I'm trying to wrap a C library in a Swift package, and have come across an error I've never seen before and can't seem to resolve. I'm trying to wrap the xxHash
library, and I have a compiling library with a Swift target wrapping the C API in some nice syntax. It compiles regularly, but when I go to try and run tests on it or include it in another package, I get the following error:
Build input file cannot be found: '/Users/.../Build/Products/Debug/CxxHash.o'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?
My project structure is set up like so:
import PackageDescription
let package = Package(
name: "xxHash",
products: [
.library(
name: "xxHash",
targets: ["xxHash", "CxxHash"]
),
],
targets: [
.target(
name: "xxHash",
dependencies: ["CxxHash"]
),
.target(
name: "CxxHash"
),
.testTarget(
name: "xxHashTests",
dependencies: ["xxHash"]
),
]
)
Package.swift
Sources/
CxxHash/include/
xxhash.h
module.modulemap
xxhash_swift.h
xxHash/
xxHash.swift
Tests/xxHashTests
xxHashTests.swift
My modulemap:
module CxxHash {
umbrella header "xxhash_swift.h"
export *
}
And the xxhash_swift.h
is just setting some compile flags and including the xxhash.h
header:
#ifndef __xxhash_swift_h__
#define __xxhash_swift_h__
#define XXH_INLINE_ALL
#define XXH_PRIVATE_API
#define XXH_STATIC_LINKING_ONLY
#include "xxhash.h"
#endif /* __xxhash_swift_h__ */
Really not sure where to go from here, I've uploaded the project to GitHub if anyone wants to take a look and maybe spot something obvious I'm missing!