Skip to content

Commit

Permalink
Add support for static linking
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Mar 27, 2024
1 parent d6c3e26 commit 7dba671
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pineappl_applgrid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ cxx = "1.0.65"
cc = "1.0.49"
cxx-build = "1.0.65"
pkg-config = "0.3.26"

[features]
static = []
25 changes: 19 additions & 6 deletions pineappl_applgrid/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(missing_docs)]

use cc::Build;
use pkg_config::Config;
use std::env;
use std::path::Path;
use std::process::Command;
Expand Down Expand Up @@ -59,11 +60,26 @@ fn main() {
)
.unwrap();

let link_modifier = if cfg!(feature = "static") {
// for some reason `libz.a` isn't found, although `libz.so` is
for link_path in Config::new().probe("zlib").unwrap().link_paths {
println!("cargo:rustc-link-search={}", link_path.to_str().unwrap());
}

"static="
} else {
""
};

for lib in libs
.split_whitespace()
.filter_map(|token| token.strip_prefix("-l"))
{
println!("cargo:rustc-link-lib={lib}");
match lib {
// we can't link gfortran statically - to avoid it compile APPLgrid without HOPPET
"gfortran" => println!("cargo:rustc-link-lib={lib}"),
_ => println!("cargo:rustc-link-lib={link_modifier}{lib}"),
}
}

Build::new()
Expand All @@ -79,17 +95,14 @@ fn main() {

println!("cargo:rerun-if-env-changed=APPL_IGRID_DIR");

let lhapdf = pkg_config::Config::new()
.atleast_version("6")
.probe("lhapdf")
.unwrap();
let lhapdf = Config::new().atleast_version("6").probe("lhapdf").unwrap();

for lib_path in lhapdf.link_paths {
println!("cargo:rustc-link-search={}", lib_path.to_str().unwrap());
}

for lib in lhapdf.libs {
println!("cargo:rustc-link-lib={lib}");
println!("cargo:rustc-link-lib={link_modifier}{lib}");
}

cxx_build::bridge("src/lib.rs")
Expand Down
1 change: 1 addition & 0 deletions pineappl_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ applgrid = ["dep:cxx", "dep:pineappl_applgrid"]
evolve = ["dep:base64", "dep:either", "dep:tar", "dep:lz4_flex", "dep:ndarray-npy", "dep:serde", "dep:serde_yaml"]
fastnlo = ["dep:pineappl_fastnlo"]
fktable = ["dep:flate2", "dep:tar"]
static = ["lhapdf/static", "pineappl_applgrid?/static", "pineappl_fastnlo?/static"]
3 changes: 3 additions & 0 deletions pineappl_fastnlo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ thiserror = "1.0.30"

[build-dependencies]
cxx-build = { version = "1.0.65" }

[features]
static = []
8 changes: 7 additions & 1 deletion pineappl_fastnlo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ fn main() {
)
.unwrap();

println!("cargo:rustc-link-lib=fastnlotoolkit");
let link_modifier = if cfg!(feature = "static") {
"static="
} else {
""
};

println!("cargo:rustc-link-lib={link_modifier}fastnlotoolkit");

cxx_build::bridge("src/lib.rs")
.file("src/fastnlo.cpp")
Expand Down

0 comments on commit 7dba671

Please sign in to comment.