Skip to content

build: define gitsha for swift package builds - #410

Merged
webern merged 1 commit into
mainfrom
fix/gitsha-swift-package
Aug 22, 2026
Merged

build: define gitsha for swift package builds#410
webern merged 1 commit into
mainfrom
fix/gitsha-swift-package

Conversation

@webern

@webern webern commented Aug 22, 2026

Copy link
Copy Markdown
Owner

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::gitSha is declared in Version.h and defined by GitSha.cpp, which cmake/GitSha.cmake
renders from Version.cpp.in into the build tree at build time. The Swift package has no code
generation step and simply globs src/, so the Mx product compiles the 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 switched to consuming mx through the Swift package instead of a prebuilt
xcframework:

Undefined symbols for architecture x86_64:
  "mx::core::gitSha", referenced from:
      mx::core::mxSoftwareAttribution() in Mx.o

This adds GitShaDefault.cpp defining gitSha as "unknown", which is the value Version.h already
documents 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

  • CMake api target builds with the new file present, never compiles it, and reports no duplicate symbol
  • ar t libmx_core.a lists GitSha.cpp.o and no GitShaDefault.o, so CMake still uses the generated definition
  • A consumer program linked against the Swift package objects builds and runs
  • Removing only GitShaDefault.cpp.o from that same link fails with undefined mx::core::gitSha, confirming this file is what resolves it
  • komp builds and runs on macOS and the iPad simulator against the Swift package

References

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.
@webern webern added bug software defect non-breaking fixes or implementation that do not require breaking changes core Affects the mx::core layer ai Issues opened by, or through, a coding agent. labels Aug 22, 2026
@webern webern changed the title fix: define gitSha for Swift package builds build: define gitsha for swift package builds Aug 22, 2026
@webern
webern merged commit f69b818 into main Aug 22, 2026
8 checks passed
@webern
webern deleted the fix/gitsha-swift-package branch August 22, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Issues opened by, or through, a coding agent. bug software defect core Affects the mx::core layer non-breaking fixes or implementation that do not require breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant