Hi. I have some c++ code that uses some embedded (copied over) files from another open source project (Asio). I have previously managed to make it compile as a standalone CMake library using c++ only (c++20).
Now I am trying to use SPM (Swift 6.0) to build a mixed language project, but it can never find my asio.hpp when I run swift build. Here is a link to the repository: GitHub - RussBaz/lumengine
Can anyone please advise how to properly set up my Package.swift file for this case? I am pretty sure it is related to the headerSearchPath, but I can never find the correct path.
I have progressed a bit further. By adding a public header path and a .cpp file and runing swift build, I am now getting different errors. Such as:
/Users/user/Projects/GitHub/lumengine/Sources/cxxLumengine/asio/include/asio/detail/io_uring_null_buffers_op.hpp:32:41: error: expected class name
30 |
31 | template <typename Handler, typename IoExecutor>
32 | class io_uring_null_buffers_op : public io_uring_operation
| `- error: expected class name
33 | {
34 | public:
These errors are not part of my code, though.
However, this is not the strangest part because I managed to compile the project myself using clang++ and swiftc directly! Here are the two commands that I used successfully (from the project root):
I don't think you've included your actual sources. I feel your pain - I had to wrap a complicated library with near zero C++ skills.
I found I needed to be absolutely explicit about which C and C++ sources needed to be included. Which is a useful feature I suppose, if only a subset needs to be used.
It seems that compiler knows to look in a folder with the same name as the target for the sources, so these can be relative to that folder.
Your target needs to look something like this:
.target(
name: "CLibrary",
sources: [
"Implementation.cpp", // This is relative to the CLibrary folder
...
],
cxxSettings: [
.headerSearchPath("include"),
]
),
Thank you for your suggestions, but in the end, thankfully, I did not have to manually enumerate every file (fixed it only today). Here is how I structured my Package.swift: