Skip to content

Commit

Permalink
add semver-prefix feature for use by bzip2-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jan 28, 2025
1 parent d5d181b commit 315aa16
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ jobs:
run: |
cargo build --release --target ${{matrix.target}} --features=custom-prefix
objdump -tT target/${{matrix.target}}/release/deps/libbz2_rs.so | grep -q "MY_CUSTOM_PREFIX_BZ2_bzCompressInit" || (echo "symbol not found!" && exit 1)
- name: "cdylib: semver-prefix"
working-directory: libbz2-rs-sys-cdylib
run: |
cargo build --release --target ${{matrix.target}} --features=semver-prefix
objdump -tT target/${{matrix.target}}/release/deps/libbz2_rs.so | grep -q -E "LIBBZ2_RS_SYS_v0.[0-9]+.x_BZ2_bzCompressInit" || (echo "symbol not found!" && exit 1)
cargo-c-dynamic-library:
name: cargo-c dynamic library
Expand Down
4 changes: 2 additions & 2 deletions libbz2-rs-sys-cdylib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libbz2-rs-sys-cdylib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bench = false
default = ["stdio"]
stdio = ["libbz2-rs-sys/stdio"]
custom-prefix = ["libbz2-rs-sys/custom-prefix"] # use the LIBBZ2_RS_SYS_PREFIX to prefix all exported symbols
semver-prefix = ["libbz2-rs-sys/semver-prefix"] # prefix all symbols in a semver-compatible way
capi = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions libbz2-rs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rust-allocator = [] # use the rust global allocator (rust is picked over c if bo
std = ["rust-allocator"]
custom-prefix = [] # use the LIBBZ2_RS_SYS_PREFIX to prefix all exported symbols
testing-prefix = [] # prefix all symbols with LIBBZ2_RS_SYS_TEST_ for testing
semver-prefix = [] # prefix all symbols in a semver-compatible way
stdio = ["dep:libc"] # corresponds to BZ_NO_STDIO; only the low-level api is available when this flag is disabled
__internal-fuzz-disable-checksum = []

Expand Down
25 changes: 24 additions & 1 deletion libbz2-rs-sys/src/bzlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,27 @@ macro_rules! prefix {
};
}

// NOTE: once we reach 1.0.0, the macro used for the `semver-prefix` feature should no longer include the
// minor version in the name. The name is meant to be unique between semver-compatible versions!
const _PRE_ONE_DOT_O: () = assert!(env!("CARGO_PKG_VERSION").as_bytes()[0] == b'0');

#[cfg(feature = "semver-prefix")]
macro_rules! prefix {
($name:expr) => {
concat!(
"LIBBZ2_RS_SYS_v",
env!("CARGO_PKG_VERSION_MAJOR"),
".",
env!("CARGO_PKG_VERSION_MINOR"),
".x_",
stringify!($name)
)
};
}

#[cfg(all(
not(feature = "custom-prefix"),
not(feature = "semver-prefix"),
not(any(test, feature = "testing-prefix"))
))]
macro_rules! prefix {
Expand All @@ -55,7 +74,11 @@ macro_rules! prefix {
};
}

#[cfg(all(not(feature = "custom-prefix"), any(test, feature = "testing-prefix")))]
#[cfg(all(
not(feature = "custom-prefix"),
not(feature = "semver-prefix"),
any(test, feature = "testing-prefix")
))]
macro_rules! prefix {
($name:expr) => {
concat!("LIBBZ2_RS_SYS_TEST_", stringify!($name))
Expand Down

0 comments on commit 315aa16

Please sign in to comment.