Apologies if this is straightforward. I have a package that contains C/C++ code and I want to load some resources from inside it. I’ve got it working by cobbling together the following monstrosity, where I hard-code the path to the target’s bundle.
But what I really want is to get that dynamically as you would using Bundle.module in Swift. Is there a sensible way to do this using CoreFoundation APIs?
I haven't tried this, but I'm almost certain SwiftPM only generates a resource bundle accessor for Swift targets and for Clang targets that contain Objective-C.
/// Generate the resource bundle accessor, if appropriate.
private func generateResourceAccessor() throws {
// Only generate access when we have a bundle and ObjC files.
guard let bundlePath = self.bundlePath, clangTarget.sources.containsObjcFiles else { return }
…
Thanks a lot @ole! Sure enough I can see the preprocessor define from Objective-C files in the target. For my use case this works fine, and I can just add a little Objective-C++ helper to my target.
Here’s a quick first pass at a helper for anyone looking to get package resource paths from C++. Corrections welcome — I’ve no idea if the memory management and string encoding is right here.