Skip to content

Commit

Permalink
Make libbz2-rs-sys-cdylib unconditionally no_std
Browse files Browse the repository at this point in the history
This reduces the size of libbz2_rs.so by 408KB in release mode.
  • Loading branch information
bjorn3 committed Dec 3, 2024
1 parent 3bf510f commit 028fc70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libbzip2-rs-sys-cdylib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ name = "bz2_rs" # turns into e.g. `libbz2_rs.so`
crate-type=["cdylib"]

[features]
default = ["c-allocator", "libbzip2-rs-sys/stdio", "libbzip2-rs-sys/std"] # when used as a cdylib crate, use the c allocator
default = ["c-allocator", "libbzip2-rs-sys/stdio"] # when used as a cdylib crate, use the c allocator
c-allocator = ["libbzip2-rs-sys/c-allocator"] # by default, use malloc/free for memory allocation
rust-allocator = ["libbzip2-rs-sys/rust-allocator", "libbzip2-rs-sys/std"] # by default, use the rust global alloctor for memory allocation
custom-prefix = ["libbzip2-rs-sys/custom-prefix"] # use the LIBBZIP2_RS_SYS_PREFIX to prefix all exported symbols
capi = []

Expand All @@ -34,3 +33,10 @@ enabled = false
[package.metadata.capi.pkg_config]
name = "libbz2_rs"
filename = "libbz2_rs"

# no_std requires panic=abort
[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
14 changes: 14 additions & 0 deletions libbzip2-rs-sys-cdylib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#![no_std]

extern crate libbzip2_rs_sys;

use core::ffi::c_int;
use core::panic::PanicInfo;
pub use libbzip2_rs_sys::*;

#[panic_handler]
fn panic_handler(_info: &PanicInfo) -> ! {
extern "C" {
fn bz_internal_error(errcode: c_int);
}

unsafe { bz_internal_error(-1) }
loop {}
}

0 comments on commit 028fc70

Please sign in to comment.