Skip to content

Commit 4acb4dc

Browse files
authored
feat: stop dynamic linking (#9)
1 parent 988c688 commit 4acb4dc

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ jobs:
9090
run: |
9191
cargo build --release --locked --target ${{ matrix.target }}
9292
93+
- name: Verify dynamic dependencies (unix)
94+
if: runner.os != 'Windows'
95+
shell: bash
96+
run: |
97+
set -euxo pipefail
98+
BIN="target/${{ matrix.target }}/release/sshpod"
99+
chmod +x ./scripts/check-dynamic-deps.sh
100+
./scripts/check-dynamic-deps.sh "$BIN"
101+
93102
- name: Package (unix)
94103
if: runner.os != 'Windows'
95104
id: package_unix

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ whoami = "1"
1414
log = "0.4"
1515
env_logger = "0.11"
1616
flate2 = "1"
17-
xz2 = "0.1"
17+
xz2 = { version = "0.1", features = ["static"] }

scripts/check-dynamic-deps.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ $# -ne 1 ]]; then
5+
echo "usage: $0 <binary>" >&2
6+
exit 2
7+
fi
8+
9+
bin="$1"
10+
11+
if [[ ! -f "$bin" ]]; then
12+
echo "binary not found: $bin" >&2
13+
exit 2
14+
fi
15+
16+
case "$(uname -s)" in
17+
Darwin)
18+
unexpected=0
19+
while IFS= read -r dep; do
20+
[[ -z "$dep" ]] && continue
21+
case "$dep" in
22+
/System/Library/*|/usr/lib/*)
23+
;;
24+
*)
25+
echo "unexpected dynamic dependency: $dep" >&2
26+
unexpected=1
27+
;;
28+
esac
29+
done < <(otool -L "$bin" | tail -n +2 | awk '{print $1}')
30+
exit "$unexpected"
31+
;;
32+
Linux)
33+
unexpected=0
34+
while IFS= read -r dep; do
35+
[[ -z "$dep" ]] && continue
36+
case "$dep" in
37+
libc.so.*|libgcc_s.so.*|libm.so.*|libpthread.so.*|librt.so.*|libdl.so.*|libutil.so.*|libresolv.so.*|libanl.so.*|libnsl.so.*|ld-linux-*.so.*|ld64.so.*)
38+
;;
39+
*)
40+
echo "unexpected dynamic dependency: $dep" >&2
41+
unexpected=1
42+
;;
43+
esac
44+
done < <(readelf -d "$bin" | sed -n 's/.*Shared library: \[\(.*\)\]/\1/p')
45+
exit "$unexpected"
46+
;;
47+
*)
48+
echo "unsupported host OS: $(uname -s)" >&2
49+
exit 2
50+
;;
51+
esac

0 commit comments

Comments
 (0)