From 156976db02cce4f4fee0ae42fb0de8ff5092bd6f Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Mon, 18 Nov 2024 11:43:18 +0100 Subject: [PATCH 1/4] Use WrapIt.jl instead of a local installation --- gen/CMakeLists.txt | 15 +-------------- gen/Project.toml | 4 ++++ gen/Pythia8-veto.h | 2 +- gen/Pythia8.wit.in | 6 +++--- gen/build.jl | 28 +++++++++++++++++++++++++--- gen/cpp/Pythia8Wrap.h | 4 ++++ src/PYTHIA8.jl | 2 +- 7 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 gen/Project.toml diff --git a/gen/CMakeLists.txt b/gen/CMakeLists.txt index 05ad7da..bfbbf71 100644 --- a/gen/CMakeLists.txt +++ b/gen/CMakeLists.txt @@ -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 @@ -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}) diff --git a/gen/Project.toml b/gen/Project.toml new file mode 100644 index 0000000..e7bbbc5 --- /dev/null +++ b/gen/Project.toml @@ -0,0 +1,4 @@ +[deps] +CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4" +PYTHIA_jll = "47b8ac8e-e87e-59c1-8ebd-407ebead3f7c" +WrapIt = "962878d8-9763-11ee-8c14-fbf60c98afae" diff --git a/gen/Pythia8-veto.h b/gen/Pythia8-veto.h index 30e159b..e93db00 100644 --- a/gen/Pythia8-veto.h +++ b/gen/Pythia8-veto.h @@ -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) diff --git a/gen/Pythia8.wit.in b/gen/Pythia8.wit.in index 6063c96..1878c18 100644 --- a/gen/Pythia8.wit.in +++ b/gen/Pythia8.wit.in @@ -10,8 +10,8 @@ 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/Pythia.h", @@ -83,6 +83,6 @@ export = "all" veto_list = "Pythia8-veto.h" cxx-std = "c++17" inheritances = [ ] -export_blacklist = [ ] +export_blacklist = ["cd"] cxxwrap_version = "@CxxWrap_VERSION@" diff --git a/gen/build.jl b/gen/build.jl index 1b543b7..a6c4c83 100644 --- a/gen/build.jl +++ b/gen/build.jl @@ -1,12 +1,12 @@ 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`) @@ -14,9 +14,31 @@ 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=5) +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`) diff --git a/gen/cpp/Pythia8Wrap.h b/gen/cpp/Pythia8Wrap.h index 0b78caa..39e6914 100644 --- a/gen/cpp/Pythia8Wrap.h +++ b/gen/cpp/Pythia8Wrap.h @@ -1,3 +1,7 @@ +#include +#include +using std::string; // to avoid confusion in WrapIt generated code!! + #include "Pythia8/Basics.h" #include "Pythia8/UserHooks.h" namespace Pythia8 { diff --git a/src/PYTHIA8.jl b/src/PYTHIA8.jl index 862c35d..ef779c6 100644 --- a/src/PYTHIA8.jl +++ b/src/PYTHIA8.jl @@ -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 From c02968f4e4e4a4ac863a2dd9dfe3c82cc0631e93 Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Mon, 18 Nov 2024 16:14:31 +0100 Subject: [PATCH 2/4] Preparing release 0.2.1 --- Project.toml | 2 +- docs/src/index.md | 9 +++++++++ docs/src/release_notes.md | 7 +++++++ gen/Pythia8.wit.in | 1 + gen/build.jl | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 27ddab5..cf18119 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PYTHIA8" uuid = "ab9774ad-7527-4370-92ef-86b02700ecc9" authors = ["Pere Mato "] -version = "0.2.0" +version = "0.2.1" [deps] CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4" diff --git a/docs/src/index.md b/docs/src/index.md index 8e8a98f..ef86530 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -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 + ``` diff --git a/docs/src/release_notes.md b/docs/src/release_notes.md index 0b7565e..9163b7b 100644 --- a/docs/src/release_notes.md +++ b/docs/src/release_notes.md @@ -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 diff --git a/gen/Pythia8.wit.in b/gen/Pythia8.wit.in index 1878c18..c051cee 100644 --- a/gen/Pythia8.wit.in +++ b/gen/Pythia8.wit.in @@ -14,6 +14,7 @@ include_dirs = [ "./cpp", "@JlCxx_INCLUDE_DIR@"] input = [ "Pythia8Wrap.h", + "Pythia8/PythiaStdlib.h", "Pythia8/Pythia.h", "Pythia8/Event.h", "Pythia8/PartonDistributions.h", diff --git a/gen/build.jl b/gen/build.jl index a6c4c83..5c7fb3b 100644 --- a/gen/build.jl +++ b/gen/build.jl @@ -30,7 +30,7 @@ open(wit, "w") do f end end -rc = wrapit(wit, force=true, cmake=false, update=updatemode, verbosity=5) +rc = wrapit(wit, force=true, cmake=false, update=updatemode, verbosity=0) if !isnothing(rc) && rc != 0 println(stderr, "Failed to produce wrapper code with the wrapit function. Exited with code ", rc, ".") exit(rc) From 0798c967a70f392ec804a29407b4f500da494260 Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Thu, 21 Nov 2024 10:45:35 +0100 Subject: [PATCH 3/4] revert to locally installed wrapit --- gen/Pythia8.wit.in | 3 ++- gen/build.jl | 7 +++++-- gen/cpp/Pythia8Extra.h | 4 ++++ gen/cpp/Pythia8Wrap.h | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 gen/cpp/Pythia8Extra.h diff --git a/gen/Pythia8.wit.in b/gen/Pythia8.wit.in index c051cee..93ac2cc 100644 --- a/gen/Pythia8.wit.in +++ b/gen/Pythia8.wit.in @@ -76,7 +76,8 @@ 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 = [ ] diff --git a/gen/build.jl b/gen/build.jl index 5c7fb3b..77bd678 100644 --- a/gen/build.jl +++ b/gen/build.jl @@ -1,6 +1,6 @@ using CxxWrap using PYTHIA_jll -using WrapIt +#using WrapIt #---Build the wrapper library---------------------------------------------------------------------- builddir = joinpath(@__DIR__, "build") @@ -30,7 +30,10 @@ open(wit, "w") do f end end -rc = wrapit(wit, force=true, cmake=false, update=updatemode, verbosity=0) +#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) diff --git a/gen/cpp/Pythia8Extra.h b/gen/cpp/Pythia8Extra.h new file mode 100644 index 0000000..7175464 --- /dev/null +++ b/gen/cpp/Pythia8Extra.h @@ -0,0 +1,4 @@ +// BinaryBuilder uses old SDK which doesn't have ranges +#ifdef __APPLE__ + #undef JLCXX_HAS_RANGES +#endif diff --git a/gen/cpp/Pythia8Wrap.h b/gen/cpp/Pythia8Wrap.h index 39e6914..f9e5d31 100644 --- a/gen/cpp/Pythia8Wrap.h +++ b/gen/cpp/Pythia8Wrap.h @@ -1,3 +1,6 @@ +#ifndef Pythia8Wrap_H +#define Pythia8Wrap_H + #include #include using std::string; // to avoid confusion in WrapIt generated code!! @@ -216,3 +219,4 @@ class Pythia8UserHooks : public Pythia8::UserHooks { bool (*onEndHadronLevel_f)(void*, Pythia8::HadronLevel&, Pythia8::Event&) = nullptr; void *onEndHadronLevel_d = nullptr; }; +#endif \ No newline at end of file From 0a5afe20eca5d13e58e88b779398fcd95b837309 Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Thu, 21 Nov 2024 11:06:14 +0100 Subject: [PATCH 4/4] Update CI --- .github/workflows/ci.yml | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7dc762..4e1dac4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -45,7 +36,7 @@ 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 @@ -53,8 +44,8 @@ jobs: 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: |