From abaf11c9948c7719ef86145540273377d5a35d9d Mon Sep 17 00:00:00 2001 From: Niranjan Yardi Date: Tue, 17 Dec 2024 01:49:31 -0800 Subject: [PATCH] Build nplb hermetically --- .github/config/linux-evergreen.json | 3 +- base/BUILD.gn | 28 ++++++++- base/allocator/partition_allocator/BUILD.gn | 17 +++++ .../partition_alloc_config.h | 6 +- build/config/c++/BUILD.gn | 26 ++++++++ buildtools/third_party/libc++/BUILD.gn | 25 ++++++++ buildtools/third_party/libc++abi/BUILD.gn | 13 ++++ cobalt/build/configs/BUILD.gn | 9 ++- starboard/BUILD.gn | 63 ++++++++++++++++++- starboard/build/config/modular/BUILD.gn | 10 --- .../absl/base/internal/direct_mmap.h | 4 +- third_party/llvm-project/compiler-rt/BUILD.gn | 1 - third_party/musl/BUILD.gn | 2 +- 13 files changed, 186 insertions(+), 21 deletions(-) diff --git a/.github/config/linux-evergreen.json b/.github/config/linux-evergreen.json index 76b187f782e4..0a5074a51b66 100644 --- a/.github/config/linux-evergreen.json +++ b/.github/config/linux-evergreen.json @@ -4,7 +4,8 @@ "linux-x64x11-evergreen" ], "targets": [ - "base_unittests" + "base", + "nplb" ], "includes": [ { diff --git a/base/BUILD.gn b/base/BUILD.gn index 434dc918c8e3..bbf4524794ed 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -1087,6 +1087,14 @@ component("base") { "//third_party/abseil-cpp:absl", ] + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + deps -= [ "//base/allocator/partition_allocator:raw_ptr" ] + deps += [ "//starboard:starboard_group" ] + } + } + if (build_rust_base_conversions) { # Base provides conversions between CXX types and base types (e.g. # StringPiece). @@ -1641,6 +1649,24 @@ component("base") { ] } + # TODO: b/384652502 - Cobalt: Fix compiler errors building hermetically. + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + sources -= [ + "base_paths_posix.h", + "memory/madv_free_discardable_memory_allocator_posix.cc", + "memory/madv_free_discardable_memory_allocator_posix.h", + "memory/madv_free_discardable_memory_posix.cc", + "memory/madv_free_discardable_memory_posix.h", + "posix/unix_domain_socket.cc", + "posix/unix_domain_socket.h", + "rand_util_posix.cc", + "system/sys_info_posix.cc", + ] + } + } + if (is_posix || is_fuchsia) { sources += [ "files/file_descriptor_watcher_posix.cc", @@ -2230,7 +2256,7 @@ component("base") { sources += [ "system/sys_info_starboard.cc", "system/sys_info_starboard.h", - ] + ] } if (use_blink) { diff --git a/base/allocator/partition_allocator/BUILD.gn b/base/allocator/partition_allocator/BUILD.gn index 4d64e3fdb4f0..0f12c7d3f475 100644 --- a/base/allocator/partition_allocator/BUILD.gn +++ b/base/allocator/partition_allocator/BUILD.gn @@ -228,6 +228,16 @@ component("partition_alloc") { "partition_alloc_base/time/time_conversion_posix.cc", ] + # TODO: b/384652502 - Cobalt: Fix compiler errors building hermetically. + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + sources -= [ "partition_alloc_base/rand_util_posix.cc" ] + deps += [ "//starboard:starboard_group" ] + + } + } + if (is_android || is_chromeos_ash) { sources += [ "partition_alloc_base/time/time_android.cc" ] } @@ -320,6 +330,13 @@ component("partition_alloc") { # tagging.cc requires __arm_mte_set_* functions. deps += [ "//third_party/android_ndk:cpu_features" ] } + + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + deps += [ "//starboard:starboard_group" ] + } + } if (is_fuchsia) { public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fit", diff --git a/base/allocator/partition_allocator/partition_alloc_config.h b/base/allocator/partition_allocator/partition_alloc_config.h index a6671d675a6b..b2a21be2ba66 100644 --- a/base/allocator/partition_allocator/partition_alloc_config.h +++ b/base/allocator/partition_allocator/partition_alloc_config.h @@ -64,8 +64,9 @@ static_assert(sizeof(void*) != 8, ""); #define PA_CONFIG_GLUE_CORE_POOLS() 0 #endif +// Cobalt comment: Avoid including Linux headers when OS is starboard. #if BUILDFLAG(HAS_64_BIT_POINTERS) && \ - (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)) + (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)) && !BUILDFLAG(IS_STARBOARD) #include // TODO(bikineev): Enable for ChromeOS. #define PA_CONFIG_STARSCAN_UFFD_WRITE_PROTECTOR_SUPPORTED() \ @@ -103,8 +104,9 @@ static_assert(sizeof(void*) != 8, ""); // POSIX is not only UNIX, e.g. macOS and other OSes. We do use Linux-specific // features such as futex(2). +// Cobalt comment: Avoid including Linux headers when OS is starboard. #define PA_CONFIG_HAS_LINUX_KERNEL() \ - (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)) + (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)) && !BUILDFLAG(IS_STARBOARD) // On some platforms, we implement locking by spinning in userspace, then going // into the kernel only if there is contention. This requires platform support, diff --git a/build/config/c++/BUILD.gn b/build/config/c++/BUILD.gn index c00dcef4cd1e..e1b53dac3332 100644 --- a/build/config/c++/BUILD.gn +++ b/build/config/c++/BUILD.gn @@ -68,6 +68,23 @@ config("runtime_library") { "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir), "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir), ] + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + cflags_cc += [ + "-isystem" + + rebase_path("//third_party/musl/include", root_build_dir), + "-isystem" + + rebase_path("//third_party/musl/arch/generic", root_build_dir), + ] + cflags_c = [ + "-isystem" + + rebase_path("//third_party/musl/include", root_build_dir), + "-isystem" + + rebase_path("//third_party/musl/arch/generic", root_build_dir), + ] + } + } cflags_objcc = cflags_cc @@ -92,6 +109,15 @@ config("runtime_library") { "m", "rt", ] + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + libs -= [ + "c", + "rt", + ] + } + } } } if (use_custom_libcxx && enable_safe_libcxx) { diff --git a/buildtools/third_party/libc++/BUILD.gn b/buildtools/third_party/libc++/BUILD.gn index 21421aa32047..a110dc277c7b 100644 --- a/buildtools/third_party/libc++/BUILD.gn +++ b/buildtools/third_party/libc++/BUILD.gn @@ -54,6 +54,13 @@ target(_libcxx_target_type, "libc++") { "//build/config:common_deps", "//third_party/catapult/devil:devil", ] + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + visibility += [ "//starboard:starboard_group" ] + } + } + if (is_linux) { # This target packages libc++.so, so must have an explicit dependency on # libc++. @@ -115,6 +122,14 @@ target(_libcxx_target_type, "libc++") { "trunk/src/verbose_abort.cpp", ] + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + # TODO: b/384652502 - Cobalt: Fix compiler errors building hermetically. + sources -= [ "trunk/src/atomic.cpp" ] + } + } + if (enable_iterator_debugging) { sources += [ "trunk/src/debug.cpp", @@ -210,4 +225,14 @@ target(_libcxx_target_type, "libc++") { deps = [ "//buildtools/third_party/libc++abi" ] } } + if (is_cobalt) { + import("//cobalt/build/configs/modular_variables.gni") + if (is_starboard && current_toolchain == cobalt_toolchain && + use_custom_libc) { + deps += [ + "//third_party/llvm-project/compiler-rt:compiler_rt", + "//third_party/musl:c", + ] + } + } } diff --git a/buildtools/third_party/libc++abi/BUILD.gn b/buildtools/third_party/libc++abi/BUILD.gn index 3ab30c4f8776..02370f9b0d57 100644 --- a/buildtools/third_party/libc++abi/BUILD.gn +++ b/buildtools/third_party/libc++abi/BUILD.gn @@ -13,6 +13,12 @@ source_set("libc++abi") { } else { visibility = [ "//buildtools/third_party/libc++" ] } + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + visibility += [ "//starboard:starboard_group" ] + } + } # Fuchsia builds don't link against any libraries that provide stack # unwinding symbols, unlike Linux does with glibc (same applies for Android). @@ -21,6 +27,13 @@ source_set("libc++abi") { deps = [ "//buildtools/third_party/libunwind" ] } + if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) { + import("//cobalt/build/configs/modular_variables.gni") + if (use_custom_libc) { + deps = [ "//third_party/musl:c" ] + } + } + sources = [ "trunk/src/abort_message.cpp", "trunk/src/cxa_aux_runtime.cpp", diff --git a/cobalt/build/configs/BUILD.gn b/cobalt/build/configs/BUILD.gn index 81f47ec01aac..ae5bb82a2d8c 100644 --- a/cobalt/build/configs/BUILD.gn +++ b/cobalt/build/configs/BUILD.gn @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//cobalt/build/configs/modular_variables.gni") import("//starboard/build/buildflags.gni") config("cobalt_config") { @@ -21,8 +22,12 @@ config("cobalt_config") { ] if (current_toolchain == starboard_toolchain) { configs += [ "//${starboard_path}/platform_configuration" ] - } else if (current_toolchain == cobalt_toolchain) { - # TODO(nyardi) : Add modular/cobalt toolchain configs as needed" + } else if (current_toolchain == cobalt_toolchain && is_starboard && + use_custom_libc) { + configs += [ + "//starboard/build/config/modular/x64", + "//starboard/build/config:starboard", + ] } else { # No configs to add for any other toolchain } diff --git a/starboard/BUILD.gn b/starboard/BUILD.gn index 397aa9a92b37..08043cf7fabb 100644 --- a/starboard/BUILD.gn +++ b/starboard/BUILD.gn @@ -169,7 +169,68 @@ if (!is_cobalt) { } } else { group("starboard_group") { - deps = [ "//starboard($starboard_toolchain)" ] + deps = [] + public_deps = [ + ":starboard_headers_only", + "//starboard/client_porting/eztime", + ] + + if (sb_is_modular && current_toolchain == cobalt_toolchain) { + public_deps += [ + "//buildtools/third_party/libc++", + "//buildtools/third_party/libc++abi", + "//third_party/llvm-project/compiler-rt:compiler_rt", + "//third_party/musl:c", + ] + + if (!sb_is_evergreen) { + # For modular builds, we need to wrap any POSIX APIs that may not be ABI + # equivalent across the Cobalt toolchain and the platform toolchain. For + # non-Evergreen builds, this is done via the below wrapper implementations + # of the API functions, which will simply call a renamed version of the + # function that will be implemented in the Starboard shared library. The + # same behavior is achieved in Evergreen via exported_symbols.cc remapping + # the functions to the same renamed version. In both cases, implementation + # of these renamed functions will handle translating data types across the + # ABI boundary and be compiled into the Starboard shared library in + # //starboard/build/config/starboard_target_type.gni. + deps += [ "//starboard/shared/modular:cobalt_layer_posix_abi_wrappers" ] + } + + if (sb_is_evergreen) { + public_deps += [ "//starboard/elf_loader:sabi_string" ] + } else { + data_deps = [ ":starboard($starboard_toolchain)" ] + } + + # TODO: b/295702296 Fix libunwind for modular builds. + if (sb_is_evergreen) { + public_deps += [ "//third_party/llvm-project/libunwind:unwind" ] + } + } else { + public_deps += [ + ":starboard($starboard_toolchain)", + "//starboard/common", + ] + + if (enable_evergreen_code) { + if (!sb_is_modular || sb_is_evergreen) { + if (sb_is_evergreen_compatible && + current_toolchain == starboard_toolchain) { + public_deps += [ "//starboard/crashpad_wrapper" ] + } else { + public_deps += [ "//starboard/crashpad_wrapper:wrapper_stub" ] + } + } + } + + if (final_executable_type == "shared_library" && + current_toolchain != default_toolchain) { + set_defaults("executable") { + sources = [ "//starboard/shared/starboard/shared_main_adapter.cc" ] + } + } + } } } diff --git a/starboard/build/config/modular/BUILD.gn b/starboard/build/config/modular/BUILD.gn index aa288c5478dc..4cff336f8748 100644 --- a/starboard/build/config/modular/BUILD.gn +++ b/starboard/build/config/modular/BUILD.gn @@ -18,20 +18,10 @@ config("modular") { "-ffunction-sections", "-fdata-sections", "-nostdlibinc", - "-isystem" + rebase_path("//third_party/llvm-project/libcxxabi/include", - root_build_dir), - "-isystem" + rebase_path("//third_party/llvm-project/libunwind/include", - root_build_dir), - "-isystem" + rebase_path("//third_party/llvm-project/libcxx/include", - root_build_dir), - "-isystem" + rebase_path("//third_party/musl/include", root_build_dir), - "-isystem" + rebase_path("//third_party/musl/arch/generic", root_build_dir), ] cflags += [ "-fPIC" ] - cflags_cc = [ "-nostdinc++" ] - defines = [ # Ensure that the Starboardized __external_threading file is included. "_LIBCPP_HAS_THREAD_API_EXTERNAL", diff --git a/third_party/abseil-cpp/absl/base/internal/direct_mmap.h b/third_party/abseil-cpp/absl/base/internal/direct_mmap.h index 815b8d23ba35..530e0348b405 100644 --- a/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +++ b/third_party/abseil-cpp/absl/base/internal/direct_mmap.h @@ -24,8 +24,8 @@ #include -#ifdef __linux__ - +#include "build/build_config.h" +#if defined(__linux__) && !BUILDFLAG(IS_STARBOARD) #include #ifdef __BIONIC__ #include diff --git a/third_party/llvm-project/compiler-rt/BUILD.gn b/third_party/llvm-project/compiler-rt/BUILD.gn index 2887ebfd7373..b4c8c3c7fcfb 100644 --- a/third_party/llvm-project/compiler-rt/BUILD.gn +++ b/third_party/llvm-project/compiler-rt/BUILD.gn @@ -92,5 +92,4 @@ static_library("compiler_rt") { } configs += [ ":compiler_rt_config" ] - configs -= [ "//starboard/build/config:default_cpp_standard" ] } diff --git a/third_party/musl/BUILD.gn b/third_party/musl/BUILD.gn index 78ecc77aac79..a7aede7f4b5c 100644 --- a/third_party/musl/BUILD.gn +++ b/third_party/musl/BUILD.gn @@ -24,7 +24,7 @@ if (target_cpu == "x64") { config("external_settings") { include_dirs = [ - "musl/include", + "include", "arch/$musl_arch", "arch/generic", ]