build: define gitsha for swift package builds - #410
Merged
Conversation
mx::core::gitSha is defined by GitSha.cpp, which cmake/GitSha.cmake renders from Version.cpp.in into the build tree. The Swift package has no code-generation step and simply globs src/, so the Mx product compiles Version.h's declaration with no definition anywhere. Nothing catches this today. `swift build --product Mx` only archives a static library, and an undefined symbol in an archive is not diagnosed until something links an executable against it. It surfaced when komp started consuming mx through the package rather than a prebuilt xcframework, failing with an undefined mx::core::gitSha referenced from mx::core::mxSoftwareAttribution(). Add GitShaDefault.cpp defining gitSha as "unknown", which is the value Version.h already documents for a build made outside a git checkout. CMake never compiles this file, so the generated definition remains the only one there: mx_core's source list is explicit and no glob covers mx/core/*.cpp. Verified by building the CMake api target with the file present, which neither compiled it nor reported a duplicate symbol.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Human Summary
Basically the CMake stuff doesn't run if you consume the library through the Swift package. So this was the agent solution for that: a file that CMake doesn't glob but that Swift does include, which writes the sha as
unknown. This is not ideal. I want to find a better versioning mechanism but everything is hard without a package manager.Summary
mx::core::gitShais declared in Version.h and defined byGitSha.cpp, whichcmake/GitSha.cmakerenders from
Version.cpp.ininto the build tree at build time. The Swift package has no codegeneration step and simply globs src/, so the Mx product compiles the declaration with no
definition anywhere.
Nothing catches this today.
swift build --product Mxonly archives a static library, and anundefined symbol in an archive is not diagnosed until something links an executable against it.
It surfaced when komp switched to consuming mx through the Swift package instead of a prebuilt
xcframework:
This adds GitShaDefault.cpp defining
gitShaas "unknown", which is the valueVersion.halreadydocuments for a build made outside a git checkout.
CMake builds are unaffected. The mx_core source list is explicit and no glob covers
mx/core/*.cpp, so the generated definition stays the only one there.Worth considering as a follow-up: the swift CI job could link a small executable rather than only
archiving, so this class of defect cannot go latent again. Left out of this PR because it is a
choice about the workflow rather than part of the fix.
Testing
ar t libmx_core.alists GitSha.cpp.o and no GitShaDefault.o, so CMake still uses the generated definitionReferences