Skip to content

Commit

Permalink
Add feature to link libelf and zlib statically
Browse files Browse the repository at this point in the history
  • Loading branch information
javierhonduco authored and alexforster committed Jul 8, 2022
1 parent bf363c7 commit 371a85d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ crate-type = ["lib", "staticlib"]

[features]
novendor = []
static = []
15 changes: 13 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ fn generate_bindings(src_dir: path::PathBuf) {
#[cfg(not(feature = "bindgen"))]
fn generate_bindings(_: path::PathBuf) {}

#[cfg(feature = "static")]
fn library_prefix() -> String {
"static=".to_string()
}

#[cfg(not(feature = "static"))]
fn library_prefix() -> String {
"".to_string()
}

fn main() {
let src_dir = path::PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let out_dir = path::PathBuf::from(env::var_os("OUT_DIR").unwrap());
Expand Down Expand Up @@ -166,14 +176,15 @@ fn main() {
.unwrap();
io::stdout().write_all("\n".as_bytes()).unwrap();
io::stdout()
.write_all("cargo:rustc-link-lib=elf\n".as_bytes())
.write_all(format!("cargo:rustc-link-lib={}elf\n", library_prefix()).as_bytes())
.unwrap();
io::stdout()
.write_all("cargo:rustc-link-lib=z\n".as_bytes())
.write_all(format!("cargo:rustc-link-lib={}z\n", library_prefix()).as_bytes())
.unwrap();
io::stdout()
.write_all("cargo:rustc-link-lib=static=bpf\n".as_bytes())
.unwrap();

io::stdout().write_all("cargo:include=".as_bytes()).unwrap();
io::stdout()
.write_all(out_dir.as_os_str().as_bytes())
Expand Down

0 comments on commit 371a85d

Please sign in to comment.