Skip to content

Commit cf7c55c

Browse files
Add a CI workflow that tests the packaging using libsemigroups installed with a combination of --disable-eigen and --disable-hpcombi (#362)
1 parent e3d3b9d commit cf7c55c

File tree

8 files changed

+137
-32
lines changed

8 files changed

+137
-32
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Config options
2+
on: [pull_request, workflow_dispatch]
3+
4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.ref }}
6+
cancel-in-progress: true
7+
8+
jobs:
9+
run-tests:
10+
name: ${{ matrix.flags }} (${{ matrix.os }})
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
flags:
15+
[
16+
"--enable-hpcombi --disable-eigen",
17+
"--disable-hpcombi --enable-eigen",
18+
"--disable-hpcombi --disable-eigen",
19+
]
20+
os: [ubuntu-latest, macOS-latest]
21+
include:
22+
- os: ubuntu-latest
23+
compiler: g++
24+
- os: macOS-latest
25+
compiler: clang++
26+
runs-on: ${{ matrix.os }}
27+
timeout-minutes: 15
28+
defaults:
29+
run:
30+
shell: bash -l {0}
31+
env:
32+
CXX: "ccache ${{ matrix.compiler }}"
33+
CXXFLAGS: "-O2 -g"
34+
UV_NO_SYNC: "1"
35+
LD_LIBRARY_PATH: "/usr/local/lib"
36+
steps:
37+
# Setup environment
38+
- uses: actions/checkout@v5
39+
- name: Set up Python . . .
40+
uses: actions/setup-python@v6
41+
with:
42+
python-version-file: "pyproject.toml"
43+
- name: Install uv . . .
44+
uses: astral-sh/setup-uv@v7
45+
with:
46+
enable-cache: true
47+
48+
# Build libsemigroups
49+
- name: "macOS only: Install libsemigroups dependencies . . ."
50+
if: ${{ matrix.os == 'macOS-latest' }}
51+
run: brew install autoconf automake libtool
52+
- name: "Setup ccache . . ."
53+
uses: Chocobo1/setup-ccache-action@v1
54+
with:
55+
update_packager_index: false
56+
install_ccache: true
57+
- name: "Install libsemigroups . . ."
58+
run: |
59+
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
60+
cd libsemigroups
61+
./autogen.sh
62+
./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" ${{ matrix.flags }}
63+
sudo make install -j4
64+
ccache -s
65+
66+
# Build libsemigroups_pybind11
67+
- name: "Install libsemigroups_pybind11 . . ."
68+
run: uv sync --verbose --locked --all-extras --no-dev
69+
70+
# Run the tests
71+
- name: "Running tests . . ."
72+
run: uv run pytest
73+
- name: "Running doc tests . . ."
74+
run: uv run make doctest

.github/workflows/custom-branch.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ jobs:
6060
run: |
6161
git clone --depth 1 --branch ${{ inputs.branch }} https://github.com/${{ inputs.fork }}.git
6262
cd libsemigroups
63-
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
63+
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
6464
ccache -s
6565
6666
# Build libsemigroups_pybind11
6767
- name: "Install libsemigroups_pybind11 . . ."
68-
run: uv sync --locked --all-extras
68+
run: uv sync --verbose --locked --all-extras
6969

70-
# Run the tests and lint
70+
# Run the tests
7171
- name: "Running tests . . ."
7272
run: uv run pytest
7373
- name: "Running doc tests . . ."

.github/workflows/doc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ jobs:
5151
run: |
5252
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
5353
cd libsemigroups
54-
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
54+
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
5555
ccache -s
5656
5757
# Build libsemigroups_pybind11
5858
- name: "Install libsemigroups_pybind11 . . ."
59-
run: uv sync --locked --extra docs --no-dev
59+
run: uv sync --verbose --locked --extra docs --no-dev
6060

6161
# Check the docs
6262
- name: "Checking the doc for warnings . . ."

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
with:
3939
enable-cache: true
4040
- name: "Install libsemigroups_pybind11 dependencies . . ."
41-
run: uv sync --locked --no-install-project --no-dev --group lint
41+
run: uv sync --verbose --locked --no-install-project --no-dev --group lint
4242
- name: "Find the names of the Python files that will be linted"
4343
run: echo "PYTHON_FILES=$(uv run ruff check --show-files | grep '\.py$' | tr -s '\n' ' ')" >> $GITHUB_ENV
4444

@@ -63,12 +63,12 @@ jobs:
6363
run: |
6464
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
6565
cd libsemigroups
66-
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
66+
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
6767
ccache -s
6868
6969
# Build libsemigroups_pybind11
7070
- name: "Install libsemigroups_pybind11 . . ."
71-
run: uv sync --locked --all-extras --no-dev --group lint
71+
run: uv sync --verbose --locked --all-extras --no-dev --group lint
7272

7373
# Lint with ruff and cpplint
7474
- name: "Lint with pylint . . ."

.github/workflows/pip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: |
4949
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
5050
cd libsemigroups
51-
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
51+
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
5252
ccache -s
5353
5454
# Build libsemigroups_pybind11

.github/workflows/test-conda.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ jobs:
5858

5959
# Build libsemigroups_pybind11
6060
- name: "Install libsemigroups_pybind11 . . ."
61-
run: uv sync --locked --all-extras --no-dev --group lint
61+
run: uv sync --verbose --locked --all-extras --no-dev
6262

63-
# Run the tests and lint
63+
# Run the tests
6464
- name: "Running tests . . ."
6565
run: uv run pytest
6666
- name: "Running doc tests . . ."

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ jobs:
5050
run: |
5151
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
5252
cd libsemigroups
53-
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
53+
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
5454
ccache -s
5555
5656
# Build libsemigroups_pybind11
5757
- name: "Install libsemigroups_pybind11 . . ."
58-
run: uv sync --locked --all-extras --no-dev --group lint
58+
run: uv sync --verbose --locked --all-extras --no-dev
5959

60-
# Run the tests and lint
60+
# Run the tests
6161
- name: "Running tests . . ."
6262
run: uv run pytest
6363
- name: "Running doc tests . . ."

setup.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
(libsemigroups.rtfd.io).
1010
"""
1111

12+
import distutils.errors # pylint: disable=deprecated-module
1213
import glob
1314
import os
1415
import platform
1516
import sys
17+
from pathlib import Path
18+
from typing import Any
1619

1720
import pkgconfig
1821
from pybind11.setup_helpers import (
@@ -21,6 +24,7 @@
2124
build_ext,
2225
has_flag,
2326
naive_recompile,
27+
tmp_chdir,
2428
)
2529
from setuptools import setup
2630

@@ -59,30 +63,58 @@ def get_arch():
5963
return arch
6064

6165

66+
def get_macro_value(compiler: Any, macro: str, include_directories: list[str]) -> bool:
67+
"""Check the value of a libsemigroups C++ preprocessor macro"""
68+
69+
with tmp_chdir():
70+
fname = Path("macro-check.cpp")
71+
file_text = f"""
72+
#include <libsemigroups/config.hpp>
73+
int main () {{
74+
static_assert({macro});
75+
return 0;
76+
}}
77+
"""
78+
fname.write_text(file_text, encoding="utf-8")
79+
80+
try:
81+
compiler.compile([str(fname)], include_dirs=include_directories)
82+
except distutils.errors.CompileError:
83+
return False
84+
return True
85+
86+
6287
class LibsemigroupsBuildExt(build_ext):
6388
# pylint: disable=too-few-public-methods
6489
"""Class conditionally add compile flags"""
6590

6691
def build_extensions(self):
6792
"""Adds compile flags before calling build_extensions in build_ext"""
6893
compiler = self.compiler
69-
70-
if has_flag(compiler, "-mavx"):
71-
print("Compiler supports '-mavx' flag, adding it to 'extra_compile_args'")
72-
for ext in self.extensions:
73-
ext.extra_compile_args += ["-mavx"]
74-
else:
75-
print("Compiler does not support '-mavx' flag, not adding it to 'extra_compile_args'")
76-
if get_arch() == "arm" and (
77-
any(x.startswith("gcc") for x in compiler.compiler)
78-
or any(x.startswith("g++") for x in compiler.compiler_cxx)
79-
):
80-
print(
81-
"Compiler is gcc, and architecture is arm, adding '-fpermissive' to "
82-
"'extra_compile_args'"
83-
)
84-
for ext in self.extensions:
85-
ext.extra_compile_args += ["-fpermissive"]
94+
hpcombi_enabled = get_macro_value(compiler, "LIBSEMIGROUPS_HPCOMBI_ENABLED", include_dirs)
95+
96+
if hpcombi_enabled:
97+
for flag in ("-flax-vector-conversions", "-mavx"):
98+
if has_flag(compiler, flag):
99+
print(f"Compiler supports '{flag}' flag, adding it to 'extra_compile_args'")
100+
for ext in self.extensions:
101+
ext.extra_compile_args += [flag]
102+
else:
103+
print(
104+
f"Compiler does not support '{flag}' flag, not adding it to "
105+
"'extra_compile_args'"
106+
)
107+
108+
if get_arch() == "arm" and (
109+
any(x.startswith("gcc") for x in compiler.compiler)
110+
or any(x.startswith("g++") for x in compiler.compiler_cxx)
111+
):
112+
print(
113+
"Compiler is gcc, and architecture is arm, adding '-fpermissive' to "
114+
"'extra_compile_args'"
115+
)
116+
for ext in self.extensions:
117+
ext.extra_compile_args += ["-fpermissive"]
86118

87119
for ext in self.extensions:
88120
print(f"'extra_compile_args' for '{ext.name}' are:")
@@ -99,7 +131,6 @@ def build_extensions(self):
99131
library_dirs=libsemigroups_info["library_dirs"],
100132
language="c++",
101133
libraries=["semigroups"],
102-
extra_compile_args=["-flax-vector-conversions"],
103134
)
104135
]
105136

0 commit comments

Comments
 (0)