From 2b38a2385c5e154bbd7c247fe74f5c83e4c522e5 Mon Sep 17 00:00:00 2001 From: Mohamed Gaber Date: Sat, 18 Oct 2025 14:58:56 +0300 Subject: [PATCH] pyosys: tox for non-wheel builds, update instructions - add `tox` to list of dependencies: saves builder(s) from manually having to manage a venv for python build dependencies - when building wheels, pip automatically creates the environment with those dependencies, so no need for tox - when running simply `make ENABLE_PYOSYS=1`, this is not the case. people attempting to `pip3 install --upgrade pybind11 cxxheaderparser` to add it to their system packages will be met with a scare message about "breaking system packages" - tox is available from all major package managers all the way back to ubuntu 20.04 and resolves this issue - update installation instructions to drop boost and add tox instead - update ci scripts to use `macos-15[-intel]` (`macos-13` sunset in early december) --- .github/actions/setup-build-env/action.yml | 2 +- .github/workflows/test-compile.yml | 2 +- .github/workflows/wheels.yml | 4 ++-- .gitignore | 1 + Brewfile | 2 +- Makefile | 13 ++++++++++--- README.md | 3 +-- docs/source/getting_started/installation.rst | 9 ++++----- docs/source/using_yosys/pyosys.rst | 8 ++++++++ tox.ini | 9 +++++++++ 10 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 tox.ini diff --git a/.github/actions/setup-build-env/action.yml b/.github/actions/setup-build-env/action.yml index e4bc8ec58..6324ef7cc 100644 --- a/.github/actions/setup-build-env/action.yml +++ b/.github/actions/setup-build-env/action.yml @@ -8,7 +8,7 @@ runs: shell: bash run: | sudo apt-get update - sudo apt-get install gperf build-essential bison flex libfl-dev libreadline-dev gawk tcl-dev libffi-dev git graphviz xdot pkg-config python3 libboost-system-dev libboost-python-dev libboost-filesystem-dev zlib1g-dev libbz2-dev libgtest-dev + sudo apt-get install gperf build-essential bison flex libfl-dev libreadline-dev gawk tcl-dev libffi-dev git graphviz xdot pkg-config python3-dev tox zlib1g-dev libbz2-dev libgtest-dev - name: Install macOS Dependencies if: runner.os == 'macOS' diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index 7c18c7ba0..1604ca9d2 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -45,7 +45,7 @@ jobs: - 'gcc-14' include: # macOS x86 - - os: macos-13 + - os: macos-15-intel compiler: 'clang-19' # macOS arm - os: macos-latest diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index b6c9a51ac..9eea1468d 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -27,13 +27,13 @@ jobs: { name: "macOS 13", family: "macos", - runner: "macos-13", + runner: "macos-15-intel", archs: "x86_64", }, { name: "macOS 14", family: "macos", - runner: "macos-14", + runner: "macos-15", archs: "arm64", }, ## Windows is disabled because of an issue with compiling FFI as diff --git a/.gitignore b/.gitignore index 2367bccb3..f1f67fb15 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ /venv /*.whl /*.egg-info +/.tox # yosysjs dependency /viz.js diff --git a/Brewfile b/Brewfile index c90434e62..75e2524c2 100644 --- a/Brewfile +++ b/Brewfile @@ -6,9 +6,9 @@ brew "git" brew "graphviz" brew "pkg-config" brew "python3" +brew "tox" brew "xdot" brew "bash" -brew "boost-python3" brew "llvm@20" brew "lld" brew "googletest" diff --git a/Makefile b/Makefile index 9252e1e7a..ed129f734 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ ENABLE_HELP_SOURCE := 0 # python wrappers ENABLE_PYOSYS := 0 +PYOSYS_USE_TOX := 1 # other configuration flags ENABLE_GCOV := 0 @@ -352,16 +353,22 @@ PYTHON_OBJECTS = pyosys/wrappers.o kernel/drivers.o kernel/yosys.o passes/cmds/p ifeq ($(ENABLE_PYOSYS),1) # python-config --ldflags includes -l and -L, but LINKFLAGS is only -L + +TOX_ENV := +ifeq ($(PYOSYS_USE_TOX),1) +TOX_ENV := tox -qq -e build -- +endif + LINKFLAGS += $(filter-out -l%,$(shell $(PYTHON_CONFIG) --ldflags)) LIBS += $(shell $(PYTHON_CONFIG) --libs) EXE_LIBS += $(filter-out $(LIBS),$(shell $(PYTHON_CONFIG_FOR_EXE) --libs)) -PYBIND11_INCLUDE ?= $(shell $(PYTHON_EXECUTABLE) -m pybind11 --includes) +PYBIND11_INCLUDE ?= $(shell $(TOX_ENV) $(PYTHON_EXECUTABLE) -m pybind11 --includes) CXXFLAGS += -I$(PYBIND11_INCLUDE) -DYOSYS_ENABLE_PYTHON CXXFLAGS += $(shell $(PYTHON_CONFIG) --includes) -DYOSYS_ENABLE_PYTHON OBJS += $(PY_WRAPPER_FILE).o PY_GEN_SCRIPT = pyosys/generator.py -PY_WRAP_INCLUDES := $(shell $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) --print-includes) +PY_WRAP_INCLUDES := $(shell $(TOX_ENV) $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) --print-includes) endif # ENABLE_PYOSYS ifeq ($(ENABLE_READLINE),1) @@ -777,7 +784,7 @@ endif ifeq ($(ENABLE_PYOSYS),1) $(PY_WRAPPER_FILE).cc: $(PY_GEN_SCRIPT) pyosys/wrappers_tpl.cc $(PY_WRAP_INCLUDES) pyosys/hashlib.h $(Q) mkdir -p $(dir $@) - $(P) $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) $(PY_WRAPPER_FILE).cc + $(P) $(TOX_ENV) $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) $(PY_WRAPPER_FILE).cc endif %.o: %.cpp diff --git a/README.md b/README.md index 6118d6079..b89cc2825 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,7 @@ prerequisites for building yosys: $ sudo apt-get install build-essential clang lld bison flex libfl-dev \ libreadline-dev gawk tcl-dev libffi-dev git \ - graphviz xdot pkg-config python3 libboost-system-dev \ - libboost-python-dev libboost-filesystem-dev zlib1g-dev + graphviz xdot pkg-config python3-dev tox zlib1g-dev The environment variable `CXX` can be used to control the C++ compiler used, or run one of the following to override it: diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index 0ac85d199..7195e4fc5 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -99,8 +99,7 @@ Installing all prerequisites for Ubuntu 22.04: sudo apt-get install gperf build-essential clang lld bison flex libfl-dev \ libreadline-dev gawk tcl-dev libffi-dev git \ - graphviz xdot pkg-config python3 libboost-system-dev \ - libboost-python-dev libboost-filesystem-dev zlib1g-dev + graphviz xdot pkg-config python3-dev tox zlib1g-dev Installing all prerequisites for macOS 13 (with Homebrew): @@ -141,7 +140,7 @@ For Cygwin use the following command to install all prerequisites, or select the missing `strdup` function when using gcc. It is instead recommended to use Windows Subsystem for Linux (WSL) and follow the instructions for Ubuntu. -.. +.. For MSYS2 (MINGW64): .. code:: console @@ -215,7 +214,7 @@ Running the build system From the root ``yosys`` directory, call the following commands: .. code:: console - + make sudo make install @@ -228,7 +227,7 @@ To use a separate (out-of-tree) build directory, provide a path to the Makefile. Out-of-tree builds require a clean source tree. -.. seealso:: +.. seealso:: Refer to :doc:`/yosys_internals/extending_yosys/test_suites` for details on testing Yosys once compiled. diff --git a/docs/source/using_yosys/pyosys.rst b/docs/source/using_yosys/pyosys.rst index 8aa7fd4fe..05d5f7953 100644 --- a/docs/source/using_yosys/pyosys.rst +++ b/docs/source/using_yosys/pyosys.rst @@ -28,6 +28,14 @@ methods: ``yosys -y ./my_pyosys_script.py`` + Do note this requires some build-time dependencies to be available to Python, + namely, ``pybind11`` and ``cxxheaderparser``. By default, the required + ``tox`` package will be used to create an ephemeral environment with the + correct versions of the tools installed. + + You can force use of your current Python environment by passing the Makefile + flag ``PYOSYS_USE_TOX=0``. + 2. Installing the Pyosys wheels On macOS and GNU/Linux you can install pre-built wheels of Yosys using diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..4307a98b3 --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = build + +[testenv:build] +skip_install = true +deps = + pybind11>=3,<4 + cxxheaderparser +commands = {posargs}