Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Fixed MacOS build; use of scractch space; change of uuid; added CI.
Browse files Browse the repository at this point in the history
Use Scratch.jl to follow recommendation to not modify package directory. Only deps.jl is now written there.
UUID was shared with Wrapit ex002 examples. UUID modified
  • Loading branch information
grasph committed Jun 1, 2024
1 parent 5d5fdeb commit a7ea19b
Show file tree
Hide file tree
Showing 19 changed files with 2,500 additions and 1,815 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#This file is kept almost identical to test-macos
#We use two files in order to get two distinct badges for Linux and macOS.
name: Linux
on:
- push
- pull_request

defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.10'
- 'nightly'
os:
- ubuntu-latest
# - macOS-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
36 changes: 36 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#This file is kept almost identical to test-macos
#We use two files in order to get two distinct badges for Linux and macOS.
name: macOS
on:
- push
- pull_request

defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.10'
- 'nightly'
os:
# - ubuntu-latest
- macOS-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest.toml
deps/build.log
deps/deps.jl
test/demo_ROOT.png
test/demo_ROOT_out.root
test/demo_TGraph.png
test/demo_fit_with_jl_func.png
test/demo_fit_with_jl_func_2.png
test/test1.root
test/test2.root
test/test3.root
17 changes: 10 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
name = "ROOT2"
uuid = "b0506e13-49c2-4ce6-b48c-bb2bc691fb3e"
uuid = "4e771be0-af1c-4c60-a3da-ec998561eab7"
version = "0.0.1"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"

[extras]
UnROOT = "3cd96dde-e98d-4713-81e9-a4a1b0235ce9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
CxxWrap = "0.14"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnROOT = "3cd96dde-e98d-4713-81e9-a4a1b0235ce9"

[targets]
test = ["Test", "UnROOT"]
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ROOT2

[![Linux](https://github.com/JuliaHEP/ROOT2/actions/workflows/test-linux.yml/badge.svg)](https://github.com/JuliaHEP/ROOT2/actions/workflows/test-linux.yml) [![macOS](https://github.com/JuliaHEP/ROOT2/actions/workflows/test-macos.yml/badge.svg)](https://github.com/JuliaHEP/ROOT2/actions/workflows/test-macos.yml)

## Introduction

ROOT2 is a Julia interface to the C++ [ROOT Data analysis framework](https://root.cern/) used in the high energy physics community.
Expand All @@ -10,14 +12,26 @@ Function documentation for the Julia help command is not yet available. Please r

ROOT2 uses [CxxWrap](https://github.com/JuliaInterop/CxxWrap.jl) to interface to the C++ libraries and the wrappers were generated using [WrapIt!](https://github.com/grasph/wrapit).


## Supported platforms

Linux and MacOS.

## Installation

```
import Pkg
Pkg.add("ROOT2")
```

⚠️ Installation or first import may take a while due to code compilation.
⚠️ Installation can stay several minutes (ten of minutes on macOS) on the following message.

```
Building ROOT2 → `.../build.log`
Progress [= ]1/2
```

This is due to the installation of ROOT and compilation of the wrapper library. **Be patient**. You can open the indicated `build.log` file to see the progress.

## ROOT version

Expand Down
7 changes: 4 additions & 3 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
BUILD_DIR = build
ROOT_CONFIG = root-config
UNAME=$(shell uname)

ROOT_LIBS = $(shell $(ROOT_CONFIG) --libs)
ROOT_INC_DIR = $(shell $(ROOT_CONFIG) --incdir)
Expand Down Expand Up @@ -39,7 +40,7 @@ LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)

.PHONY: all clean distclean run_demo run_demo2 check_root make_lib_from_objs

PRODUCTS = libjlROOT2$(SO_SUFFIX)
PRODUCTS = $(BUILD_DIR)/libjlROOT2$(SO_SUFFIX)

#Define WRAPPER_CXX
#WRAPPER_CXX: = $(file < src/generated_cxx) Extra.cxx #does not work on MacOS
Expand All @@ -59,7 +60,7 @@ distclean:


$(BUILD_DIR):
@mkdir $(BUILD_DIR)
@mkdir -p $(BUILD_DIR)
@echo 'all:\n\n%:\n\t$$(MAKE) -C .. $$@\nclean:\n\t$$(MAKE) -C .. clean build\n' > $(BUILD_DIR)/Makefile

$(BUILD_DIR)/ROOT2-generated.wit: ROOT2.wit $(BUILD_DIR)
Expand Down Expand Up @@ -99,7 +100,7 @@ $(BUILD_DIR)/%.o: src/%.cxx $(BUILD_DIR)
[ -d $(BUILD_DIR)/libROOT2/build ] || mkdir -p $(BUILD_DIR)/libROOT2/build
$(COMPILE.cc) $(CPPFLAGS) -o $@ $<

libjlROOT2$(SO_SUFFIX): $(OBJS)
$(BUILD_DIR)/libjlROOT2$(SO_SUFFIX): $(OBJS)
$(MAKE) check_root
$(LINK.o) -o $@ --shared -fPIC $(OBJS) $(ROOT_LIBS) $(LDLIBS)

Expand Down
49 changes: 24 additions & 25 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import CxxWrap
import Libdl
import Conda

import TOML
using UUIDs
using Scratch
const CXXWRAP_PREFIX = CxxWrap.prefix_path()
const JL_SHARE = joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia")
const JULIA = joinpath(Sys.BINDIR, "julia")
const libname="libjlROOT2." * Libdl.dlext

const required_root_version="6.30.04"
const conda_root_version = "6.30.04"
const supported_root_versions = [ conda_root_version ]

used_root_version = ""
root_libdir = ""
root_bindir = ""
rootconfig = "root-config"

#function version_decode(version_label)
# nums = split(version_label, ".")
# if length(nums) < 3
# error("Error in ROOT version check. Unrecognized version label $version_label")
# end
# nums
#end
const pkg_uuid = UUID(TOML.parsefile(joinpath(dirname(@__DIR__), "Project.toml"))["uuid"])
const pkg_version = VersionNumber(TOML.parsefile(joinpath(dirname(@__DIR__), "Project.toml"))["version"])

if isfile(libname)
@info "Library " * libname * " found. Nothing to build."
exit(0)
end

#Test root installation
try
Expand All @@ -36,52 +30,57 @@ catch
global root_found = false
end

#vnums_used=version_decode(used_root_version)
#vnums_required=version_decode(required_root_version)
const scratch = joinpath(get_scratch!(pkg_uuid, "lib"), string(pkg_version), "ROOT-v" * used_root_version)

found_root_ok = root_found && used_root_version == required_root_version
found_root_ok = root_found && (used_root_version supported_root_versions)

if found_root_ok
@info "ROOT libraries from $root_libdir will be used."
else
if !root_found
@info "Executable root-config not found. We will try to install ROOT from conda-forge."
elseif !found_root_ok
@info "Release of the found root installation is not compatible. Release " * required_root_version * " required. We will try to install root from conda-forge."
@info "Release of the found root installation is not compatible. Release " * join(supported_root_versions) * " required. We will try to install root from conda-forge."
end
try
cmd=:(Conda.add("root=$required_root_version", args=`--strict-channel-priority --override-channels -c conda-forge`, satisfied_skip_solve=true))
cmd=:(Conda.add("root=$conda_root_version", args=`--strict-channel-priority --override-channels -c conda-forge`, satisfied_skip_solve=true))
@info "Conda command: $cmd"
eval(cmd)
global rootlibdir = Conda.LIBDIR
global rootconfig = joinpath(Conda.BINDIR, "root-config")
global found_root_ok = true
catch
@error "Failed to install ROOT release $required_root_version from conda-forge. Check you network connection or install ROOT yourself and restart julia with the path to the ROOT executables included in the shell exectable path list (PATH)."
@error "Failed to install ROOT release $conda_root_version from conda-forge. Check you network connection or install ROOT yourself and restart julia with the path to the ROOT executables included in the shell exectable path list (PATH)."
#no-op
end
end

found_root_ok || exit(1)

cmd=`make CXXWRAP_PREFIX="$CXXWRAP_PREFIX" JL_SHARE="$JL_SHARE" JULIA="$JULIA" ROOT_CONFIG="$rootconfig" -j $(Sys.CPU_THREADS)`
const buildpath = joinpath(scratch, "build")

cmd=`make BUILD_DIR=$buildpath CXXWRAP_PREFIX="$CXXWRAP_PREFIX" JL_SHARE="$JL_SHARE" JULIA="$JULIA" ROOT_CONFIG="$rootconfig" -j $(Sys.CPU_THREADS)`
@info "Build command: " * string(cmd)[2:end-1] * " executed in " * pwd() * " directory."

#julia needs to be in the PATH for julia-config.jl, invoked by the Makefile, to run
PATH=Sys.BINDIR * ":" * ENV["PATH"]

build_rc = run(Cmd(cmd, env = ["PATH" => PATH], ignorestatus=true)).exitcode
libpath = joinpath(scratch, libname)
try
run(`make clean`)
catch
@warn "Failed to clean-up directory after dependency build."
mv(joinpath(buildpath, libname), libpath, force=true)
splitpath(buildpath)[end-1] != "build" || error("Bug foud. buildpath must end with /build") #protection against deleted bad directory after introduciton of a bug
rm(buildpath, recursive=true, force=true)
catch e
@warn "Failed to clean-up directory after dependency build. " * string(e)
end

if build_rc == 0
rootbindir = readchomp(`$rootconfig --bindir`)
open("deps.jl", "w") do f
println(f, "const rootlibdir = \"", rootlibdir, "\"")
println(f, "const rootbindir = \"", rootbindir, "\"")
println(f, "const rootlibdir = \"", escape_string(rootlibdir), "\"")
println(f, "const rootbindir = \"", escape_string(rootbindir), "\"")
println(f, "const libpath = \"", escape_string(libpath), "\"")
end
end

Expand Down
Loading

0 comments on commit a7ea19b

Please sign in to comment.