Skip to content

Comments

feat/ci: ensure static linkage of C deps#1684

Merged
drahnr merged 2 commits intonextfrom
bernhard-add-ldd-ci-step-check
Feb 18, 2026
Merged

feat/ci: ensure static linkage of C deps#1684
drahnr merged 2 commits intonextfrom
bernhard-add-ldd-ci-step-check

Conversation

@drahnr
Copy link
Contributor

@drahnr drahnr commented Feb 17, 2026

Adds a CI step to check compiled binaries to be statically linked against libsqlite and librocksdb

@Mirko-von-Leipzig Mirko-von-Leipzig self-requested a review February 17, 2026 09:33
@drahnr drahnr added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Feb 17, 2026
@drahnr drahnr force-pushed the bernhard-add-ldd-ci-step-check branch from 52941c1 to db6e876 Compare February 17, 2026 09:44
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@drahnr drahnr Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! is inverting the bool exit coe of echo "foo" | grep ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified to prefer if-cases over [[ .. ]] || .. pattern and avoiding brace-less inversions

@drahnr drahnr force-pushed the bernhard-add-ldd-ci-step-check branch from 10fff50 to 7f72ace Compare February 18, 2026 14:13
@drahnr drahnr merged commit 2f26190 into next Feb 18, 2026
19 checks passed
@drahnr drahnr deleted the bernhard-add-ldd-ci-step-check branch February 18, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants