[draft] swift: Config for Swift Package build #2420
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently we have opened a new ThorVG for Swift repo: thorvg.swift.
Code will be migrated from a Swift fork thorvg-swift. You can see more details here at the GitHub issue on the repo.
In order to build the Swift Package, with the thorvg core as a submodule inside the thorvg.swift repo, the following changes need to take place for the upstream thorvg repo. These are what are currently allowing the thorvg-swift repo to build.
Note: I've marked this PR as draft because these changes are particular to the new thorvg.swift repo and are subject to change.
Config header file
When building the thorvg source using the
meson
build system, we spit out a config.h inside the outputbuilddir/
directory. Many of the C++ source files refer to this at compile time.Swift Package Manager doesn't follow the same paradigm, and requires all files to be present in the target directory at compile time. Thus, we need to generate a
config.h
file ahead of time so that SPM can see that header file and successfully build all of the C++ source files.For time being, I've put this underneath the C API bindings folder, but am open to another destination for this file.
Symbolic link for
inc
folderSwift Package Manager allows us to define a single path to the source code that we wish to build. We use the path parameter of this target function available to us inside the
Package.swift
manifest.However, the umbrella file of the thorvg API (thorvg.h) is one step removed from the
src
directory. For more context, have a look at this diagram:We need this umbrella file to be accessible by Swift Package Manager because many of the C++ files rely on that header file to build successfully. Currently, the meson build system takes care of this, but to get around this issue, we need to add a symbolic link inside the
src/
directory pointing to theinc/
directory. After we do this, the package builds successfully.I'm unsure how we get around this in a more elegant way without moving many of the files around, but this is the current solution that works.