Skip to content

Commit

Permalink
Build nplb hermetically
Browse files Browse the repository at this point in the history
  • Loading branch information
niranjanyardi committed Jan 3, 2025
1 parent 8e7db49 commit 5e9c5fa
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/config/linux-evergreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"linux-x64x11-evergreen"
],
"targets": [
"base_unittests"
"base",
"nplb"
],
"includes": [
{
Expand Down
28 changes: 27 additions & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2230,7 +2256,7 @@ component("base") {
sources += [
"system/sys_info_starboard.cc",
"system/sys_info_starboard.h",
]
]
}

if (use_blink) {
Expand Down
17 changes: 17 additions & 0 deletions base/allocator/partition_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions base/allocator/partition_allocator/partition_alloc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <linux/version.h>
// TODO(bikineev): Enable for ChromeOS.
#define PA_CONFIG_STARSCAN_UFFD_WRITE_PROTECTOR_SUPPORTED() \
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions build/config/c++/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions buildtools/third_party/libc++/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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++.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]
}
}
}
13 changes: 13 additions & 0 deletions buildtools/third_party/libc++abi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions cobalt/build/configs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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
}
Expand Down
63 changes: 62 additions & 1 deletion starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}
}
}
}

Expand Down
10 changes: 0 additions & 10 deletions starboard/build/config/modular/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions third_party/abseil-cpp/absl/base/internal/direct_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#include <sys/mman.h>

#ifdef __linux__

#include "build/build_config.h"
#if defined(__linux__) && !BUILDFLAG(IS_STARBOARD)
#include <sys/types.h>
#ifdef __BIONIC__
#include <sys/syscall.h>
Expand Down
1 change: 0 additions & 1 deletion third_party/llvm-project/compiler-rt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ static_library("compiler_rt") {
}

configs += [ ":compiler_rt_config" ]
configs -= [ "//starboard/build/config:default_cpp_standard" ]
}
2 changes: 1 addition & 1 deletion third_party/musl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (target_cpu == "x64") {

config("external_settings") {
include_dirs = [
"musl/include",
"include",
"arch/$musl_arch",
"arch/generic",
]
Expand Down

0 comments on commit 5e9c5fa

Please sign in to comment.