Skip to content

Commit

Permalink
Merge pull request #1 from JuliaHEP/new-wrapit
Browse files Browse the repository at this point in the history
Prepare to use WrapIt.jl
  • Loading branch information
peremato authored Nov 21, 2024
2 parents 9893642 + 0a5afe2 commit 197a149
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 39 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
Expand All @@ -45,16 +36,16 @@ jobs:
prefix: xvfb-run
- uses: julia-actions/julia-processcoverage@v1
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: JuliaHEP/PYTHIA8.jl
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- run: |
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PYTHIA8"
uuid = "ab9774ad-7527-4370-92ef-86b02700ecc9"
authors = ["Pere Mato <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
Expand Down
9 changes: 9 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ Example of how PYTHIA can be used as a shared library from Julia. The physics ca

## Tests
Unit tests can be run with `julia --project=. test/runtests.jl`. It runs in addition all the implemented examples to ensure their correct execution and detection of any regression.

## Re-generating wrapper code
It is possible to re-generate the wrapper library locally instead of using the registered `Pythia8_cxxwrap_jll` package. This can be useful for adding new classes or functions to the wrapper library. These are the instructions:
- The configuration file `gen/Pythia8.wit.in` is the input to the automated process. New header files can be added to the input list.
- The script `gen/build.jl` does the work of generating the code and building the library. The command to execute are:
```
julia --project=gen -e 'import Pkg; Pkg.instantiate()'
julia --project=gen gen/build.jl
```
7 changes: 7 additions & 0 deletions docs/src/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

# Release Notes

## 0.2.1 (18-11-2024)
### New functionality
- Adapted `gen/build.jl` to use the WrapIt.jl package instead of a locally installed `wrapit`
### Fixes
- Removed Hist::operator+(double) to avoid [#457](https://github.com/JuliaInterop/CxxWrap.jl/issues/458)
- Do not export `cd` to avoid warnings

## 0.2.0 (07-11-2024)
### New functionality
- Added 2 more new examples: main294.jl and main296.jl
Expand Down
15 changes: 1 addition & 14 deletions gen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ get_filename_component(JlCxx_location ${JlCxx_location} DIRECTORY)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${JlCxx_location}")
message(STATUS "Found JlCxx at ${JlCxx_location}")
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

#---Find Pythia8---------------------------------------------------------------------
find_path(Pythia8_INCLUDE_DIR
NAMES Pythia8/Pythia.h
Expand All @@ -22,20 +23,6 @@ find_library(Pythia8_LIBRARY

# Files are in gen folder----------------------------------------------------------
file(REAL_PATH ${CMAKE_SOURCE_DIR}/../gen SOURCE_DIR)

#---Generate wrapper if WrapIt is found---------------------------------------------
find_program(WRAPIT_EXECUTABLE wrapit)
if(WRAPIT_EXECUTABLE)
configure_file(${SOURCE_DIR}/Pythia8.wit.in ${SOURCE_DIR}/Pythia8.wit @ONLY)
add_custom_command(OUTPUT ${SOURCE_DIR}/cpp/jlPythia8.cxx
COMMAND mkdir -p ${SOURCE_DIR}/jl
COMMAND ${WRAPIT_EXECUTABLE} --force -v 1 ${SOURCE_DIR}/Pythia8.wit
WORKING_DIRECTORY ${SOURCE_DIR}
DEPENDS ${SOURCE_DIR}/Pythia8.wit ${SOURCE_DIR}/Pythia8-veto.h ${SOURCE_DIR}/cpp/Pythia8Wrap.h)
else()
message(STATUS "The executable wrapit was not found. Building wrapper using the generated jlPythia8.cxx/h files from the sources.")
endif()

file(GLOB GEN_SOURCES CONFIGURE_DEPENDS ${SOURCE_DIR}/cpp/Jl*.cxx)
add_library(Pythia8Wrap SHARED ${SOURCE_DIR}/cpp/jlPythia8.cxx ${SOURCE_DIR}/cpp/Pythia8Wrap.cxx ${GEN_SOURCES})
target_include_directories(Pythia8Wrap PRIVATE ${SOURCE_DIR} ${Pythia8_INCLUDE_DIR})
Expand Down
4 changes: 4 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
PYTHIA_jll = "47b8ac8e-e87e-59c1-8ebd-407ebead3f7c"
WrapIt = "962878d8-9763-11ee-8c14-fbf60c98afae"
2 changes: 1 addition & 1 deletion gen/Pythia8-veto.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Pythia8::MergingHooks::resonances
Pythia8::PythiaParallel::pythiaHelper!
Pythia8::SingleSlowJet::idx
bool Pythia8::SlowJetHook::include(int, const Pythia8::Event &, Pythia8::Vec4 &, double &)

Pythia8::Hist Pythia8::Hist::operator+(double)
10 changes: 6 additions & 4 deletions gen/Pythia8.wit.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ clang_opts = ["-v"]

include_dirs = [ "./cpp",
"@Pythia8_INCLUDE_DIR@",
"@Julia_INCLUDE_DIRS@",
"@JlCxx_DIR@/../../../include"]
"@Julia_INCLUDE_DIR@",
"@JlCxx_INCLUDE_DIR@"]

input = [ "Pythia8Wrap.h",
"Pythia8/PythiaStdlib.h",
"Pythia8/Pythia.h",
"Pythia8/Event.h",
"Pythia8/PartonDistributions.h",
Expand Down Expand Up @@ -75,14 +76,15 @@ input = [ "Pythia8Wrap.h",
# "Pythia8/Weights.h",
# "Pythia8/VinciaCommon.h",

extra_headers = ["Pythia8/HIInfo.h",
extra_headers = ["Pythia8Extra.h",
"Pythia8/HIInfo.h",
"Pythia8/HeavyIons.h",
"Pythia8/SplittingsOnia.h"]
vetoed_finalizer_classes = [ ]
export = "all"
veto_list = "Pythia8-veto.h"
cxx-std = "c++17"
inheritances = [ ]
export_blacklist = [ ]
export_blacklist = ["cd"]
cxxwrap_version = "@CxxWrap_VERSION@"

31 changes: 28 additions & 3 deletions gen/build.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
using CxxWrap
using PYTHIA_jll
#using WrapIt

#---Build the wrapper library----------------------------------------------------------------------
builddir = joinpath(@__DIR__, "build")
sourcedir = @__DIR__
cd(@__DIR__)
mkpath(builddir)
cd(builddir)

if Sys.isapple()
ENV["SDKROOT"]=readchomp(`xcrun --sdk macosx --show-sdk-path`)
end

cxxwrap_prefix = CxxWrap.prefix_path()
pythia8_prefix = PYTHIA_jll.artifact_dir
julia_prefix = dirname(Sys.BINDIR)

#---Generate the wrapper code----------------------------------------------------------------------
updatemode = ("--update" ARGS)
updatemode && println("Update mode")
wit = joinpath(@__DIR__, "Pythia8.wit")
witin = joinpath(@__DIR__, "Pythia8.wit.in")
open(wit, "w") do f
for l in eachline(witin)
println(f, replace(l, "@Pythia8_INCLUDE_DIR@" => "$pythia8_prefix/include",
"@Julia_INCLUDE_DIR@" => "$julia_prefix/include/julia",
"@JlCxx_INCLUDE_DIR@" => "$cxxwrap_prefix/include",
"@CxxWrap_VERSION@" => "$(pkgversion(CxxWrap))"))
end
end

#rc = wrapit(wit, force=true, cmake=false, update=updatemode, verbosity=1)
rc = run(`wrapit $wit --force -v 1`).exitcode


if !isnothing(rc) && rc != 0
println(stderr, "Failed to produce wrapper code with the wrapit function. Exited with code ", rc, ".")
exit(rc)
end

#---Build the wrapper library----------------------------------------------------------------------
cd(builddir)
run(`cmake -DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_STANDARD=17
-DCMAKE_PREFIX_PATH=$cxxwrap_prefix\;$pythia8_prefix $sourcedir
-DCxxWrap_VERSION=$(pkgversion(CxxWrap))`)
-DCMAKE_PREFIX_PATH=$cxxwrap_prefix\;$pythia8_prefix $sourcedir`)
run(`cmake --build . --config Release --parallel 8`)
4 changes: 4 additions & 0 deletions gen/cpp/Pythia8Extra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// BinaryBuilder uses old SDK which doesn't have ranges
#ifdef __APPLE__
#undef JLCXX_HAS_RANGES
#endif
8 changes: 8 additions & 0 deletions gen/cpp/Pythia8Wrap.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#ifndef Pythia8Wrap_H
#define Pythia8Wrap_H

#include <vector>
#include <string>
using std::string; // to avoid confusion in WrapIt generated code!!

#include "Pythia8/Basics.h"
#include "Pythia8/UserHooks.h"
namespace Pythia8 {
Expand Down Expand Up @@ -212,3 +219,4 @@ class Pythia8UserHooks : public Pythia8::UserHooks {
bool (*onEndHadronLevel_f)(void*, Pythia8::HadronLevel&, Pythia8::Event&) = nullptr;
void *onEndHadronLevel_d = nullptr;
};
#endif
2 changes: 1 addition & 1 deletion src/PYTHIA8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module PYTHIA8
# Check whether the wrappers have been build locally otherwise use the binary package Pythia8_cxxwrap_jll
gendir = normpath(joinpath(@__DIR__, "../gen"))
if isdir(joinpath(gendir, "build/lib"))
include(joinpath(gendir, "jl/Pythia8-export.jl"))
include(joinpath(gendir, "jl/src/Pythia8-export.jl"))
@wrapmodule(()->joinpath(gendir, "build/lib", "libPythia8Wrap.$(Libdl.dlext)"))
else
using Pythia8_cxxwrap_jll
Expand Down

2 comments on commit 197a149

@peremato
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

New functionality

  • Adapted gen/build.jl to use the WrapIt.jl package instead of a locally installed wrapit

Fixes

  • Removed Hist::operator+(double) to avoid #457
  • Do not export cd to avoid warnings

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119886

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 197a14973c13523bd82df6093cde98c2e3666424
git push origin v0.2.1

Please sign in to comment.