Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/config-options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Config options
on: [pull_request, workflow_dispatch]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
run-tests:
name: ${{ matrix.flags }} (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
flags:
[
"--enable-hpcombi --disable-eigen",
"--disable-hpcombi --enable-eigen",
"--disable-hpcombi --disable-eigen",
]
os: [ubuntu-latest, macOS-latest]
include:
- os: ubuntu-latest
compiler: g++
- os: macOS-latest
compiler: clang++
runs-on: ${{ matrix.os }}
timeout-minutes: 15
defaults:
run:
shell: bash -l {0}
env:
CXX: "ccache ${{ matrix.compiler }}"
CXXFLAGS: "-O2 -g"
UV_NO_SYNC: "1"
LD_LIBRARY_PATH: "/usr/local/lib"
steps:
# Setup environment
- uses: actions/checkout@v5
- name: Set up Python . . .
uses: actions/setup-python@v6
with:
python-version-file: "pyproject.toml"
- name: Install uv . . .
uses: astral-sh/setup-uv@v7
with:
enable-cache: true

# Build libsemigroups
- name: "macOS only: Install libsemigroups dependencies . . ."
if: ${{ matrix.os == 'macOS-latest' }}
run: brew install autoconf automake libtool
- name: "Setup ccache . . ."
uses: Chocobo1/setup-ccache-action@v1
with:
update_packager_index: false
install_ccache: true
- name: "Install libsemigroups . . ."
run: |
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
cd libsemigroups
./autogen.sh
./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" ${{ matrix.flags }}
sudo make install -j4
ccache -s

# Build libsemigroups_pybind11
- name: "Install libsemigroups_pybind11 . . ."
run: uv sync --verbose --locked --all-extras --no-dev

# Run the tests
- name: "Running tests . . ."
run: uv run pytest
- name: "Running doc tests . . ."
run: uv run make doctest
6 changes: 3 additions & 3 deletions .github/workflows/custom-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ jobs:
run: |
git clone --depth 1 --branch ${{ inputs.branch }} https://github.com/${{ inputs.fork }}.git
cd libsemigroups
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
ccache -s

# Build libsemigroups_pybind11
- name: "Install libsemigroups_pybind11 . . ."
run: uv sync --locked --all-extras
run: uv sync --verbose --locked --all-extras

# Run the tests and lint
# Run the tests
- name: "Running tests . . ."
run: uv run pytest
- name: "Running doc tests . . ."
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ jobs:
run: |
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
cd libsemigroups
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
ccache -s

# Build libsemigroups_pybind11
- name: "Install libsemigroups_pybind11 . . ."
run: uv sync --locked --extra docs --no-dev
run: uv sync --verbose --locked --extra docs --no-dev

# Check the docs
- name: "Checking the doc for warnings . . ."
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
enable-cache: true
- name: "Install libsemigroups_pybind11 dependencies . . ."
run: uv sync --locked --no-install-project --no-dev --group lint
run: uv sync --verbose --locked --no-install-project --no-dev --group lint
- name: "Find the names of the Python files that will be linted"
run: echo "PYTHON_FILES=$(uv run ruff check --show-files | grep '\.py$' | tr -s '\n' ' ')" >> $GITHUB_ENV

Expand All @@ -63,12 +63,12 @@ jobs:
run: |
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
cd libsemigroups
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
ccache -s

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

# Lint with ruff and cpplint
- name: "Lint with pylint . . ."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
cd libsemigroups
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
ccache -s

# Build libsemigroups_pybind11
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ jobs:

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

# Run the tests and lint
# Run the tests
- name: "Running tests . . ."
run: uv run pytest
- name: "Running doc tests . . ."
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ jobs:
run: |
git clone --depth 1 --branch main https://github.com/libsemigroups/libsemigroups.git
cd libsemigroups
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j8
./autogen.sh && ./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" && sudo make install -j4
ccache -s

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

# Run the tests and lint
# Run the tests
- name: "Running tests . . ."
run: uv run pytest
- name: "Running doc tests . . ."
Expand Down
67 changes: 49 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
(libsemigroups.rtfd.io).
"""

import distutils.errors # pylint: disable=deprecated-module
import glob
import os
import platform
import sys
from pathlib import Path
from typing import Any

import pkgconfig
from pybind11.setup_helpers import (
Expand All @@ -21,6 +24,7 @@
build_ext,
has_flag,
naive_recompile,
tmp_chdir,
)
from setuptools import setup

Expand Down Expand Up @@ -59,30 +63,58 @@ def get_arch():
return arch


def get_macro_value(compiler: Any, macro: str, include_directories: list[str]) -> bool:
"""Check the value of a libsemigroups C++ preprocessor macro"""

with tmp_chdir():
fname = Path("macro-check.cpp")
file_text = f"""
#include <libsemigroups/config.hpp>
int main () {{
static_assert({macro});
return 0;
}}
"""
fname.write_text(file_text, encoding="utf-8")

try:
compiler.compile([str(fname)], include_dirs=include_directories)
except distutils.errors.CompileError:
return False
return True


class LibsemigroupsBuildExt(build_ext):
# pylint: disable=too-few-public-methods
"""Class conditionally add compile flags"""

def build_extensions(self):
"""Adds compile flags before calling build_extensions in build_ext"""
compiler = self.compiler

if has_flag(compiler, "-mavx"):
print("Compiler supports '-mavx' flag, adding it to 'extra_compile_args'")
for ext in self.extensions:
ext.extra_compile_args += ["-mavx"]
else:
print("Compiler does not support '-mavx' flag, not adding it to 'extra_compile_args'")
if get_arch() == "arm" and (
any(x.startswith("gcc") for x in compiler.compiler)
or any(x.startswith("g++") for x in compiler.compiler_cxx)
):
print(
"Compiler is gcc, and architecture is arm, adding '-fpermissive' to "
"'extra_compile_args'"
)
for ext in self.extensions:
ext.extra_compile_args += ["-fpermissive"]
hpcombi_enabled = get_macro_value(compiler, "LIBSEMIGROUPS_HPCOMBI_ENABLED", include_dirs)

if hpcombi_enabled:
for flag in ("-flax-vector-conversions", "-mavx"):
if has_flag(compiler, flag):
print(f"Compiler supports '{flag}' flag, adding it to 'extra_compile_args'")
for ext in self.extensions:
ext.extra_compile_args += [flag]
else:
print(
f"Compiler does not support '{flag}' flag, not adding it to "
"'extra_compile_args'"
)

if get_arch() == "arm" and (
any(x.startswith("gcc") for x in compiler.compiler)
or any(x.startswith("g++") for x in compiler.compiler_cxx)
):
print(
"Compiler is gcc, and architecture is arm, adding '-fpermissive' to "
"'extra_compile_args'"
)
for ext in self.extensions:
ext.extra_compile_args += ["-fpermissive"]

for ext in self.extensions:
print(f"'extra_compile_args' for '{ext.name}' are:")
Expand All @@ -99,7 +131,6 @@ def build_extensions(self):
library_dirs=libsemigroups_info["library_dirs"],
language="c++",
libraries=["semigroups"],
extra_compile_args=["-flax-vector-conversions"],
)
]

Expand Down