3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-05-25 19:36:21 +00:00

Migrate build system to CMake

See #5895 for details.

This commit does not include CI or documentation changes.
This commit is contained in:
Catherine 2026-05-12 05:33:04 +00:00
parent 7bcda9d304
commit 5f1d2297aa
207 changed files with 5257 additions and 2294 deletions

2
pyosys/.gitignore vendored
View file

@ -1,2 +0,0 @@
wrappers.cc
wrappers.inc.cc

29
pyosys/CMakeLists.txt Normal file
View file

@ -0,0 +1,29 @@
add_custom_command(
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/generator.py
${CMAKE_CURRENT_SOURCE_DIR}/wrappers_tpl.cc
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/wrappers.cc
${CMAKE_CURRENT_BINARY_DIR}/wrappers.inc.cc
DEPFILE
${CMAKE_CURRENT_BINARY_DIR}/wrappers.cc.d
COMMAND
${CMAKE_COMMAND} -E env
CCACHE=${CMAKE_CXX_COMPILER_LAUNCHER}
CXX=${CMAKE_CXX_COMPILER}
CXX_STD=c++${CMAKE_CXX_STANDARD}
-- ${PyosysEnv_PYTHON}
${CMAKE_CURRENT_SOURCE_DIR}/generator.py
${CMAKE_CURRENT_BINARY_DIR}/wrappers.cc
--build-dir ${CMAKE_BINARY_DIR}
VERBATIM
COMMENT "Generating Python wrappers"
)
yosys_core(pyosys
wrappers.cc
INCLUDE_DIRS
${pybind11_INCLUDE_DIR}
LIBRARIES
$<${YOSYS_ENABLE_PYTHON}:Python3::Python>
ESSENTIAL
)

View file

@ -130,6 +130,8 @@ global_denylist = frozenset(
## function pointers
"log_error_atexit",
"log_verific_callback",
# incomplete type
"yosys_get_tcl_interp",
}
)
pyosys_headers = [
@ -322,9 +324,9 @@ class PyosysWrapperGenerator(object):
self.class_registry: Dict[str, Tuple[ClassScope, PyosysClass]] = {}
# entry point
def generate(self):
def generate(self, build_dir):
tpl = __file_dir__ / "wrappers_tpl.cc"
preprocessor_opts = self.make_preprocessor_options()
preprocessor_opts = self.make_preprocessor_options(build_dir)
with open(tpl, encoding="utf8") as f:
do_line_directive = True
for i, line in enumerate(f):
@ -373,15 +375,19 @@ class PyosysWrapperGenerator(object):
print(f"}}", file=self.f_inc)
# helpers
def make_preprocessor_options(self):
def make_preprocessor_options(self, build_dir):
py_include = get_paths()["include"]
preprocessor_bin = shutil.which("clang++") or "g++"
cxx_bin = os.getenv("CXX") or shutil.which("clang++") or "c++"
if ccache := os.getenv("CCACHE"):
compiler = [ccache, cxx_bin]
else:
compiler = [cxx_bin]
cxx_std = os.getenv("CXX_STD", "c++20")
return ParserOptions(
preprocessor=make_gcc_preprocessor(
defines=["_YOSYS_", "YOSYS_ENABLE_PYTHON"],
gcc_args=[preprocessor_bin, "-fsyntax-only", f"-std={cxx_std}"],
include_paths=[str(__yosys_root__), py_include, pybind11.get_include()],
gcc_args=[*compiler, f"-std={cxx_std}", "-fsyntax-only"],
include_paths=[str(__yosys_root__), py_include, pybind11.get_include(), build_dir],
),
)
@ -819,28 +825,23 @@ keyword_aliases = {
}
def print_includes():
for header in pyosys_headers:
print(header.name)
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("--debug", default=0, type=int)
ap.add_argument("--build-dir", default=".", type=str)
group = ap.add_mutually_exclusive_group(required=True)
group.add_argument("--print-includes", action="store_true")
group.add_argument("output", nargs="?")
ns = ap.parse_args()
if ns.print_includes:
print_includes()
exit(0)
build_dir = Path(ns.build_dir)
out_path = Path(ns.output)
out_inc = out_path.parent / (out_path.stem + ".inc.cc")
with open(out_path, "w", encoding="utf8") as f, open(
out_inc, "w", encoding="utf8"
) as inc_f:
out_dep = out_path.parent / (out_path.name + ".d")
with (open(out_path, "w", encoding="utf8") as f,
open(out_inc, "w", encoding="utf8") as inc_f,
open(out_dep, "w", encoding="utf8") as dep_f):
generator = PyosysWrapperGenerator(
from_headers=pyosys_headers, wrapper_stream=f, header_stream=inc_f
)
generator.generate()
generator.generate(ns.build_dir)
for header in pyosys_headers:
print(f"{out_path} {out_inc}: {__yosys_root__ / header.name}", file=dep_f)

View file

@ -16,8 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef YOSYS_ENABLE_PYTHON
// <!-- generated includes -->
#include <pybind11/pybind11.h>
#include <pybind11/native_enum.h>
@ -259,5 +257,3 @@ namespace pyosys {
py::implicitly_convertible<const char *, RTLIL::IdString>();
};
};
#endif // YOSYS_ENABLE_PYTHON