Skip to content

Commit

Permalink
Merge some fixes from fix-macos-cli-generation branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Apr 23, 2024
1 parent 8f5f52b commit b323985
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 34 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

95 changes: 69 additions & 26 deletions pineappl_applgrid/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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")
Expand Down Expand Up @@ -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");

Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions pineappl_applgrid/src/applgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct appl_igrid_m_reweight
friend type access(appl_igrid_m_reweight);
};

template class access_private_member_variable<appl_igrid_m_reweight, &appl::igrid::m_reweight>;
template struct access_private_member_variable<appl_igrid_m_reweight, &appl::igrid::m_reweight>;

// we need access to `m_reweight`, but it is private
bool igrid_m_reweight(appl::igrid const& igrid)
Expand All @@ -254,7 +254,7 @@ struct appl_grid_m_grids
friend type access(appl_grid_m_grids);
};

template class access_private_member_variable<appl_grid_m_grids, &appl::grid::m_grids>;
template struct access_private_member_variable<appl_grid_m_grids, &appl::grid::m_grids>;

appl::igrid& grid_get_igrid(appl::grid& grid, std::size_t order, std::size_t bin)
{
Expand Down
1 change: 1 addition & 0 deletions pineappl_fastnlo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ thiserror = "1.0.30"

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

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

use std::process::Command;
use pkg_config::Config;

fn main() {
let fnlo_lib_path = String::from_utf8(
Expand All @@ -24,16 +25,31 @@ 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 {
""
};

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");
Expand Down
11 changes: 5 additions & 6 deletions xtask/src/install_manpages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit b323985

Please sign in to comment.