Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pycheribuild/config/compilation_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def c_preprocessor(self) -> Path:
def linker(self) -> Path:
return self._compiler_dir / "ld.lld"

@property
def objcopy(self) -> Path:
return self._compiler_dir / "objcopy"

@property
def ar(self) -> Path:
return self._compiler_dir / "llvm-ar"
Expand Down Expand Up @@ -1647,7 +1651,7 @@ class CompilationTargets(BasicCompilationTargets):
)
UPSTREAM_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, UpstreamLinuxTargetInfo)
CHERI_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, CheriLinuxTargetInfo)
MORELLO_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, MorelloLinuxTargetInfo)
MORELLO_LINUX_AARCH64 = CrossCompileTarget("legacy-aarch64", CPUArchitecture.AARCH64, MorelloLinuxTargetInfo)
CHERI_LINUX_MORELLO_PURECAP = CrossCompileTarget(
"morello-purecap",
CPUArchitecture.AARCH64,
Expand All @@ -1656,8 +1660,12 @@ class CompilationTargets(BasicCompilationTargets):
check_conflict_with=CHERI_LINUX_AARCH64,
non_cheri_target=CHERI_LINUX_AARCH64,
)
# This target is kept for historical reasons as Morello Linux (from Arm) was the first Linux kernel
# and target that added CHERI support. CHERI-Linux (from CHERI Alliance) has built on top of Morello
# Linux to include more features, targets (RISC-V), and is the currently active project and should
# be used instead of the following target unless there is a good reason not to.
MORELLO_LINUX_MORELLO_PURECAP = CrossCompileTarget(
"morello-purecap",
"legacy-morello-purecap",
CPUArchitecture.AARCH64,
MorelloLinuxTargetInfo,
is_cheri_purecap=True,
Expand Down
113 changes: 113 additions & 0 deletions pycheribuild/projects/cross/cheriportableostests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#
# Copyright (c) 2025-2026 Paul Metzger
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

import os
import typing

from .crosscompileproject import CrossCompileMakefileProject, DefaultInstallDir, GitRepository, MakeCommandKind
from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase
from ...utils import classproperty


class BuildPortableOSTests(CrossCompileMakefileProject):
_always_add_suffixed_targets = True
_needs_sysroot = True
_supported_architectures = (
CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093,
CompilationTargets.CHERI_LINUX_MORELLO_PURECAP,
CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP,
)
_default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093
target = "cheri-portable-os-tests"
build_in_source_dir = False
make_kind = MakeCommandKind.BsdMake
repository = GitRepository("https://github.com/CTSRD-CHERI/portable-cheribsd-test-suite.git")

@classproperty
def default_install_dir(self):
return DefaultInstallDir.ROOTFS_LOCALBASE

@classmethod
def dependencies(cls, config) -> "tuple[str, ...]":
ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls)
return ti.musl_target, "libxo", "libbsd"

def setup(self) -> None:
# Don't depend on libgcc_s
self.COMMON_LDFLAGS.append("--unwindlib=none")

if self.get_crosscompile_target().is_aarch64(include_purecap=True):
self.set_env_make_args(machine_cpuarch="aarch64c", machine_abi="purecap", machine_arch="aarch64c")
elif self.get_crosscompile_target().is_experimental_cheri093_std(self.config):
self.set_env_make_args(
machine_cpuarch="rv64imafdc_zcherihybrid_zcherilevels",
machine_abi="purecap",
machine_arch="rv64imafdc_zcherihybrid_zcherilevels",
)
else:
target = self.target_info.target
raise NotImplementedError(f"Unsupported architecture: {target.cpu_architecture} {target._cheri_isa}")

return super().setup()

def compile(self, **kwargs):
# The binaries will be put into /opt/cheri-api-tests
# This ensures Pyrefly that destdir won't be None
assert self.destdir is not None
self.destdir = self.destdir / "rootfs" / "opt" / "cheri-portable-os-tests"
self.makedirs(self.destdir)

self.make_args.set_env(
# Put the binary into root's home directory
DESTDIR=str(self.destdir),
BINOWN=os.getuid(),
BINGRP=os.getgid(),
BINMODE=755,
# Suppress a warning related to absent exception handlers.
LD_FATAL_WARNINGS="no",
# This is not supported by Morello LLVM,
MAKESYSPATH=str(self.source_dir / "mk"),
MAKEOBJDIRPREFIX=str(self.build_dir),
# This property was added to _ClangBasedTargetInfo to support this specific use case.
OBJCOPY=self.target_info.objcopy,
**self.env_make_args,
)

self.run_make(cwd=self.source_dir / "cheribsdtest")
Comment thread
heshamelmatary marked this conversation as resolved.

def set_env_make_args(self, machine_cpuarch: str, machine_abi: str, machine_arch: str):
self.env_make_args = {
"MACHINE_CPUARCH": machine_cpuarch,
"MACHINE_ABI": machine_abi,
"MACHINE_ARCH": machine_arch,
}

def install(self, **kwargs):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that needed? if it's just make install I guess the CrossCompileMakefileProjector CrossCompileAutotoolsProject parent would do that for you, without you having to define install

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells cheribuild that the makefile is not in the root directory of the repository but in <repo_root>/cheribsdtest. This makefile and the source code will move from <repo_root>/cheribsdtest to the repository's root directory in the future.

self.run_make_install(cwd=self.source_dir / "cheribsdtest")

def process(self):
self.check_required_system_tool("bmake", homebrew="bmake", cheribuild_target="bmake")
super().process()
78 changes: 78 additions & 0 deletions pycheribuild/projects/cross/libbsd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# Copyright (c) 2025-2026 Paul Metzger
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

import typing

from .crosscompileproject import CrossCompileAutotoolsProject, DefaultInstallDir, GitRepository, MakeCommandKind
from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase
from ...utils import classproperty


class BuildLibbsd(CrossCompileAutotoolsProject):
_always_add_suffixed_targets = True
_can_use_autogen_sh = True
_supported_architectures = (
CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093,
CompilationTargets.CHERI_LINUX_MORELLO_PURECAP,
CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP,
)
_default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093
make_kind = MakeCommandKind.GnuMake
repository = GitRepository(
"https://gitlab.freedesktop.org/libbsd/libbsd.git",
temporary_url_override="https://gitlab.freedesktop.org/paul-metzger/libbsd-private-fork-pmetzger.git",
default_branch="0_12_2_with_alignment_macro_fix",
force_branch=True,
)

@classproperty
def default_install_dir(self):
return DefaultInstallDir.ROOTFS_LOCALBASE

@classmethod
def dependencies(cls, config) -> "tuple[str, ...]":
ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls)
return ti.musl_target, "libmd"

def setup(self) -> None:
super().setup()
# Remove dependency on libgcc_eh
self.COMMON_LDFLAGS.append("--unwindlib=none")
# Remove dependcy on libgcc_s
self.COMMON_LDFLAGS.append("-Wc,--unwindlib=none")

def configure(self, **kwargs):
if not self.configure_command.exists():
self.run_cmd(self.source_dir / "autogen", cwd=self.source_dir)
super().configure(**kwargs)

def compile(self, **kwargs):
self.run_make()
super().compile()

def install(self, **kwargs):
self.run_make_install()
super().install(**kwargs)
74 changes: 74 additions & 0 deletions pycheribuild/projects/cross/libmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#
# Copyright (c) 2025-2026 Paul Metzger
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

import typing

from .crosscompileproject import CrossCompileAutotoolsProject, DefaultInstallDir, GitRepository, MakeCommandKind
from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase
from ...utils import classproperty


class BuildLibmd(CrossCompileAutotoolsProject):
_always_add_suffixed_targets = True
_can_use_autogen_sh = True
_supported_architectures = (
CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093,
CompilationTargets.CHERI_LINUX_MORELLO_PURECAP,
CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP,
)
_default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093
make_kind = MakeCommandKind.GnuMake
is_sdk_target = False
repository = GitRepository("https://git.hadrons.org/git/libmd.git")

@classproperty
def default_install_dir(self):
return DefaultInstallDir.ROOTFS_LOCALBASE

@classmethod
def dependencies(cls, config) -> "tuple[str, ...]":
ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls)
return (ti.musl_target,)

def setup(self) -> None:
super().setup()
# Remove dependency on libgcc_eh
self.COMMON_LDFLAGS.append("--unwindlib=none")
# Remove dependcy on libgcc_s
self.COMMON_LDFLAGS.append("-Wc,--unwindlib=none")

def configure(self, **kwargs):
if not self.configure_command.exists():
self.run_cmd(self.source_dir / "autogen", cwd=self.source_dir)
super().configure(**kwargs)

def compile(self, **kwargs):
self.run_make()
super().compile(**kwargs)

def install(self, **kwargs):
self.run_make_install()
super().install(**kwargs)
88 changes: 88 additions & 0 deletions pycheribuild/projects/cross/libxo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Copyright (c) 2025-2026 Paul Metzger
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

import typing

from .crosscompileproject import CrossCompileAutotoolsProject, DefaultInstallDir, GitRepository, MakeCommandKind
from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase
from ...utils import classproperty


class BuildLibxo(CrossCompileAutotoolsProject):
_always_add_suffixed_targets = True
_can_use_autogen_sh = True
_supported_architectures = (
CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093,
CompilationTargets.CHERI_LINUX_MORELLO_PURECAP,
CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP,
)
_default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093
make_kind = MakeCommandKind.GnuMake
repository = GitRepository("https://github.com/Juniper/libxo.git")

@classproperty
def default_install_dir(self):
return DefaultInstallDir.ROOTFS_LOCALBASE

@classmethod
def dependencies(cls, config) -> "tuple[str, ...]":
ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls)
return ti.musl_target, "libbsd", "libmd"

def _patch_to_use_libbsd(self, path):
self.run_cmd("sed", "-i", "s|<sys/queue.h>|<bsd/sys/queue.h>|g", path, cwd=self.source_dir)

def _patch_includes(self) -> None:
self._patch_to_use_libbsd("libxo/xo_encoder.c")
self._patch_to_use_libbsd("xopo/xopo.c")

def _patch_configure_ac(self) -> None:
self.run_cmd("sed", "-i", "s|AC_FUNC_REALLOC|#AC_FUNC_REALLOC|g", "configure.ac", cwd=self.source_dir)
self.run_cmd("sed", "-i", "s|AC_FUNC_MALLOC|#AC_FUNC_MALLOC|g", "configure.ac", cwd=self.source_dir)

def configure(self, **kwargs):
# Don't depend on libgcc_s. If this isn't set then clang wants to link
# with libgcc_s, which is not available on Morello Linux.
self.LDFLAGS.append("--unwindlib=none")
# This prompts libtool to pass '--unwindlib=none' to clang during
# linking. Libtool ignores "--unwindlib=none" and needs
# "-Wc,--unwindlib=none" instead. "-Wc,--unwindlib=none" is turned
# into "--unwindlib=none" by libtool when it invokes clang.
self.CFLAGS.append("-Wc,--unwindlib=none")

self._patch_configure_ac()
self._patch_includes()
self.run_shell_script("sh bin/setup.sh", shell="sh", cwd=self.source_dir)

super().configure(**kwargs)

def compile(self, **kwargs):
self.run_make()
super().compile(**kwargs)

def install(self, **kwargs):
self.run_make_install()
super().install(**kwargs)
2 changes: 1 addition & 1 deletion pycheribuild/projects/cross/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def install(self, **kwargs):

class BuildCheriAllianceLinux(BuildLinux):
target = "linux-kernel"
repository = GitRepository("https://github.com/CHERI-Alliance/linux.git", default_branch="codasip-cheri-riscv-6.18")
repository = GitRepository("https://github.com/CHERI-Alliance/linux.git", default_branch="cambridge-morello-7.0")
_supported_architectures = (
*CompilationTargets.ALL_CHERI_LINUX_TARGETS,
CompilationTargets.LINUX_KERNEL_RISCV64_GCC,
Expand Down
Loading
Loading