mirror of
https://git.sr.ht/~kivikakk/niar
synced 2024-12-23 04:12:24 +00:00
support zig builds.
This commit is contained in:
parent
071f1cef41
commit
a4b04502b6
|
@ -1,5 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
@ -31,13 +33,19 @@ CXXFLAGS = [
|
||||||
class _Optimize(Enum):
|
class _Optimize(Enum):
|
||||||
none = "none"
|
none = "none"
|
||||||
rtl = "rtl"
|
rtl = "rtl"
|
||||||
|
app = "app"
|
||||||
|
both = "both"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def opt_rtl(self) -> bool:
|
def opt_rtl(self) -> bool:
|
||||||
return self in (self.rtl,)
|
return self in (self.rtl, self.both)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def opt_app(self) -> bool:
|
||||||
|
return self in (self.app, self.both)
|
||||||
|
|
||||||
|
|
||||||
def add_arguments(np: Project, parser):
|
def add_arguments(np: Project, parser):
|
||||||
|
@ -86,6 +94,8 @@ def add_arguments(np: Project, parser):
|
||||||
def main(np: Project, args):
|
def main(np: Project, args):
|
||||||
yosys = find_yosys(lambda ver: ver >= (0, 10))
|
yosys = find_yosys(lambda ver: ver >= (0, 10))
|
||||||
|
|
||||||
|
os.makedirs(np.path.build(), exist_ok=True)
|
||||||
|
|
||||||
platform = np.cxxrtl_target_by_name(args.target)
|
platform = np.cxxrtl_target_by_name(args.target)
|
||||||
design = construct_top(np, platform)
|
design = construct_top(np, platform)
|
||||||
|
|
||||||
|
@ -113,6 +123,11 @@ def main(np: Project, args):
|
||||||
*(["-O3"] if args.optimize.opt_rtl else ["-O0"]),
|
*(["-O3"] if args.optimize.opt_rtl else ["-O0"]),
|
||||||
*(["-g"] if args.debug else []),
|
*(["-g"] if args.debug else []),
|
||||||
]
|
]
|
||||||
|
if platform.uses_zig:
|
||||||
|
cxxflags += [
|
||||||
|
"-DCXXRTL_INCLUDE_CAPI_IMPL",
|
||||||
|
"-DCXXRTL_INCLUDE_VCD_CAPI_IMPL",
|
||||||
|
]
|
||||||
|
|
||||||
procs = []
|
procs = []
|
||||||
compile_commands = {}
|
compile_commands = {}
|
||||||
|
@ -128,6 +143,8 @@ def main(np: Project, args):
|
||||||
"-o",
|
"-o",
|
||||||
str(o_path),
|
str(o_path),
|
||||||
]
|
]
|
||||||
|
if platform.uses_zig:
|
||||||
|
cmd = ["zig"] + cmd
|
||||||
compile_commands[o_path] = cmd
|
compile_commands[o_path] = cmd
|
||||||
logger.debug(" ".join(str(e) for e in cmd))
|
logger.debug(" ".join(str(e) for e in cmd))
|
||||||
procs.append((cc_path, subprocess.Popen(cmd)))
|
procs.append((cc_path, subprocess.Popen(cmd)))
|
||||||
|
@ -157,6 +174,24 @@ def main(np: Project, args):
|
||||||
raise RuntimeError("failed compile step")
|
raise RuntimeError("failed compile step")
|
||||||
|
|
||||||
exe_o_path = np.path.build("cxxrtl")
|
exe_o_path = np.path.build("cxxrtl")
|
||||||
|
if platform.uses_zig:
|
||||||
|
# Zig really wants relative paths.
|
||||||
|
joined_o_paths = ",".join(
|
||||||
|
f"../{p.relative_to(np.path())}" for p in cc_o_paths.values()
|
||||||
|
)
|
||||||
|
cmd = [
|
||||||
|
"zig",
|
||||||
|
"build",
|
||||||
|
f"-Dclock_hz={int(platform.default_clk_frequency)}",
|
||||||
|
f"-Dyosys_data_dir={yosys.data_dir()}",
|
||||||
|
f"-Dcxxrtl_o_paths={joined_o_paths}",
|
||||||
|
]
|
||||||
|
if args.optimize.opt_app:
|
||||||
|
cmd += ["-Doptimize=ReleaseFast"]
|
||||||
|
logger.debug(" ".join(str(e) for e in cmd))
|
||||||
|
subprocess.run(cmd, cwd="cxxrtl", check=True)
|
||||||
|
shutil.copy("cxxrtl/zig-out/bin/cxxrtl", exe_o_path)
|
||||||
|
else:
|
||||||
cmd = [
|
cmd = [
|
||||||
"c++",
|
"c++",
|
||||||
*cxxflags,
|
*cxxflags,
|
||||||
|
|
|
@ -5,3 +5,4 @@ __all__ = ["CxxrtlPlatform"]
|
||||||
|
|
||||||
class CxxrtlPlatform(metaclass=ABCMeta):
|
class CxxrtlPlatform(metaclass=ABCMeta):
|
||||||
default_clk_frequency = property(abstractmethod(lambda _: None))
|
default_clk_frequency = property(abstractmethod(lambda _: None))
|
||||||
|
uses_zig = False
|
||||||
|
|
Loading…
Reference in a new issue