Skip to content

Commit

Permalink
Fix building the CLI on macOS (#269)
Browse files Browse the repository at this point in the history
* Install LHAPDF on macOS

* Disable Python

* Correctly disable Python

* Fix `--disable-dynamic` with `--disable-shared`

* Do not run workflows in this branch

* Use brew to install LHAPDF on macOS

* Run Release workflow automatically in this branch

* Create missing directory

* Fix problems with workflow syntax

* Simplify matrix strategy a bit

* Try to fix packaging the CLI

* Add comment why we can't cross compile

* Simplify CLI installation on Linux

* Add missing `--locked` switch to installation

* Install and use APPLgrid on macOS

* Download sources and export `APPL_IGRID_DIR` on macOS

* Add some diagnostics for homebrew

* Keep temporary directory when compiling with brew

* Fix `APPL_IGRID_DIR` determination

* Print more diagnostics

* Add missing include paths for `pineappl_applgrid`

* Add more tested versions of APPLgrid

* Set C++ standard in `pineappl_applgrid`

* Reduce APPLgrid dependencies and install zlib

* Fix C++ warning

* Force installation of zlib and list contents

* Print zlib search path

* Install `pkg-config` to find zlib from brew

* Fix `pkg-config` call

* Add more diagnostic to pkg-config call

* Print more diagnostic strings

* List contents of the ROOT installation

* Compile APPLgrid without ROOT

* Add missing `--without-root`

* Manually install zlib

* Print `applgrid-config` script to diagnose building failure

* Force-remove linking to `gfortran`

* Rename existing `tmp` with `new`

* Remove diagnostics and simplify `sed` call

* Revert last commit except the removal of diagnostics

* Compile CLI on macOS against fastNLO

* Update `cc` create to fix yet another problem on macOS

* Update `cxx` and related crates to hopefull fix missing compiler flag

* Explicitly set C++11 standard

* Add LHAPDF include paths to fastNLO

* Install manpages on both Linux and macOS

* Debug version string when installing manpages

* Try to fix version string patching on GitHub

* Add zlib when linking statically

* Revert "refactor: Use Rust version of convolute_with_one"

This reverts commit 0d9876f.

* Remove `signature` macro that breaks Python 3.6 support

This commit and the previous should be reverted when we drop Python 3.6
support

* Try to fix problems on macOS
  • Loading branch information
cschwan authored Apr 26, 2024
1 parent 618b097 commit 957c4b9
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/capi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: CAPI

on:
push:
branches-ignore:
- fix-macos-cli-generation

jobs:
capi:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: MSRV

on:
push:
branches-ignore:
- fix-macos-cli-generation

env:
CARGO_TERM_COLOR: always
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Python

on:
push:
branches-ignore:
- fix-macos-cli-generation

jobs:
test:
Expand Down
51 changes: 39 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
tags:
- 'v[0-9]+*'
branches:
- fix-macos-cli-generation
workflow_dispatch:

env:
Expand Down Expand Up @@ -31,9 +33,9 @@ jobs:
- name: Compile library
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --target=${{ matrix.target }}
cargo install cargo-c
cargo install --locked cargo-c
cd pineappl_capi
cargo cinstall --verbose --destdir=prefix --library-type=cdylib --prefix=/ --target=${{ matrix.target }}
cargo cinstall --destdir=prefix --library-type=cdylib --locked --prefix=/ --target=${{ matrix.target }} --verbose
cd prefix
tar czf ../../pineappl_capi-${{ matrix.target }}.tar.gz .
- name: Upload artifact
Expand All @@ -46,20 +48,44 @@ jobs:
cli-macos:
strategy:
matrix:
os: [macos-latest, macos-14]
include:
- os: macos-latest
- os: macos-13
target: x86_64-apple-darwin
- os: macos-14
# we cannot cross-compile, because we need also all dependencies for the specified target
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Compile binary
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --target=${{ matrix.target }}
cargo build --release --features=evolve,fktable,static --bin pineappl --target=${{ matrix.target }}
cp target/release/pineappl prefix/bin/
brew tap davidchall/hep
# install LHAPDF
brew install lhapdf
# install APPLgrid's dependencies; disable ROOT because its static libraries are missing
brew install --only-dependencies --without-hoppet --without-lhapdf --without-root applgrid
# install zlib, which is a dependency of APPLgrid but somehow missing
brew install zlib
# APPLgrid wants to be linked against zlib, and we need to find its static library via pkg-config
export PKG_CONFIG_PATH=$(find $(brew --cellar) -name '*.pc' -exec dirname {} + | sort -u | tr '\n' ':')
# manually compile APPLgrid, because we need the file `appl_igrid.h` and the files it includes, which are possibly generated
export HOMEBREW_TEMP="$(pwd)"/tmp
mkdir -p ${HOMEBREW_TEMP}
brew install --build-from-source --keep-tmp --without-hoppet --without-lhapdf --without-root applgrid
export APPL_IGRID_DIR=$(find ${HOMEBREW_TEMP} -name appl_igrid.h -exec dirname {} +)
# do not link against `gfortran`
sed 's/-lgfortran//g' $(command -v applgrid-config) > applgrid-config.new
mv applgrid-config.new $(command -v applgrid-config)
chmod +x $(command -v applgrid-config)
# install fastNLO
brew install --without-fastjet fastnlo
# install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-host=${{ matrix.target }}
# build the CLI
cargo install --all-features --locked --path pineappl_cli --root=prefix --target=${{ matrix.target }}
# build manpages
mkdir -p prefix/share/man/man1
cargo xtask install-manpages prefix/share/man/man1
cd prefix
tar czf ../pineappl_cli-${{ matrix.target }}.tar.gz .
- name: Upload artifact
Expand All @@ -81,7 +107,7 @@ jobs:
- name: Compile library
run: |
cd pineappl_capi
cargo cinstall --verbose --destdir=prefix --library-type=cdylib --prefix=/ --target=${{ matrix.target }}
cargo cinstall --destdir=prefix --library-type=cdylib --locked --prefix=/ --target=${{ matrix.target }} --verbose
cd prefix
tar czf ../../pineappl_capi-${{ matrix.target }}.tar.gz .
# print the glibc version requirement
Expand All @@ -104,9 +130,10 @@ jobs:
- uses: actions/checkout@v3
- name: Compile binary
run: |
cargo build --release --all-features --bin pineappl
mkdir -p prefix/bin
cp target/release/pineappl prefix/bin/
cargo install --all-features --locked --path pineappl_cli --root=prefix --target=${{ matrix.target }}
# build manpages
mkdir -p prefix/share/man/man1
cargo xtask install-manpages prefix/share/man/man1
cd prefix
tar czf ../pineappl_cli-${{ matrix.target }}.tar.gz .
- name: Upload artifact
Expand Down Expand Up @@ -235,7 +262,7 @@ jobs:
path: dist

wheels-macos:
runs-on: macos-latest
runs-on: macos-13
strategy:
matrix:
target: [aarch64, x86_64]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Rust

on:
push:
branches-ignore:
- fix-macos-cli-generation

defaults:
run:
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

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

38 changes: 38 additions & 0 deletions pineappl_py/pineappl/fk_table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from .pineappl import PyFkTable, PyFkAssumptions
from .utils import PyWrapper

Expand Down Expand Up @@ -50,6 +52,42 @@ def optimize(self, assumptions = "Nf6Ind"):
assumptions = FkAssumptions(assumptions)
return self._raw.optimize(assumptions._raw)

def convolute_with_one(
self,
pdg_id,
xfx,
bin_indices=np.array([], dtype=np.uint64),
lumi_mask=np.array([], dtype=bool),
):
r"""Convolute FkTable with a pdf.
Parameters
----------
pdg_id : int
PDG Monte Carlo ID of the hadronic particle `xfx` is the PDF for
xfx : callable
lhapdf like callable with arguments `pid, x, Q2` returning x*pdf for :math:`x`-grid
bin_indices : sequence(int)
A list with the indices of the corresponding bins that should be calculated. An
empty list means that all orders should be calculated.
lumi_mask : sequence(bool)
Mask for selecting specific luminosity channels. The value `True` means the
corresponding channel is included. An empty list corresponds to all channels being
enabled.
Returns
-------
list(float) :
cross sections for all bins, for each scale-variation tuple (first all bins, then
the scale variation)
"""
return self.raw.convolute_with_one(
pdg_id,
xfx,
np.array(bin_indices),
np.array(lumi_mask),
)


class FkAssumptions(PyWrapper):
"""
Expand Down
1 change: 0 additions & 1 deletion pineappl_py/src/fk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ impl PyFkTable {
/// -------
/// numpy.ndarray(float) :
/// cross sections for all bins
#[pyo3(signature = (pdg_id, xfx, bin_indices = None, lumi_mask= None))]
pub fn convolute_with_one<'py>(
&self,
pdg_id: i32,
Expand Down

0 comments on commit 957c4b9

Please sign in to comment.