Skip to content

Commit ced9a4e

Browse files
committed
added build.py script
1 parent fe4cd1c commit ced9a4e

File tree

7 files changed

+245
-86
lines changed

7 files changed

+245
-86
lines changed

.github/build.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import argparse
2+
import os
3+
import subprocess
4+
from urllib.request import urlretrieve
5+
6+
DEFAULT_UTM_VERSION = "0.13.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+
def fetch(self):
25+
...
26+
27+
def build(self):
28+
...
29+
30+
31+
class BoostBuilder(Builder):
32+
def fetch(self):
33+
os.chdir(self.build_dir)
34+
url = f"https://github.com/boostorg/boost/releases/download/boost-{self.version}/boost-{self.version}.tar.xz"
35+
urlretrieve(url, f"boost-{self.version}.tar.xz")
36+
run("tar", "xf", f"boost-{self.version}.tar.xz", "-C", self.build_dir)
37+
38+
def build(self):
39+
os.chdir(self.build_dir)
40+
os.chdir(f"boost-{self.version}")
41+
b2_options = [
42+
f"-j{self.cpu_count}",
43+
"--with-system",
44+
"--with-filesystem",
45+
"link=shared",
46+
"runtime-link=shared",
47+
"threading=multi",
48+
"variant=release",
49+
]
50+
run("./bootstrap.sh")
51+
run("./b2", *b2_options, "install", f"--prefix={self.install_prefix}")
52+
53+
54+
class XercesCBuilder(Builder):
55+
def fetch(self):
56+
os.chdir(self.build_dir)
57+
url = f"https://github.com/apache/xerces-c/archive/v{self.version}.tar.gz"
58+
urlretrieve(url, f"xerces-c-{self.version}.tar.gz")
59+
run("tar", "xf", f"xerces-c-{self.version}.tar.gz", "-C", self.build_dir)
60+
os.chdir(f"xerces-c-{self.version}")
61+
62+
def build(self):
63+
os.chdir(self.build_dir)
64+
os.chdir(f"xerces-c-{self.version}")
65+
os.makedirs("build")
66+
os.chdir("build")
67+
cmake_options = [
68+
"-DCMAKE_BUILD_TYPE=Release",
69+
f"-DCMAKE_INSTALL_PREFIX={self.install_prefix}",
70+
"-DBUILD_SHARED_LIBS=ON",
71+
"-DCMAKE_INSTALL_LIBDIR=lib",
72+
]
73+
make_options = [
74+
f"-j{self.cpu_count}",
75+
]
76+
run("cmake", *cmake_options, "..")
77+
run("make", *make_options)
78+
run("make", "install")
79+
80+
81+
class UtmBuilder(Builder):
82+
boost_prefix = None
83+
xerces_c_prefix = None
84+
85+
def fetch(self):
86+
os.chdir(self.build_dir)
87+
url = f"https://gitlab.cern.ch/cms-l1t-utm/utm/-/archive/utm_{self.version}/utm-utm_{self.version}.tar.gz"
88+
urlretrieve(url, f"utm-utm_{self.version}.tar.gz")
89+
run("tar", "xzf", f"utm-utm_{self.version}.tar.gz", "-C", self.build_dir)
90+
os.chdir(f"utm-utm_{self.version}")
91+
92+
def build(self):
93+
os.chdir(self.build_dir)
94+
os.chdir(f"utm-utm_{self.version}")
95+
run("./configure")
96+
make_options = [
97+
f"-j{self.cpu_count}",
98+
"CPPFLAGS='-DNDEBUG -DSWIG'",
99+
]
100+
if self.boost_prefix:
101+
make_options.append(f"BOOST_BASE={self.boost_prefix}")
102+
if self.xerces_c_prefix:
103+
make_options.append(f"XERCES_C_BASE={self.xerces_c_prefix}")
104+
run("make", "all", *make_options)
105+
run("make", "install", f"PREFIX={self.install_prefix}")
106+
107+
108+
def parse_args():
109+
parser = argparse.ArgumentParser()
110+
parser.add_argument("--utm-version", default=DEFAULT_UTM_VERSION)
111+
parser.add_argument("--with-boost", action="store_true")
112+
parser.add_argument("--boost-version", default=DEFAULT_BOOST_VERSION)
113+
parser.add_argument("--with-xerces-c", action="store_true")
114+
parser.add_argument("--xerces-c-version", default=DEFAULT_XERCES_C_VERSION)
115+
parser.add_argument("--build", default=DEFAULT_BUILD_DIR)
116+
parser.add_argument("--install-prefix", default=DEFAULT_INSTALL_PREFIX)
117+
return parser.parse_args()
118+
119+
120+
def main():
121+
args = parse_args()
122+
123+
# Setup
124+
125+
if not os.path.exists(args.build):
126+
os.makedirs(args.build)
127+
128+
if not os.path.exists(args.install_prefix):
129+
os.makedirs(args.install_prefix)
130+
131+
boost_builder = BoostBuilder(
132+
version=args.boost_version,
133+
build_dir=args.build,
134+
install_prefix=args.install_prefix,
135+
)
136+
xerxes_c_builder = XercesCBuilder(
137+
version=args.xerces_c_version,
138+
build_dir=args.build,
139+
install_prefix=args.install_prefix,
140+
)
141+
utm_builder = UtmBuilder(
142+
version=args.utm_version,
143+
build_dir=args.build,
144+
install_prefix=args.install_prefix,
145+
)
146+
147+
# Fetch
148+
149+
if args.with_boost:
150+
boost_builder.fetch()
151+
utm_builder.boost_prefix=args.install_prefix
152+
153+
if args.with_xerces_c:
154+
xerxes_c_builder.fetch()
155+
utm_builder.xerces_c_prefix=args.install_prefix
156+
157+
utm_builder.fetch()
158+
159+
# Build
160+
161+
if args.with_boost:
162+
boost_builder.build()
163+
164+
if args.with_xerces_c:
165+
xerxes_c_builder.build()
166+
167+
utm_builder.build()
168+
169+
170+
if __name__ == "__main__":
171+
main()

.github/build_boost.sh

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

.github/build_utm.sh

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

.github/build_xerces_c.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
name: wheel
1+
name: Build package
22

33
on: [push]
44

55
jobs:
66
build_wheel:
77
runs-on: ubuntu-latest
88
env:
9-
MODULE: tmEventSetup
109
UTM_VERSION: 0.13.0
10+
MODULE: tmEventSetup
1111
strategy:
1212
matrix:
13-
python-version: ["3.12"]
13+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
- name: Install build dependecies
1717
run: |
1818
sudo apt-get install -y libboost-dev libboost-system-dev libboost-filesystem-dev libxerces-c-dev swig
1919
- name: Build utm
2020
run: |
21-
curl -L https://gitlab.cern.ch/cms-l1t-utm/utm/-/archive/utm_${{ env.UTM_VERSION }}/utm-utm_${{ env.UTM_VERSION }}.tar.gz -O
22-
tar xzf utm-utm_${{ env.UTM_VERSION }}.tar.gz
23-
cd utm-utm_${{ env.UTM_VERSION }}
24-
./configure
25-
make all -j4 CPPFLAGS='-DNDEBUG -DSWIG'
26-
make install PREFIX=.
21+
python3 .github/build.py --utm-version=${{ env.UTM_VERSION }} --install-prefix=${GITHUB_WORKSPACE}/dist
2722
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v3
2924
with:
3025
python-version: ${{ matrix.python-version }}
3126
- name: Install dependencies
@@ -34,11 +29,11 @@ jobs:
3429
pip install build wheel
3530
- name: Build wheel
3631
run: |
37-
export UTM_BASE="$(pwd)/utm-utm_${{ env.UTM_VERSION }}"
38-
python -m build --wheel
32+
export UTM_BASE=${GITHUB_WORKSPACE}/dist
33+
python -m build
3934
python -m pip install dist/*-linux_x86_64.whl
4035
- name: Test module
4136
run: |
42-
export LD_LIBRARY_PATH="$(pwd)/utm-utm_${{ env.UTM_VERSION }}:$LD_LIBRARY_PATH"
37+
export LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/dist/lib
4338
python -m ${{ env.MODULE }}.__init__
44-
python -c 'from ${{ env.MODULE }} import __version__; print(__version__)'
39+
python -c 'from ${{ env.MODULE }} import __version__; print(__version__); assert __version__ == "${{ env.UTM_VERSION }}"'

.github/workflows/build-wheels.yml

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

.github/workflows/build_wheels_macos.yml

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

0 commit comments

Comments
 (0)