feat/ci: ensure static linkage of C deps#1684
Merged
Conversation
52941c1 to
db6e876
Compare
Comment on lines
63
to
78
| metadata=$(cargo metadata --no-deps --format-version 1) | ||
| mapfile -t bin_targets < <( | ||
| echo "${metadata}" | jq -r '.packages[].targets[] | select(.kind[] == "bin") | .name' | sort -u | ||
| ) | ||
| [[ ${#bin_targets[@]} -ne 0 ]] || { echo "No bin targets found."; exit 1; } | ||
| for bin_target in "${bin_targets[@]}"; do | ||
| binary_path="target/debug/${bin_target}" | ||
| [[ -x "${binary_path}" ]] || { echo "Missing binary: ${binary_path}"; exit 1; } | ||
| ldd_output="$(ldd "${binary_path}" 2>&1 || true)" | ||
| [[ "${ldd_output}" != *"not a dynamic executable"* ]] || continue | ||
| ! echo "${ldd_output}" | grep -E -q 'librocksdb|libsqlite' || { | ||
| echo "Dynamic linkage detected for ${bin_target}." | ||
| echo "${ldd_output}" | ||
| exit 1 | ||
| } | ||
| done |
Collaborator
There was a problem hiding this comment.
I think some comments for the next poor non-bash soul would be kind.
Suggested change
| metadata=$(cargo metadata --no-deps --format-version 1) | |
| mapfile -t bin_targets < <( | |
| echo "${metadata}" | jq -r '.packages[].targets[] | select(.kind[] == "bin") | .name' | sort -u | |
| ) | |
| [[ ${#bin_targets[@]} -ne 0 ]] || { echo "No bin targets found."; exit 1; } | |
| for bin_target in "${bin_targets[@]}"; do | |
| binary_path="target/debug/${bin_target}" | |
| [[ -x "${binary_path}" ]] || { echo "Missing binary: ${binary_path}"; exit 1; } | |
| ldd_output="$(ldd "${binary_path}" 2>&1 || true)" | |
| [[ "${ldd_output}" != *"not a dynamic executable"* ]] || continue | |
| ! echo "${ldd_output}" | grep -E -q 'librocksdb|libsqlite' || { | |
| echo "Dynamic linkage detected for ${bin_target}." | |
| echo "${ldd_output}" | |
| exit 1 | |
| } | |
| done | |
| # Pull out the binary names from `cargo metadata`. | |
| metadata=$(cargo metadata --no-deps --format-version 1) | |
| bin_targets=$( | |
| echo "${metadata}" | jq -r '.packages[].targets[] | select(.kind[] == "bin") | .name' | sort -u' | |
| ) | |
| # Sanity check, abort if no binaries found. | |
| [ -z ${bin_targets} ] || { | |
| echo "::error::No binaries targets found."; | |
| exit 1; | |
| } | |
| # Map to an array so we can iterate over entries. | |
| mapfile -t bin_targets < <$bin_targets | |
| # Inspect each binary's linker output for `rocksdb` and `sqlite`. | |
| # If they're present then we know they're dynamically linked and | |
| # are _not_ statically linked (bad). | |
| for bin_target in "${bin_targets[@]}"; do | |
| # Sanity check that the binary was built. | |
| binary_path="target/debug/${bin_target}" | |
| [[ -x "${binary_path}" ]] || { | |
| echo "::error::Missing binary: ${binary_path}"; | |
| exit 1; | |
| } | |
| # I'm actually unsure why this is short-circuiting `|| true` | |
| ldd_output="$(ldd "${binary_path}" 2>&1 || true)" | |
| # Should this not be an unexpected abort? Or are there binaries | |
| # that we have like this? | |
| [[ "${ldd_output}" != *"not a dynamic executable"* ]] || continue | |
| # I also don't know this `! echo` syntax? | |
| ! echo "${ldd_output}" | grep -E -q 'librocksdb|libsqlite' || { | |
| echo "Dynamic linkage detected for ${bin_target}." | |
| echo "${ldd_output}" | |
| exit 1 | |
| } | |
| done |
Contributor
Author
There was a problem hiding this comment.
! is inverting the bool exit coe of echo "foo" | grep ..
Contributor
Author
There was a problem hiding this comment.
Simplified to prefer if-cases over [[ .. ]] || .. pattern and avoiding brace-less inversions
Mirko-von-Leipzig
approved these changes
Feb 18, 2026
10fff50 to
7f72ace
Compare
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.
Adds a CI step to check compiled binaries to be statically linked against
libsqliteandlibrocksdb