3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-22 23:25:51 +00:00

Merge remote-tracking branch 'donn/pyosys_bugfixes' into merge_pybind11

This commit is contained in:
Mohamed Gaber 2025-10-26 02:39:43 +03:00
commit dec28f65ae
No known key found for this signature in database
127 changed files with 4674 additions and 7342 deletions

View file

@ -16,19 +16,19 @@ import os
import re
import shlex
import shutil
from pathlib import Path
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
__dir__ = os.path.dirname(os.path.abspath(__file__))
import pybind11
from pybind11.setup_helpers import build_ext
yosys_version_rx = re.compile(r"PREQORSOR_VERSION\s*:=\s*([\w\-\+\.]+)")
__yosys_root__ = Path(__file__).parent
try:
version = yosys_version_rx.search(
open(os.path.join(__dir__, "../../Makefile"), encoding="utf8").read()
)[1]
except TypeError:
version = open(os.path.join(__dir__, "../../tmpl/version.txt"), encoding="utf8").read().strip()
yosys_version_rx = re.compile(r"YOSYS_VER\s*:=\s*([\w\-\+\.]+)")
with open(__yosys_root__ / "Makefile", encoding="utf8") as f:
# Extract and convert + to patch version
version = yosys_version_rx.search(f.read())[1].replace("+", ".")
class libyosys_so_ext(Extension):
def __init__(
@ -38,7 +38,13 @@ class libyosys_so_ext(Extension):
"libyosys.so",
[],
)
# when iterating locally, you probably want to set this variable
# to avoid mass rebuilds bec of pybind11's include path changing
pybind_include = os.getenv("_FORCE_PYBIND_INCLUDE", pybind11.get_include())
self.args = [
f"PYBIND11_INCLUDE={pybind_include}",
"ENABLE_PYOSYS=1",
# Would need to be installed separately by the user
"ENABLE_TCL=0",
@ -73,24 +79,25 @@ class libyosys_so_ext(Extension):
*self.args,
]
)
build_path = os.path.dirname(os.path.dirname(bext.get_ext_fullpath(self.name)))
pyosys_path = os.path.join(build_path, "pyosys")
ext_fullpath = Path(bext.get_ext_fullpath(self.name))
build_path = ext_fullpath.parents[1]
pyosys_path = build_path / "pyosys"
os.makedirs(pyosys_path, exist_ok=True)
# libyosys.so
target = os.path.join(pyosys_path, os.path.basename(self.name))
target = pyosys_path / self.name
shutil.copy(self.name, target)
# strip prevents proper debug symbols for libpyosys.so
# bext.spawn(["strip", "-S", target])
# yosys-abc
yosys_abc_target = os.path.join(pyosys_path, "yosys-abc")
yosys_abc_target = pyosys_path / "yosys-abc"
shutil.copy("yosys-abc", yosys_abc_target)
bext.spawn(["strip", "-S", yosys_abc_target])
bext.spawn(["strip", "-S", str(yosys_abc_target)])
# share directory
share_target = os.path.join(pyosys_path, "share")
share_target = pyosys_path / "share"
try:
shutil.rmtree(share_target)
except FileNotFoundError:
@ -106,14 +113,16 @@ class custom_build_ext(build_ext):
return ext.custom_build(self)
with open(__yosys_root__ / "README.md", encoding="utf8") as f:
long_description = f.read()
setup(
name="pyosys",
packages=["pyosys"],
version=version,
version=os.getenv("_PYOSYS_OVERRIDE_VER", version),
description="Python access to libyosys",
long_description=open(os.path.join(__dir__, "README.md")).read(),
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=["wheel", "setuptools"],
license="MIT",
classifiers=[
"Programming Language :: Python :: 3",
@ -121,7 +130,6 @@ setup(
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
],
package_dir={"pyosys": "misc"},
python_requires=">=3.8",
ext_modules=[libyosys_so_ext()],
cmdclass={