diff --git a/Cargo.lock b/Cargo.lock index e0c0f6f4e..2a38a6d0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1328,6 +1328,7 @@ version = "0.7.4-rc.1" dependencies = [ "cxx", "cxx-build", + "pkg-config", "thiserror", ] diff --git a/pineappl_applgrid/build.rs b/pineappl_applgrid/build.rs index c30b2f9a5..9eb5facd3 100644 --- a/pineappl_applgrid/build.rs +++ b/pineappl_applgrid/build.rs @@ -6,6 +6,14 @@ use std::env; use std::path::Path; use std::process::Command; +fn conditional_std<'a>(build: &'a mut Build, std: Option<&str>) -> &'a mut Build { + if let Some(std) = std { + build.std(std) + } else { + build + } +} + fn main() { let version = String::from_utf8( Command::new("applgrid-config") @@ -16,7 +24,14 @@ fn main() { ) .unwrap(); - if version.trim() != "1.6.27" { + let tested_versions = [ + "1.6.27", "1.6.28", "1.6.29", "1.6.30", "1.6.31", "1.6.32", "1.6.35", + ]; + + if !tested_versions + .iter() + .any(|&tested| tested == version.trim()) + { println!( "cargo:warning=found APPLgrid version {}, which has not been tested", version.trim() @@ -34,22 +49,44 @@ fn main() { println!("cargo:rustc-link-search={}", lib_path.trim()); - let include_path = String::from_utf8( + let appl_igrid_dir = env::var("APPL_IGRID_DIR").unwrap_or_else(|_| { + Path::new( + &String::from_utf8( + Command::new("applgrid-config") + .arg("--incdir") + .output() + .expect("did not find `applgrid-config`, please install APPLgrid") + .stdout, + ) + .unwrap(), + ) + .join("appl_grid") + .to_str() + .unwrap() + .to_owned() + }); + + let cxx_flags: Vec<_> = String::from_utf8( Command::new("applgrid-config") - .arg("--incdir") + .arg("--cxxflags") .output() .expect("did not find `applgrid-config`, please install APPLgrid") .stdout, ) - .unwrap(); + .unwrap() + .split_ascii_whitespace() + .map(ToOwned::to_owned) + .collect(); - let appl_igrid_dir = env::var("APPL_IGRID_DIR").unwrap_or_else(|_| { - Path::new(&include_path) - .join("appl_grid") - .to_str() - .unwrap() - .to_owned() - }); + let include_dirs: Vec<_> = cxx_flags + .iter() + .filter_map(|token| token.strip_prefix("-I")) + .collect(); + + let std = cxx_flags + .iter() + .filter_map(|token| token.strip_prefix("-std=")) + .last(); let libs = String::from_utf8( Command::new("applgrid-config") @@ -82,16 +119,19 @@ fn main() { } } - Build::new() - .cpp(true) - .file("src/check_appl_igrid.cpp") - .include(include_path.trim()) - .include(&appl_igrid_dir) - .try_compile("appl_igrid") - .expect( - "could not find file `appl_igrid.h`, please set the environment variable \ + conditional_std( + Build::new() + .cpp(true) + .file("src/check_appl_igrid.cpp") + .includes(&include_dirs) + .include(&appl_igrid_dir), + std, + ) + .try_compile("appl_igrid") + .expect( + "could not find file `appl_igrid.h`, please set the environment variable \ `APPL_IGRID_DIR` to the directory containing it", - ); + ); println!("cargo:rerun-if-env-changed=APPL_IGRID_DIR"); @@ -105,12 +145,15 @@ fn main() { println!("cargo:rustc-link-lib={link_modifier}{lib}"); } - cxx_build::bridge("src/lib.rs") - .file("src/applgrid.cpp") - .include(include_path.trim()) - .include(appl_igrid_dir) - .includes(lhapdf.include_paths) - .compile("appl-bridge"); + conditional_std( + cxx_build::bridge("src/lib.rs") + .file("src/applgrid.cpp") + .includes(&include_dirs) + .include(appl_igrid_dir) + .includes(lhapdf.include_paths), + std, + ) + .compile("appl-bridge"); println!("cargo:rerun-if-changed=src/lib.rs"); println!("cargo:rerun-if-changed=src/applgrid.cpp"); diff --git a/pineappl_applgrid/src/applgrid.cpp b/pineappl_applgrid/src/applgrid.cpp index 1d31949c8..592a16d85 100644 --- a/pineappl_applgrid/src/applgrid.cpp +++ b/pineappl_applgrid/src/applgrid.cpp @@ -233,7 +233,7 @@ struct appl_igrid_m_reweight friend type access(appl_igrid_m_reweight); }; -template class access_private_member_variable; +template struct access_private_member_variable; // we need access to `m_reweight`, but it is private bool igrid_m_reweight(appl::igrid const& igrid) @@ -254,7 +254,7 @@ struct appl_grid_m_grids friend type access(appl_grid_m_grids); }; -template class access_private_member_variable; +template struct access_private_member_variable; appl::igrid& grid_get_igrid(appl::grid& grid, std::size_t order, std::size_t bin) { diff --git a/pineappl_fastnlo/Cargo.toml b/pineappl_fastnlo/Cargo.toml index 6d3e2a2a4..de1694c44 100644 --- a/pineappl_fastnlo/Cargo.toml +++ b/pineappl_fastnlo/Cargo.toml @@ -21,6 +21,7 @@ thiserror = "1.0.30" [build-dependencies] cxx-build = { version = "1.0.65" } +pkg-config = "0.3" [features] static = [] diff --git a/pineappl_fastnlo/build.rs b/pineappl_fastnlo/build.rs index c384b86ee..040b9c8a0 100644 --- a/pineappl_fastnlo/build.rs +++ b/pineappl_fastnlo/build.rs @@ -1,6 +1,7 @@ #![allow(missing_docs)] use std::process::Command; +use pkg_config::Config; fn main() { let fnlo_lib_path = String::from_utf8( @@ -24,6 +25,17 @@ fn main() { .unwrap(); let link_modifier = if cfg!(feature = "static") { + let zlib = Config::new().probe("zlib").unwrap(); + + // for some reason `libz.a` isn't found, although `libz.so` is + for link_path in zlib.link_paths { + println!("cargo:rustc-link-search={}", link_path.to_str().unwrap()); + } + + for lib in zlib.libs { + println!("cargo:rustc-link-lib=static={lib}"); + } + "static=" } else { "" @@ -31,9 +43,13 @@ fn main() { println!("cargo:rustc-link-lib={link_modifier}fastnlotoolkit"); + let lhapdf = Config::new().atleast_version("6").probe("lhapdf").unwrap(); + cxx_build::bridge("src/lib.rs") .file("src/fastnlo.cpp") .include(fnlo_include_path.trim()) + .includes(lhapdf.include_paths) + .std("c++11") // apparently not supported by MSVC, but fastNLO probably can't be compiled on Windows .compile("fnlo-bridge"); println!("cargo:rerun-if-changed=src/lib.rs"); diff --git a/xtask/src/install_manpages.rs b/xtask/src/install_manpages.rs index e75223faf..62c9aea1f 100644 --- a/xtask/src/install_manpages.rs +++ b/xtask/src/install_manpages.rs @@ -41,14 +41,13 @@ fn render_manpages(path: &Path, cmd: &clap::Command, version: &str) -> Result<() impl Subcommand for Opts { fn run(&self) -> Result<()> { let cmd = pineappl_cli::Opts::command(); - let version: String = cmd + let version = cmd .get_version() // UNWRAP: the command must have a version - .unwrap() - .strip_prefix('v') - // UNWRAP: the version string must start with a 'v' - .unwrap() - .to_string(); + .unwrap(); + + // TODO: why does the version string not start with a 'v' on GitHub? + let version = version.strip_prefix('v').unwrap_or(version).to_string(); let mut cmd = cmd.version(version.clone()); // this is needed so subcommands return the correct `bin_name`