Skip to content

Commit 98440da

Browse files
authored
0.14.0 (#3)
* utm 0.14.0 * updated build script
1 parent 1c91023 commit 98440da

File tree

8 files changed

+339
-161
lines changed

8 files changed

+339
-161
lines changed

.github/build.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import argparse
2+
import os
3+
import subprocess
4+
from urllib.request import urlretrieve
5+
6+
DEFAULT_UTM_VERSION = "0.14.0"
7+
DEFAULT_BOOST_VERSION = "1.84.0"
8+
DEFAULT_XERCES_C_VERSION = "3.2.5"
9+
DEFAULT_BUILD_DIR = os.path.join(os.getcwd(), "build")
10+
DEFAULT_INSTALL_PREFIX = os.path.join(os.getcwd(), "dist")
11+
12+
13+
def run(*args):
14+
subprocess.run(args, check=True)
15+
16+
17+
class Builder:
18+
def __init__(self, version, build_dir, install_prefix):
19+
self.version = version
20+
self.build_dir = os.path.realpath(build_dir)
21+
self.install_prefix = os.path.realpath(install_prefix)
22+
self.cpu_count = os.cpu_count()
23+
24+
@property
25+
def version_us(self):
26+
return self.version.replace(".", "_")
27+
28+
def fetch(self):
29+
...
30+
31+
def build(self):
32+
...
33+
34+
35+
class BoostBuilder(Builder):
36+
def fetch(self):
37+
os.chdir(self.build_dir)
38+
url = f"https://archives.boost.io/release/{self.version}/source/boost_{self.version_us}.tar.gz"
39+
urlretrieve(url, f"boost_{self.version_us}.tar.gz")
40+
run("tar", "xf", f"boost_{self.version_us}.tar.gz", "-C", self.build_dir)
41+
42+
def build(self):
43+
os.chdir(self.build_dir)
44+
os.chdir(f"boost_{self.version_us}")
45+
b2_options = [
46+
f"-j{self.cpu_count}",
47+
"--with-system",
48+
"--with-filesystem",
49+
"link=shared",
50+
"runtime-link=shared",
51+
"threading=multi",
52+
"variant=release",
53+
]
54+
run("./bootstrap.sh")
55+
run("./b2", *b2_options, "install", f"--prefix={self.install_prefix}")
56+
57+
58+
class XercesCBuilder(Builder):
59+
def fetch(self):
60+
os.chdir(self.build_dir)
61+
url = f"https://github.com/apache/xerces-c/archive/v{self.version}.tar.gz"
62+
urlretrieve(url, f"xerces-c-{self.version}.tar.gz")
63+
run("tar", "xf", f"xerces-c-{self.version}.tar.gz", "-C", self.build_dir)
64+
os.chdir(f"xerces-c-{self.version}")
65+
66+
def build(self):
67+
os.chdir(self.build_dir)
68+
os.chdir(f"xerces-c-{self.version}")
69+
os.makedirs("build")
70+
os.chdir("build")
71+
cmake_options = [
72+
"-DCMAKE_BUILD_TYPE=Release",
73+
f"-DCMAKE_INSTALL_PREFIX={self.install_prefix}",
74+
"-DBUILD_SHARED_LIBS=ON",
75+
"-DCMAKE_INSTALL_LIBDIR=lib",
76+
]
77+
make_options = [
78+
f"-j{self.cpu_count}",
79+
]
80+
run("cmake", *cmake_options, "..")
81+
run("make", *make_options)
82+
run("make", "install")
83+
84+
85+
class UtmBuilder(Builder):
86+
boost_prefix = None
87+
xerces_c_prefix = None
88+
89+
def fetch(self):
90+
os.chdir(self.build_dir)
91+
url = f"https://gitlab.cern.ch/cms-l1t-utm/utm/-/archive/utm_{self.version}/utm-utm_{self.version}.tar.gz"
92+
urlretrieve(url, f"utm-utm_{self.version}.tar.gz")
93+
run("tar", "xzf", f"utm-utm_{self.version}.tar.gz", "-C", self.build_dir)
94+
os.chdir(f"utm-utm_{self.version}")
95+
96+
def build(self):
97+
os.chdir(self.build_dir)
98+
os.chdir(f"utm-utm_{self.version}")
99+
run("./configure")
100+
make_options = [
101+
f"-j{self.cpu_count}",
102+
"CPPFLAGS='-DNDEBUG -DSWIG'",
103+
]
104+
if self.boost_prefix:
105+
make_options.append(f"BOOST_BASE={self.boost_prefix}")
106+
if self.xerces_c_prefix:
107+
make_options.append(f"XERCES_C_BASE={self.xerces_c_prefix}")
108+
run("make", "all", *make_options)
109+
run("make", "install", f"PREFIX={self.install_prefix}")
110+
111+
112+
def parse_args():
113+
parser = argparse.ArgumentParser()
114+
parser.add_argument("--utm-version", default=DEFAULT_UTM_VERSION)
115+
parser.add_argument("--with-boost", action="store_true")
116+
parser.add_argument("--boost-version", default=DEFAULT_BOOST_VERSION)
117+
parser.add_argument("--with-xerces-c", action="store_true")
118+
parser.add_argument("--xerces-c-version", default=DEFAULT_XERCES_C_VERSION)
119+
parser.add_argument("--build", default=DEFAULT_BUILD_DIR)
120+
parser.add_argument("--install-prefix", default=DEFAULT_INSTALL_PREFIX)
121+
return parser.parse_args()
122+
123+
124+
def main():
125+
args = parse_args()
126+
127+
# Setup
128+
129+
if not os.path.exists(args.build):
130+
os.makedirs(args.build)
131+
132+
if not os.path.exists(args.install_prefix):
133+
os.makedirs(args.install_prefix)
134+
135+
boost_builder = BoostBuilder(
136+
version=args.boost_version,
137+
build_dir=args.build,
138+
install_prefix=args.install_prefix,
139+
)
140+
xerxes_c_builder = XercesCBuilder(
141+
version=args.xerces_c_version,
142+
build_dir=args.build,
143+
install_prefix=args.install_prefix,
144+
)
145+
utm_builder = UtmBuilder(
146+
version=args.utm_version,
147+
build_dir=args.build,
148+
install_prefix=args.install_prefix,
149+
)
150+
151+
# Fetch
152+
153+
if args.with_boost:
154+
boost_builder.fetch()
155+
utm_builder.boost_prefix=args.install_prefix
156+
157+
if args.with_xerces_c:
158+
xerxes_c_builder.fetch()
159+
utm_builder.xerces_c_prefix=args.install_prefix
160+
161+
utm_builder.fetch()
162+
163+
# Build
164+
165+
if args.with_boost:
166+
boost_builder.build()
167+
168+
if args.with_xerces_c:
169+
xerxes_c_builder.build()
170+
171+
utm_builder.build()
172+
173+
174+
if __name__ == "__main__":
175+
main()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build package
2+
3+
on: [push]
4+
5+
jobs:
6+
build_wheel:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Install build dependecies
14+
run: |
15+
sudo apt-get install -y libboost-dev libboost-system-dev libboost-filesystem-dev libxerces-c-dev swig
16+
- name: Build utm
17+
run: |
18+
python3 .github/build.py --install-prefix=${GITHUB_WORKSPACE}/dist
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install build wheel
27+
- name: Build wheel
28+
run: |
29+
export UTM_BASE=${GITHUB_WORKSPACE}/dist
30+
python -m build
31+
python -m pip install dist/*-linux_x86_64.whl

.github/workflows/build-wheels.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build wheels
2+
3+
on: [push, workflow_dispatch]
4+
5+
jobs:
6+
build_wheels_linux:
7+
name: Build wheels for Linux
8+
runs-on: ubuntu-latest
9+
env:
10+
CIBW_SKIP: pp*
11+
CIBW_ENVIRONMENT: >
12+
BOOST_BASE=/project/dist
13+
XERCES_C_BASE=/project/dist
14+
UTM_BASE=/project/dist
15+
LD_LIBRARY_PATH=/project/dist/lib
16+
CIBW_BEFORE_ALL: |
17+
python3 .github/build.py --with-boost --with-xerces-c --install-prefix=/project/dist
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v3
21+
- name: Install cibuildwheel
22+
run: python -m pip install cibuildwheel==3.3.0
23+
- name: Build wheels
24+
run: |
25+
python -m cibuildwheel --output-dir wheelhouse
26+
- uses: actions/upload-artifact@v4
27+
with:
28+
name: cibw-wheels-linux
29+
path: ./wheelhouse/*.whl
30+
build_wheels_macos:
31+
name: Build wheels for MacOS
32+
runs-on: macos-15-intel
33+
env:
34+
MACOSX_DEPLOYMENT_TARGET: '10.9'
35+
CIBW_SKIP: pp*
36+
CIBW_ENVIRONMENT: >
37+
BOOST_BASE=${GITHUB_WORKSPACE}/dist
38+
XERCES_C_BASE=${GITHUB_WORKSPACE}/dist
39+
UTM_BASE=${GITHUB_WORKSPACE}/dist
40+
REPAIR_LIBRARY_PATH=${GITHUB_WORKSPACE}/dist/lib
41+
CIBW_BEFORE_ALL: |
42+
brew install swig
43+
python .github/build.py --with-boost --with-xerces-c --install-prefix=${GITHUB_WORKSPACE}/dist
44+
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
45+
DYLD_LIBRARY_PATH="${REPAIR_LIBRARY_PATH}" delocate-listdeps {wheel} &&
46+
DYLD_LIBRARY_PATH="${REPAIR_LIBRARY_PATH}" delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: actions/setup-python@v3
50+
- name: Install cibuildwheel
51+
run: |
52+
python -m pip install cibuildwheel==3.3.0
53+
- name: Build wheels
54+
run: |
55+
python -m cibuildwheel --output-dir wheelhouse
56+
- uses: actions/upload-artifact@v4
57+
with:
58+
name: cibw-wheels-macos
59+
path: ./wheelhouse/*.whl

.github/workflows/wheel.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,20 @@
22

33
Python bindings for tmTable.
44

5-
## Install instructions
5+
## Install
66

77
It is recommended to install the utm Python bindings in a virtual environment
88
which makes it also possible to use multiple versions in parallel.
99

10-
### Python 3.12
11-
12-
```bash
13-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
14-
```
15-
16-
### Python 3.11
17-
18-
```bash
19-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
20-
```
21-
22-
### Python 3.10
23-
24-
```bash
25-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
26-
```
27-
28-
### Python 3.9
29-
30-
```bash
31-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
32-
```
33-
34-
### Python 3.8
35-
36-
```bash
37-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
38-
```
39-
40-
### Python 3.7
41-
42-
```bash
43-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
44-
```
45-
46-
### Python 3.6
47-
4810
```bash
49-
pip install https://github.com/cms-l1-globaltrigger/tm-table/releases/download/0.13.0/tm_table-0.13.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
11+
pip install --index https://globaltrigger.web.cern.ch/pypi tm-table==0.14.0
5012
```
5113

5214
## Build instructions
5315

5416
**Note:** building the Python bindings from scratch is only recommended for
5517
development. To create portable Python bindings use the
56-
[tm-manylinux](https://github.com/cms-l1-globaltrigger/tm-manylinux)
57-
Docker image.
18+
[cibuildwheel](https://cibuildwheel.pypa.io/en/stable/) workflow.
5819

5920
Make sure to install all required build dependecies.
6021

@@ -70,7 +31,7 @@ Check out and build all utm libraries.
7031
```bash
7132
git clone https://gitlab.cern.ch/cms-l1t-utm/utm.git
7233
cd utm
73-
git checkout utm_0.13.0
34+
git checkout utm_0.14.0
7435
./configure # create makefiles
7536
make all CPPFLAGS='-DNDEBUG -DSWIG' # compile with -DSWIG
7637
. ./env.sh # source paths
@@ -83,7 +44,7 @@ recommended to execute this step in a virtual environment.
8344
```bash
8445
git clone https://github.com/cms-l1-globaltrigger/tm-table.git
8546
cd tm-table
86-
git checkout 0.13.0
47+
git checkout 0.14.0
8748
python3 -m venv env
8849
. env/bin/activate
8950
pip install --upgrade pip

0 commit comments

Comments
 (0)