Skip to content

Commit 085f75f

Browse files
committed
cheribsd: Overhaul freebsd-univere and add cheribsd-universe
These are a bit awkward since we need the notion of a FreeBSD/CheriBSD target without a specific CPU, and these are targets that the base classes do not themselves support. Also split tinderbox into separate targets as, whilst universe is the base Makefile target, tinderbox is its own first-class thing, and it's more natural to be able to run cheribuild cheribsd-tinderbox.
1 parent 5d8d310 commit 085f75f

6 files changed

Lines changed: 175 additions & 100 deletions

File tree

pycheribuild/config/compilation_targets.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def _get_sdk_root_dir_lazy(self) -> Path:
408408
xtarget = self.target.get_rootfs_target()
409409
# We don't want to call setup() yet on the FreeBSD instance (not needed to get the compiler)
410410
# noinspection PyProtectedMember
411-
fbsd = self._get_rootfs_class(xtarget)._get_instance_no_setup(self.project, cross_target=xtarget)
411+
fbsd = self._get_sdk_root_class(xtarget)._get_instance_no_setup(self.project, cross_target=xtarget)
412412
configured_path = fbsd.build_toolchain_root_dir # pytype: disable=attribute-error
413413
if configured_path is None:
414414
# If we couldn't find a working system compiler, default to cheribuild-compiled upstream LLVM.
@@ -439,6 +439,7 @@ def is_freebsd(cls) -> bool:
439439

440440
@classmethod
441441
def triple_for_target(cls, target: "CrossCompileTarget", config: "CheriConfig", *, include_version: bool):
442+
assert not target.is_nocpu()
442443
common_suffix = "-unknown-freebsd"
443444
if include_version:
444445
common_suffix += str(cls.FREEBSD_VERSION)
@@ -514,6 +515,11 @@ def localbase(self) -> Path:
514515
def _get_rootfs_class(self, xtarget: "CrossCompileTarget") -> "type[SimpleProject]":
515516
return SimpleProject.get_class_for_target_name("freebsd", xtarget)
516517

518+
def _get_sdk_root_class(self, xtarget: "CrossCompileTarget") -> "type[SimpleProject]":
519+
if xtarget.is_nocpu():
520+
return SimpleProject.get_class_for_target_name("freebsd-universe", xtarget)
521+
return self._get_rootfs_class(xtarget)
522+
517523
def _get_run_project(self, xtarget: "CrossCompileTarget", caller: AbstractProject) -> LaunchFreeBSDInterface:
518524
result = SimpleProject.get_instance_for_target_name("run-freebsd", xtarget, caller.config, caller)
519525
return typing.cast(LaunchFreeBSDInterface, result)
@@ -758,6 +764,11 @@ def pkgconfig_dirs(self) -> "list[str]":
758764
def _get_rootfs_class(self, xtarget: "CrossCompileTarget") -> "type[SimpleProject]":
759765
return SimpleProject.get_class_for_target_name("cheribsd", xtarget)
760766

767+
def _get_sdk_root_class(self, xtarget: "CrossCompileTarget") -> "type[SimpleProject]":
768+
if xtarget.is_nocpu():
769+
return SimpleProject.get_class_for_target_name("cheribsd-universe", xtarget)
770+
return self._get_rootfs_class(xtarget)
771+
761772
def cheribsd_version(self) -> "Optional[int]":
762773
return sys_param_h_cheribsd_version(self.sysroot_dir)
763774

@@ -1769,6 +1780,10 @@ class CompilationTargets(BasicCompilationTargets):
17691780
ALL_SUPPORTED_CHERIBSD_AND_HOST_TARGETS + ALL_SUPPORTED_BAREMETAL_TARGETS
17701781
)
17711782

1783+
# Special targets for use in freebsd/cheribsd-universe
1784+
CHERIBSD_NOCPU = CrossCompileTarget("nocpu", CPUArchitecture.NOCPU, CheriBSDTargetInfo)
1785+
FREEBSD_NOCPU = CrossCompileTarget("nocpu", CPUArchitecture.NOCPU, FreeBSDTargetInfo)
1786+
17721787
@staticmethod
17731788
def _dump_cheribsd_target_relations() -> None:
17741789
for target in (

pycheribuild/config/target_info.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class CPUArchitecture(Enum):
6767
RISCV32 = "riscv32"
6868
RISCV64 = "riscv64"
6969
X86_64 = "x86_64"
70+
NOCPU = "nocpu"
7071

7172
def word_bits(self) -> int:
7273
mapping = {
@@ -87,6 +88,7 @@ def is_64bit(self) -> bool:
8788
return self.word_bits() == 64
8889

8990
def as_meson_cpu_family(self) -> str:
91+
assert self is not CPUArchitecture.NOCPU
9092
# https://mesonbuild.com/Reference-tables.html#cpu-families
9193
if self is CPUArchitecture.I386:
9294
return "x86"
@@ -96,6 +98,7 @@ def as_meson_cpu_family(self) -> str:
9698
return str(self.value)
9799

98100
def endianess(self) -> str:
101+
assert self is not CPUArchitecture.NOCPU
99102
# Meson expects us to pass this manually... Why not query the compiler???
100103
if self is CPUArchitecture.MIPS64:
101104
return "big"
@@ -1050,6 +1053,9 @@ def _check_arch(self, arch: CPUArchitecture, include_purecap: "Optional[bool]")
10501053
return True
10511054

10521055
# Querying the CPU architecture:
1056+
def is_nocpu(self, include_purecap: Optional[bool] = None) -> bool:
1057+
return self._check_arch(CPUArchitecture.NOCPU, include_purecap)
1058+
10531059
def is_mips(self, include_purecap: Optional[bool] = None) -> bool:
10541060
return self._check_arch(CPUArchitecture.MIPS64, include_purecap)
10551061

0 commit comments

Comments
 (0)