Repository navigation
Embed build/version info into spank_qrmi binary - #202
Conversation
| # Version of this plugin itself: read from VERSION.txt, a plain one-line | ||
| # file checked into the repo (see VERSION.txt next to this CMakeLists.txt). | ||
| # This is deliberately NOT derived from `git describe`: it works the same | ||
| # way whether built from a full git clone, a release tarball, or a zip | ||
| # export with no .git directory, and a version bump shows up as a normal, | ||
| # reviewable one-line diff in the PR instead of depending on someone | ||
| # remembering to push a tag. | ||
| set(SPANK_QRMI_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt") |
There was a problem hiding this comment.
Personally I'd set the version directly in the cmake project() directly. Still as visible in git diffs as VERSION.txt imho and doesn't need all this extra cmake logic
There was a problem hiding this comment.
Thanks for comment.
I think people will probably have different preferences on this. Personally, I prefer this approach because I don't want to update the CMakeLists.txt file frequently. Another advantage is that if we introduce CI workflows in the future, a simple VERSION.txt file would be easier to integrate into those workflows. I'd also be interested in hearing other people's opinions on this point.
There was a problem hiding this comment.
@awennersteen @MatthieuMoreau0 @yoonho @OkuyanBoga What do you think above?
There are 2 solutions for now. I'm open to switching the current implementation to project(spank_qrmi VERSION x.y.z) as I described:
VERSION.txt needs to be bumped by hand as part of future release PRs; it isn't tied to git tags. Open to switching this to project(spank_qrmi VERSION x.y.z) in CMakeLists.txt instead if that's preferred as the single source of truth — happy to adjust either way.
There was a problem hiding this comment.
@badtst I implemented the alternative approach and committed it. Thinking about it further, I can see your point. It does seem simpler and closer to the conventional way of handling versioning in CMake. Regarding CI, I don't see a significant difference in effort between the two approaches. In either case, updating the version would amount to a straightforward one-line file replacement. Could you please take a look at the latest updates when you have time?
There was a problem hiding this comment.
I'll take a look. Sure both options work but I feel like the spank plugin does not iterate nearly as fast as the QRMI itself and versions bump do not happen this frequently
badtst
left a comment
There was a problem hiding this comment.
Works as expected on my side, lgtm
|
After talking with @yoonho, I reconsidered the current implementation. At the moment, the SPANK plugin writes not only its own version information but also the version and Git hash of the statically linked QRMI library into |
|
@badtst @awennersteen @MatthieuMoreau0 @yoonho @OkuyanBoga I have recreated this PR based on above post. I also opened QRMI side changes - qiskit-community/qrmi#225. Could you please review and approve ? |
Description of Change
Review & Approve
Urgency: Not urgent. That said, a quick review would give us a chance to get this into the current customer upgrade window, so faster turnaround is appreciated if feasible.
Target date: Hoping to complete within one week.
Background
We recently ran into an issue during a cluster upgrade at one of our customers' data centers: quantum workloads stopped running due to a version mismatch between the deployed spank plugin binary and the QRMI Python package. While investigating, it became clear that being able to quickly determine
would have made this kind of issue much easier to diagnose.
As described in this PR, I addressed this by embedding version information directly into the binary's ELF headers, making it possible to retrieve the relevant version information with standard Linux commands.
Summary
Currently there is no way to determine which version of
spank_qrmi.sois actually deployed without rebuilding or running the plugin. This PR embeds that information as a plain string in the binary so it can be inspectedoffline with
strings/readelf, e.g.:QRMI will embed the same kind of marker into its own
.version_infosection (see the companion change in the QRMI crate), so the two show up side by side in the same linked.so:This lets an operator answer "which spank_qrmi build, and which QRMI build, are actually linked into this
.so?" directly from the deployed file, without rebuilding or invoking the plugin.Changes
CMakeLists.txt:VERSION x.y.zto the existingproject(spank_qrmi ...)declaration, so this plugin's own version is CMake's standardPROJECT_VERSION, bumped by hand as part of a release PR.git rev-parse --short=12 HEAD), falling back to"unknown"when built outside a git checkout (e.g. a tarball/zip export).spank_qrmi_version.hunder${CMAKE_BINARY_DIR}/generatedviafile(WRITE ...). Both values are known atcmake ..configure time (unlike QRMI's own version, which is only available after itsExternalProjectfetch step), so no extra build-time step, target dependency, or separate template file is needed here.spank_qrmi.c: includes the generatedspank_qrmi_version.hand embeds a version string in a dedicated.version_infoELF section via__attribute__((section(".version_info"), used)), readable withstringsorreadelf -p .version_infowithout executing the plugin.Note: an earlier version of this PR also duplicated QRMI's own crate version/git-hash into this same string. That's been dropped now that QRMI embeds its own
.version_infomarker directly (see the companion QRMI PR),so
spank_qrmi.so's string only needs to describe itself.Testing
-Wall -Wextra -Werror -O2 -pedantic -Wconversion -Wwrite-strings -Wfloat-equal) with no new warnings.stringsandreadelf -p .version_infoon the compiled object, and that it coexists correctly in the same section alongside QRMI's own marker once linked together (same section name, distinct symbol names — no collision).cmake .. && makebuild against the real QRMI ExternalProject fetch path (both default GitHub fetch and-DQRMI_ROOT=local-checkout path), and a check that the linkedspank_qrmi.sostill loads correctly underslurmd.Notes / follow-ups
strip -s(full strip) on the final.so, custom ELF sections like.version_infocan be removed along with symbol tables. If binary stripping is part of the deploy process, either usestrip --strip-debuginstead, or add--keep-section=.version_infoto whateverstrip/objcopyinvocation is used.project(...VERSION x.y.z)line as part of future release PRs; it isn't tied to git tags, and isn't currently overridable from thecmakecommand line(
project(VERSION ...)always wins over any-Dof the same name)..version_infomarker) to get the full picture; this PR alone only covers the spank_qrmi side.Related
qiskit-community/qrmi#225
Checklist ✅
Ticket