From b36736d36c7fe96122af1dd5f65d0939697d0d9b Mon Sep 17 00:00:00 2001 From: Alfredo Mazzinghi Date: Fri, 25 Jul 2025 12:36:11 +0100 Subject: [PATCH] grpc: Add targets necessary to cross build grpc and the qps benchmark. This introduces the following targets for both morello and riscv64: - abseil - c-ares - googlebenchmakr - googletest - grpc - protobuf - re2 --- pycheribuild/projects/cross/abseil.py | 51 ++++++++ pycheribuild/projects/cross/c_ares.py | 47 ++++++++ pycheribuild/projects/cross/googlebench.py | 55 +++++++++ pycheribuild/projects/cross/grpc.py | 129 +++++++++++++++++++++ pycheribuild/projects/cross/protobuf.py | 51 ++++++++ pycheribuild/projects/cross/re2.py | 47 ++++++++ 6 files changed, 380 insertions(+) create mode 100644 pycheribuild/projects/cross/abseil.py create mode 100644 pycheribuild/projects/cross/c_ares.py create mode 100644 pycheribuild/projects/cross/googlebench.py create mode 100644 pycheribuild/projects/cross/grpc.py create mode 100644 pycheribuild/projects/cross/protobuf.py create mode 100644 pycheribuild/projects/cross/re2.py diff --git a/pycheribuild/projects/cross/abseil.py b/pycheribuild/projects/cross/abseil.py new file mode 100644 index 000000000..99e17d73c --- /dev/null +++ b/pycheribuild/projects/cross/abseil.py @@ -0,0 +1,51 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Alfredo Mazzinghi +# +# This software was developed by SRI International, the University of +# Cambridge Computer Laboratory (Department of Computer Science and +# Technology), and Capabilities Limited under Defense Advanced Research +# Projects Agency (DARPA) Contract No. FA8750-24-C-B047 ("DEC"). +# +# 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. +# +from .crosscompileproject import BuildType, CrossCompileCMakeProject, GitRepository +from ...config.compilation_targets import CompilationTargets +from ...config.target_info import DefaultInstallDir + + +class BuildAbseil(CrossCompileCMakeProject): + target = "abseil" + repository = GitRepository("https://github.com/CTSRD-CHERI/abseil-cpp.git", default_branch="cheri-20220623.0") + is_large_source_repository = True + default_build_type = BuildType.DEBUG + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) + + def setup(self): + super().setup() + self.add_cmake_options( + CMAKE_CXX_STANDARD=17, + BUILD_SHARED_LIBS="ON", + ) + self.cross_warning_flags.append("-Wno-error=cheri-capability-misuse") diff --git a/pycheribuild/projects/cross/c_ares.py b/pycheribuild/projects/cross/c_ares.py new file mode 100644 index 000000000..af5f1c30c --- /dev/null +++ b/pycheribuild/projects/cross/c_ares.py @@ -0,0 +1,47 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Alfredo Mazzinghi +# +# This software was developed by SRI International, the University of +# Cambridge Computer Laboratory (Department of Computer Science and +# Technology), and Capabilities Limited under Defense Advanced Research +# Projects Agency (DARPA) Contract No. FA8750-24-C-B047 ("DEC"). +# +# 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. +# +from .crosscompileproject import BuildType, CrossCompileCMakeProject, GitRepository +from ...config.compilation_targets import CompilationTargets +from ...config.target_info import DefaultInstallDir + + +class BuildCAres(CrossCompileCMakeProject): + target = "c-ares" + repository = GitRepository("https://github.com/c-ares/c-ares.git", default_branch="cares-1_19_1") + is_large_source_repository = True + default_build_type = BuildType.DEBUG + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) + + def setup(self): + super().setup() + self.add_cmake_options(CARES_BUILD_TESTS="OFF") diff --git a/pycheribuild/projects/cross/googlebench.py b/pycheribuild/projects/cross/googlebench.py new file mode 100644 index 000000000..fb2947f9d --- /dev/null +++ b/pycheribuild/projects/cross/googlebench.py @@ -0,0 +1,55 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Alfredo Mazzinghi +# +# This software was developed by SRI International, the University of +# Cambridge Computer Laboratory (Department of Computer Science and +# Technology), and Capabilities Limited under Defense Advanced Research +# Projects Agency (DARPA) Contract No. FA8750-24-C-B047 ("DEC"). +# +# 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. +# +from .crosscompileproject import BuildType, CrossCompileCMakeProject, GitRepository +from ...config.compilation_targets import CompilationTargets +from ...config.target_info import DefaultInstallDir + + +class BuildGoogleBenchmark(CrossCompileCMakeProject): + target = "googlebenchmark" + repository = GitRepository("https://github.com/google/benchmark", default_branch="v1.8.2") + dependencies = ("googletest",) + default_build_type = BuildType.RELWITHDEBINFO + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) + + def setup(self): + super().setup() + self.add_cmake_options(BENCHMARK_ENABLE_TESTING="OFF") + + +class BuildGoogleTest(CrossCompileCMakeProject): + target = "googletest" + repository = GitRepository("https://github.com/google/googletest", default_branch="v1.13.0") + default_build_type = BuildType.RELWITHDEBINFO + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) diff --git a/pycheribuild/projects/cross/grpc.py b/pycheribuild/projects/cross/grpc.py new file mode 100644 index 000000000..604daf886 --- /dev/null +++ b/pycheribuild/projects/cross/grpc.py @@ -0,0 +1,129 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Alfredo Mazzinghi +# +# This software was developed by SRI International, the University of +# Cambridge Computer Laboratory (Department of Computer Science and +# Technology), and Capabilities Limited under Defense Advanced Research +# Projects Agency (DARPA) Contract No. FA8750-24-C-B047 ("DEC"). +# +# 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. +# + +from .crosscompileproject import BuildType, CrossCompileCMakeProject, GitRepository +from ...config.compilation_targets import CompilationTargets +from ...config.target_info import DefaultInstallDir + + +class BuildGrpc(CrossCompileCMakeProject): + target = "grpc" + repository = GitRepository("https://github.com/CTSRD-CHERI/grpc.git", default_branch="grpc-1.54.2-cheri") + dependencies = ("abseil", "c-ares", "protobuf", "re2", "googlebenchmark") + is_large_source_repository = True + default_build_type = BuildType.RELWITHDEBINFO + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) + + @property + def cmake_prefix_paths(self): + # Force CMAKE_PREFIX_PATH to be empty + # This should be fine, because we are still setting the + # CMAKE_SYSROOT correctly and setting + # CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER + # So the find_package() calls should pick up sysroot packages + # while find_program() will find thigs in $PATH or CMAKE_PROGRAM_PATH. + if self.compiling_for_host(): + return super().cmake_prefix_paths + else: + return [] + + def setup(self): + super().setup() + self.add_cmake_options( + CMAKE_CXX_STANDARD=17, + gRPC_ABSL_PROVIDER="package", + gRPC_BENCHMARK_PROVIDER="package", + gRPC_CARES_PROVIDER="package", + gRPC_PROTOBUF_PROVIDER="package", + gRPC_RE2_PROVIDER="package", + gRPC_SSL_PROVIDER="package", + gRPC_ZLIB_PROVIDER="package", + gRPC_BACKWARDS_COMPATIBILITY_MODE="OFF", + gRPC_BUILD_CODEGEN="ON", + gRPC_BUILD_GRPC_CPP_PLUGIN="ON", + BUILD_SHARED_LIBS="ON", + CMAKE_PROGRAM_PATH=self.config.cheri_sdk_bindir, + ) + + if not self.compiling_for_host(): + self.add_cmake_options(gRPC_BUILD_TESTS="ON") + self.cross_warning_flags.append("-Wno-error=cheri-capability-misuse") + self.cross_warning_flags.append("-Wno-error=format") + + def install(self, **kwargs): + super().install(**kwargs) + + if self.target_info.is_native(): + return + + scenario_dir = self.install_dir / "qps_scenarios" + self.makedirs(scenario_dir) + self.run_cmd( + "python", + f"{self.source_dir}/tools/run_tests/performance/scenario_config_exporter.py", + "--export_scenarios", + "-l", + "c++", + "--category=all", + cwd=scenario_dir, + ) + + # Install the QPS benchmark components + self.install_file(self.build_dir / "qps_worker", self.install_dir / "grpc_qps_worker") + self.install_file(self.build_dir / "qps_json_driver", self.install_dir / "grpc_qps_json_driver") + + qps_utils_dir = self.install_dir / "qps_utils" + self.makedirs(qps_utils_dir) + self.makedirs(qps_utils_dir / "python_utils") + self.install_file( + self.source_dir / "tools" / "run_tests" / "start_port_server.py", qps_utils_dir / "start_port_server.py" + ) + self.install_file( + self.source_dir / "tools" / "run_tests" / "python_utils" / "port_server.py", + qps_utils_dir / "python_utils" / "port_server.py", + ) + self.install_file( + self.source_dir / "tools" / "run_tests" / "python_utils" / "start_port_server.py", + qps_utils_dir / "python_utils" / "start_port_server.py", + ) + self.install_file( + self.source_dir / "tools" / "run_tests" / "python_utils" / "jobset.py", + qps_utils_dir / "python_utils" / "jobset.py", + ) + + for sofile in self.build_dir.glob("libgrpc++_test_config.so*"): + self.install_file(self.build_dir / sofile, self.install_dir / "lib" / sofile.name) + for sofile in self.build_dir.glob("libgrpc++_test_util.so*"): + self.install_file(self.build_dir / sofile, self.install_dir / "lib" / sofile.name) + for sofile in self.build_dir.glob("libgrpc_test_util.so*"): + self.install_file(self.build_dir / sofile, self.install_dir / "lib" / sofile.name) diff --git a/pycheribuild/projects/cross/protobuf.py b/pycheribuild/projects/cross/protobuf.py new file mode 100644 index 000000000..39048b15c --- /dev/null +++ b/pycheribuild/projects/cross/protobuf.py @@ -0,0 +1,51 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Alfredo Mazzinghi +# +# This software was developed by SRI International, the University of +# Cambridge Computer Laboratory (Department of Computer Science and +# Technology), and Capabilities Limited under Defense Advanced Research +# Projects Agency (DARPA) Contract No. FA8750-24-C-B047 ("DEC"). +# +# 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. +# +from .crosscompileproject import BuildType, CrossCompileCMakeProject, GitRepository +from ...config.compilation_targets import CompilationTargets +from ...config.target_info import DefaultInstallDir + + +class BuildProtobuf(CrossCompileCMakeProject): + target = "protobuf" + repository = GitRepository("https://github.com/CTSRD-CHERI/protobuf.git", default_branch="v3.21.12-cheri") + is_large_source_repository = True + default_build_type = BuildType.RELWITHDEBINFO + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) + + def setup(self): + super().setup() + self.add_cmake_options( + CMAKE_CXX_STANDARD=11, + protobuf_BUILD_TESTS="OFF", + BUILD_SHARED_LIBS="ON", + ) diff --git a/pycheribuild/projects/cross/re2.py b/pycheribuild/projects/cross/re2.py new file mode 100644 index 000000000..d99b0bea6 --- /dev/null +++ b/pycheribuild/projects/cross/re2.py @@ -0,0 +1,47 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Alfredo Mazzinghi +# +# This software was developed by SRI International, the University of +# Cambridge Computer Laboratory (Department of Computer Science and +# Technology), and Capabilities Limited under Defense Advanced Research +# Projects Agency (DARPA) Contract No. FA8750-24-C-B047 ("DEC"). +# +# 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. +# +from .crosscompileproject import BuildType, CrossCompileCMakeProject, GitRepository +from ...config.compilation_targets import CompilationTargets +from ...config.target_info import DefaultInstallDir + + +class BuildRe2(CrossCompileCMakeProject): + target = "re2" + repository = GitRepository("https://github.com/google/re2", default_branch="2023-03-01") + is_large_source_repository = True + default_build_type = BuildType.DEBUG + native_install_dir = DefaultInstallDir.CHERI_SDK + supported_architectures = (*CompilationTargets.ALL_SUPPORTED_CHERIBSD_TARGETS, *CompilationTargets.ALL_NATIVE) + + def setup(self): + super().setup() + self.add_cmake_options(BUILD_SHARED_LIBS="ON")