Skip to content

Commit 234c03f

Browse files
committed
cdylib: apply versioning to symbols
1 parent ca81aa4 commit 234c03f

File tree

4 files changed

+133
-2
lines changed

4 files changed

+133
-2
lines changed

.github/workflows/checks.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
124124
# build
125125
- name: cargo build
126-
run: cargo build --target ${{matrix.target}} ${{ matrix.flags }}
126+
run: cargo build -vv --target ${{matrix.target}} ${{ matrix.flags }}
127127

128128
# ensure tests for "real" features work standalone
129129
- name: cargo test --no-default-features --features ...
@@ -390,6 +390,13 @@ jobs:
390390
run: |
391391
cargo build --release --target ${{matrix.target}} --features=semver-prefix
392392
objdump -tT target/${{matrix.target}}/release/deps/libz_rs.so | grep -q -E "LIBZ_RS_SYS_v0.[0-9]+.x_uncompress" || (echo "symbol not found!" && exit 1)
393+
- name: "cdylib: version-symbols"
394+
working-directory: libz-rs-sys-cdylib
395+
run: |
396+
cargo build --release --target ${{matrix.target}} --features=version-symbols
397+
objdump -T target/${{matrix.target}}/release/deps/libz_rs.so
398+
objdump -T target/${{matrix.target}}/release/deps/libz_rs.so | grep "ZLIB"
399+
objdump -T target/${{matrix.target}}/release/deps/libz_rs.so | grep -q -E "ZLIB_1.2.2.3 deflateTune" || (echo "symbol not found!" && exit 1)
393400
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends valgrind
394401
- name: "cdylib: example.c"
395402
env:

libz-rs-sys-cdylib/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version = "1.75" # MSRV
1212

1313
[lib]
1414
name = "z_rs" # turns into e.g. `libz_rs.so`
15-
crate-type = ["cdylib", "lib"]
15+
crate-type = ["cdylib", "staticlib", "lib"]
1616

1717
[profile.dev]
1818
panic = "abort" # abort on panics. This is crucial, unwinding would cause UB!
@@ -29,6 +29,7 @@ c-allocator = ["libz-rs-sys/c-allocator"] # by default, use malloc/free for memo
2929
rust-allocator = ["libz-rs-sys/rust-allocator", "libz-rs-sys/std"] # by default, use the rust global alloctor for memory allocation
3030
custom-prefix = ["libz-rs-sys/custom-prefix"] # use the LIBZ_RS_SYS_PREFIX to prefix all exported symbols
3131
semver-prefix = ["libz-rs-sys/semver-prefix"] # prefix all symbols in a semver-compatible way
32+
version-symbols = []
3233
capi = []
3334
gz = ["dep:libc"] # support for the `gz*` functions is experimental
3435
gzprintf = []

libz-rs-sys-cdylib/build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::{env, path::PathBuf};
2+
3+
fn main() {
4+
// Prevent fighting over the symbol version between libz-rs and us in the test crate.
5+
if env::var_os("CARGO_FEATURE_VERSION_SYMBOLS").is_none() {
6+
return;
7+
}
8+
9+
let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
10+
match os.as_str() {
11+
"linux" | "android" => { /* fall through */ }
12+
_ => return,
13+
};
14+
15+
let map = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("zlib.map");
16+
17+
println!("cargo:rerun-if-changed={}", map.display());
18+
19+
println!(
20+
"cargo:rustc-link-arg=-Wl,--version-script={}",
21+
map.display()
22+
);
23+
24+
println!("cargo:rustc-link-arg=-Wl,--undefined-version");
25+
}

libz-rs-sys-cdylib/zlib.map

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
ZLIB_1.2.0 {
2+
global:
3+
compressBound;
4+
deflateBound;
5+
inflateBack;
6+
inflateBackEnd;
7+
inflateBackInit_;
8+
inflateCopy;
9+
local:
10+
deflate_copyright;
11+
inflate_copyright;
12+
zcalloc;
13+
zcfree;
14+
z_errmsg;
15+
gz_error;
16+
gz_intmax;
17+
_*;
18+
};
19+
20+
ZLIB_1.2.0.2 {
21+
gzclearerr;
22+
gzungetc;
23+
zlibCompileFlags;
24+
} ZLIB_1.2.0;
25+
26+
ZLIB_1.2.0.8 {
27+
deflatePrime;
28+
} ZLIB_1.2.0.2;
29+
30+
ZLIB_1.2.2 {
31+
adler32_combine;
32+
crc32_combine;
33+
deflateSetHeader;
34+
inflateGetHeader;
35+
} ZLIB_1.2.0.8;
36+
37+
ZLIB_1.2.2.3 {
38+
deflateTune;
39+
gzdirect;
40+
} ZLIB_1.2.2;
41+
42+
ZLIB_1.2.2.4 {
43+
inflatePrime;
44+
} ZLIB_1.2.2.3;
45+
46+
ZLIB_1.2.3.3 {
47+
adler32_combine64;
48+
crc32_combine64;
49+
gzopen64;
50+
gzseek64;
51+
gztell64;
52+
inflateUndermine;
53+
} ZLIB_1.2.2.4;
54+
55+
ZLIB_1.2.3.4 {
56+
inflateReset2;
57+
inflateMark;
58+
} ZLIB_1.2.3.3;
59+
60+
ZLIB_1.2.3.5 {
61+
gzbuffer;
62+
gzoffset;
63+
gzoffset64;
64+
gzclose_r;
65+
gzclose_w;
66+
} ZLIB_1.2.3.4;
67+
68+
ZLIB_1.2.5.1 {
69+
deflatePending;
70+
} ZLIB_1.2.3.5;
71+
72+
ZLIB_1.2.5.2 {
73+
deflateResetKeep;
74+
gzgetc_;
75+
inflateResetKeep;
76+
} ZLIB_1.2.5.1;
77+
78+
ZLIB_1.2.7.1 {
79+
inflateGetDictionary;
80+
gzvprintf;
81+
} ZLIB_1.2.5.2;
82+
83+
ZLIB_1.2.9 {
84+
inflateCodesUsed;
85+
inflateValidate;
86+
uncompress2;
87+
gzfread;
88+
gzfwrite;
89+
deflateGetDictionary;
90+
adler32_z;
91+
crc32_z;
92+
} ZLIB_1.2.7.1;
93+
94+
ZLIB_1.2.12 {
95+
crc32_combine_gen;
96+
crc32_combine_gen64;
97+
crc32_combine_op;
98+
} ZLIB_1.2.9;

0 commit comments

Comments
 (0)