mirror of
https://github.com/YosysHQ/yosys
synced 2026-06-06 00:50:57 +00:00
Update top-level Python project for CMake compatibility.
This commit reimplements the (no longer recommended) setuptools based build system using a standards-based in-tree PEP517 build backend. The implementation is partially based on https://codeberg.org/ziglang/zig-pypi/src/branch/main/make_wheels.py which is licensed under BSD-0-clause. It also adds a new option `YOSYS_BUILD_PYTHON_ONLY` that is available only if the binary or the library aren't going to be installed, which turns off these targets entirely, as well as some dependent ones (e.g. tests). Co-authored-by: Mohamed Gaber <me@donn.website>
This commit is contained in:
parent
780588f28c
commit
afc0e78d11
15 changed files with 321 additions and 294 deletions
|
|
@ -4,8 +4,10 @@
|
|||
# whether the host interpreter has the necessary dependencies first, and if it
|
||||
# does not, fall back to using `uv`.
|
||||
|
||||
foreach (strategy host uv fail)
|
||||
if (strategy STREQUAL "host")
|
||||
foreach (strategy virtualenv host uv fail)
|
||||
if (strategy STREQUAL "virtualenv")
|
||||
set(PyosysEnv_PYTHON $ENV{VIRTUAL_ENV}/bin/python)
|
||||
elseif (strategy STREQUAL "host")
|
||||
set(PyosysEnv_PYTHON ${Python3_EXECUTABLE})
|
||||
elseif (strategy STREQUAL "uv")
|
||||
set(PyosysEnv_PYTHON uv run --no-project --with pybind11>3,<4 --with cxxheaderparser python)
|
||||
|
|
|
|||
|
|
@ -6,10 +6,22 @@ get_property(packages_found GLOBAL PROPERTY PACKAGES_FOUND)
|
|||
get_property(packages_not_found GLOBAL PROPERTY PACKAGES_NOT_FOUND)
|
||||
get_property(required_version GLOBAL PROPERTY _CMAKE_Python3_REQUIRED_VERSION)
|
||||
|
||||
# A hack to make pyosys buildable in wheel-only environments.
|
||||
# `Interpreter` is a part of the component set to ensure that a Python implementation without
|
||||
# an interpreter that's earlier in the search order won't be selected instead of the desired one.
|
||||
# (This is awful and should be removed once CMake 4.0 is here.)
|
||||
if (YOSYS_BUILD_PYTHON_ONLY)
|
||||
set(components Interpreter Development.Module)
|
||||
else()
|
||||
set(components Interpreter Development)
|
||||
endif()
|
||||
|
||||
# The `EXACT` specifier prevents the situation of `FindPython3` discovering a newer libpython-dev
|
||||
# than the interpreter found in the past, rejecting it because it is too new, and giving up.
|
||||
find_package(Python3 EXACT ${Python3_VERSION} COMPONENTS Development.Embed)
|
||||
set(Python3Embed_FOUND ${Python3_Development.Embed_FOUND})
|
||||
find_package(Python3 EXACT ${Python3_VERSION} COMPONENTS ${components})
|
||||
if (Python3_Development.Embed_FOUND OR Python3_Development.Module_FOUND)
|
||||
set(Python3Devel_FOUND YES)
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY PACKAGES_FOUND "${packages_found}")
|
||||
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND "${packages_not_found}")
|
||||
14
cmake/GetPyosysVersion.cmake
Normal file
14
cmake/GetPyosysVersion.cmake
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.27)
|
||||
set(CMAKE_MESSAGE_LOG_LEVEL ERROR)
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
include(YosysVersion)
|
||||
|
||||
yosys_extract_version()
|
||||
if (YOSYS_VERSION_COMMIT EQUAL "0")
|
||||
set(yosys_version "${YOSYS_VERSION_MAJOR}.${YOSYS_VERSION_MINOR}")
|
||||
elseif (YOSYS_VERSION_COMMIT STREQUAL "")
|
||||
set(yosys_version "${YOSYS_VERSION_MAJOR}.${YOSYS_VERSION_MINOR}.post9999")
|
||||
else()
|
||||
set(yosys_version "${YOSYS_VERSION_MAJOR}.${YOSYS_VERSION_MINOR}.post${YOSYS_VERSION_COMMIT}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${yosys_version}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue