Skip to content

Commit

Permalink
Introduce sb_is_modular build flag (#1111)
Browse files Browse the repository at this point in the history
b/246854012

sb_is_modular is set for modular builds, which have:
1) Application binary built as a shared library.
2) Either of a) or b)
a. Starboard built at a shared library and a separate loader_app
executable.
   b. A loader_app executable with Starboard built in ( Evergreen ).

sb_is_modular shares a large subset with evergreen but is different
because of certain elements which are evergreen specific. An example of
evergreen specific code not part of modular builds is
a)Cobalt app updater(cobalt/updater/updater.cc)

This change replaces certain common instances of sb_is_evergreen with
sb_is_modular
and SB_IS_EVERGREEN with SB_IS_MODULAR
  • Loading branch information
niranjanyardi authored Aug 2, 2023
1 parent c8634d0 commit 84b3eec
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 61 deletions.
2 changes: 1 addition & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ component("base") {
# TODO(b/206642994): see if we can remove this condition. It's added for now
# because linking atomic leads to linker errors for evergreen on arm-hardfp,
# and it's apparently not really needed (i.e., we can build without it).
if (!is_starboard || !sb_is_evergreen) {
if (!is_starboard || !sb_is_modular) {
libs += [ "atomic" ]
}
}
Expand Down
6 changes: 3 additions & 3 deletions base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void SetMinLogLevel(int level) {
g_min_log_level = std::min(LOG_FATAL, level);
}

#if defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#if defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)
int GetMinLogLevel() {
return LOG_NUM_SEVERITIES;
}
Expand All @@ -579,7 +579,7 @@ void SetLogItems(bool enable_process_id,

void SetLogPrefix(const char* prefix) {}

#else // defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#else // defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)

int GetMinLogLevel() {
return g_min_log_level;
Expand Down Expand Up @@ -623,7 +623,7 @@ void SetLogPrefix(const char* prefix) {
base::ContainsOnlyChars(prefix, "abcdefghijklmnopqrstuvwxyz"));
g_log_prefix = prefix;
}
#endif // defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#endif // defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)

void SetShowErrorDialogs(bool enable_dialogs) {
show_error_dialogs = enable_dialogs;
Expand Down
12 changes: 6 additions & 6 deletions base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ const LogSeverity LOG_0 = LOG_ERROR;
// LOG_IS_ON(DFATAL) always holds in debug mode. In particular, CHECK()s will
// always fire if they fail.

#if defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#if defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)
#define LOG_IS_ON(severity) false
#else // defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#else // defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)
#define LOG_IS_ON(severity) \
(::logging::ShouldCreateLogMessage(::logging::LOG_##severity))
#endif // defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#endif // defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)

// We can't do any caching tricks with VLOG_IS_ON() like the
// google-glog version since it requires GCC extensions. This means
Expand Down Expand Up @@ -445,9 +445,9 @@ const LogSeverity LOG_0 = LOG_ERROR;
#define LOG_IF(severity, condition) \
LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition))

#if defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#if defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)
#define LOG_ONCE(severity) EAT_STREAM_PARAMETERS
#else // defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#else // defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)
#define LOG_ONCE_MSG "[once] "

constexpr uint32_t kFnvOffsetBasis32 = 0x811c9dc5U;
Expand Down Expand Up @@ -481,7 +481,7 @@ bool LogOnceHelper<FILE_HASH, LINE>::logged_ = false;
((::logging::LogOnceHelper<::logging::hash_32_fnv1a_const(__FILE__), \
__LINE__>::logged_ = true) == true))) \
<< LOG_ONCE_MSG
#endif // defined(OFFICIAL_BUILD) && !SB_IS(EVERGREEN)
#endif // defined(OFFICIAL_BUILD) && !SB_IS(MODULAR)

// The VLOG macros log with negative verbosities.
#define VLOG_STREAM(verbose_level) \
Expand Down
2 changes: 1 addition & 1 deletion build/toolchain/gcc_toolchain.gni
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ template("gcc_toolchain") {
# TODO(b/206642994): see if we can remove this condition. It's needed for
# now to add cflags for evergreen platforms but we haven't yet decided
# whether cflags should be added here for all platforms.
if (is_starboard && sb_is_evergreen && !is_starboard_toolchain) {
if (is_starboard && sb_is_modular && !is_starboard_toolchain) {
command = "$asm -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{asmflags}}${extra_asmflags} -c {{source}} -o {{output}}"
} else {
command = "$asm -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{asmflags}}${extra_asmflags} -c {{source}} -o {{output}}"
Expand Down
23 changes: 14 additions & 9 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,27 @@ group("default") {
"//third_party/brotli:dec_no_dictionary_data",
]

if (sb_is_evergreen) {
if (sb_is_modular) {
deps += [
"//base/util/values:values_util",
"//cobalt/updater",
"//cobalt/updater:crash_sandbox",
"//cobalt/updater:noop_sandbox",
"//cobalt/updater:one_app_only_sandbox",
"//components/client_update_protocol",
"//components/crx_file",
"//components/prefs",
"//components/update_client",
"//third_party/llvm-project/compiler-rt:compiler_rt",
"//third_party/llvm-project/libcxx:cxx",
"//third_party/llvm-project/libcxxabi:cxxabi",
"//third_party/musl:c",
]
if (sb_is_evergreen) {
deps += [
# TODO(b/294247612): Remove unnecessary dependencies.
"//cobalt/updater",
"//cobalt/updater:crash_sandbox",
"//cobalt/updater:noop_sandbox",
"//cobalt/updater:one_app_only_sandbox",
"//components/client_update_protocol",
"//components/crx_file",
"//components/prefs",
"//components/update_client",
]
}
if (!build_with_separate_cobalt_toolchain) {
deps += [ "//third_party/llvm-project/libunwind:unwind_evergreen" ]
}
Expand Down
6 changes: 3 additions & 3 deletions cobalt/base/wrap_main_starboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "starboard/client_porting/wrap_main/wrap_main.h"
#include "starboard/event.h"
#include "starboard/system.h"
#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
#include "third_party/musl/src/starboard/internal/hwcap_impl.h"
#endif

Expand All @@ -45,7 +45,7 @@ void BaseEventHandler(const SbEvent* event) {
DCHECK(!g_started);
DCHECK(!g_at_exit);
g_at_exit = new base::AtExitManager();
#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
init_musl_hwcap();
#endif
InitCobalt(data->argument_count, data->argument_values, data->link);
Expand All @@ -64,7 +64,7 @@ void BaseEventHandler(const SbEvent* event) {
if (!g_started) {
DCHECK(!g_at_exit);
g_at_exit = new base::AtExitManager();
#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
init_musl_hwcap();
#endif
InitCobalt(data->argument_count, data->argument_values, data->link);
Expand Down
4 changes: 2 additions & 2 deletions cobalt/css_parser/scanner_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ScannerTest : public ::testing::Test,
return;
}

#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
// We don't support changing locale for Evergreen so run only
// if the default/empty local is passed in the param.
locale_okay_ = (GetParam()[0] == 0);
Expand All @@ -60,7 +60,7 @@ class ScannerTest : public ::testing::Test,
}

virtual void TearDown() {
#if !SB_IS(EVERGREEN)
#if !SB_IS(MODULAR)
if (!old_locale_.empty()) setlocale(LC_NUMERIC, old_locale_.c_str());
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion cobalt/media/sandbox/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ target(final_executable_type, "web_media_player_sandbox") {
"//url",
]

if (!sb_is_evergreen) {
if (!sb_is_modular) {
deps += cobalt_platform_dependencies
}
}
2 changes: 1 addition & 1 deletion cobalt/network/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static_library("network") {
defines = [ "ENABLE_NETWORK_LOGGING" ]
}

if (!sb_is_evergreen) {
if (!sb_is_modular) {
deps += cobalt_platform_dependencies
}
}
Expand Down
13 changes: 10 additions & 3 deletions starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ group("gn_all") {
deps += [ "//starboard/benchmark" ]
}

if (build_with_separate_cobalt_toolchain && is_cobalt_toolchain) {
assert(sb_is_modular,
"sb_is_modular should be set when building with cobalt_toolchain")
}

if (!sb_is_evergreen) {
deps += [ "//third_party/lz4_lib:lz4" ]

Expand Down Expand Up @@ -92,14 +97,16 @@ group("starboard") {
"//starboard/client_porting/eztime",
]

if (sb_is_evergreen) {
if (sb_is_modular) {
public_deps += [
"//starboard/elf_loader:sabi_string",
"//third_party/llvm-project/compiler-rt:compiler_rt",
"//third_party/llvm-project/libcxx:cxx",
"//third_party/llvm-project/libcxxabi:cxxabi",
"//third_party/musl:c",
]
if (sb_is_evergreen) {
public_deps += [ "//starboard/elf_loader:sabi_string" ]
}
if (build_with_separate_cobalt_toolchain) {
data_deps = [ ":starboard_platform_group($starboard_toolchain)" ]
} else {
Expand Down Expand Up @@ -193,7 +200,7 @@ if (current_toolchain == starboard_toolchain) {
} else {
public_deps += [ "//third_party/crashpad/wrapper:wrapper_stub" ]
}
if (!sb_is_evergreen) {
if (!sb_is_modular) {
public_deps += [ "//$starboard_path:starboard_platform" ]
}
}
Expand Down
6 changes: 5 additions & 1 deletion starboard/build/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ config("starboard") {
defines += [ "SB_IS_LIBRARY=1" ]
}

if (sb_is_modular) {
defines += [ "SB_IS_MODULAR=1" ]
}

if (sb_is_evergreen) {
defines += [ "SB_IS_EVERGREEN=1" ]
}
Expand Down Expand Up @@ -221,7 +225,7 @@ config("warnings_as_errors") {
# override flags specified in a platform's "platform_configuration" config,
# which is where these particular flags would otherwise naturally fit.
config("default_compiler_flags") {
if (is_starboardized_toolchain && sb_is_evergreen && target_cpu == "arm") {
if (is_starboardized_toolchain && sb_is_modular && target_cpu == "arm") {
cflags = [ "-mfpu=vfpv3" ]
asmflags = cflags
}
Expand Down
3 changes: 3 additions & 0 deletions starboard/build/config/base_configuration.gni
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ declare_args() {
# Directory path to static contents' data.
sb_static_contents_output_data_dir = "$root_out_dir/content/data"

# Whether this is a modular build.
sb_is_modular = false

# Whether this is an Evergreen build.
sb_is_evergreen = false

Expand Down
4 changes: 2 additions & 2 deletions starboard/common/benchmark_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int RunAllBenchmarks(int argc, char** argv) {

// When we are building Evergreen we need to export SbEventHandle so that the
// ELF loader can find and invoke it.
#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
SB_EXPORT
#endif // SB_IS(EVERGREEN)
#endif // SB_IS(MODULAR)
STARBOARD_WRAP_SIMPLE_MAIN(RunAllBenchmarks);
2 changes: 1 addition & 1 deletion starboard/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class LogMessageVoidify {
#define SB_LAZY_STREAM(stream, condition) \
!(condition) ? (void)0 : ::starboard::logging::LogMessageVoidify() & (stream)

#if SB_LOGGING_IS_OFFICIAL_BUILD && !SB_IS(EVERGREEN) && \
#if SB_LOGGING_IS_OFFICIAL_BUILD && !SB_IS(MODULAR) && \
!SB_IS(EVERGREEN_COMPATIBLE)
#define SB_LOG_IS_ON(severity) \
((::starboard::logging::SB_LOG_##severity >= \
Expand Down
4 changes: 2 additions & 2 deletions starboard/common/test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int InitAndRunAllTests(int argc, char** argv) {

// When we are building Evergreen we need to export SbEventHandle so that the
// ELF loader can find and invoke it.
#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
SB_EXPORT
#endif // SB_IS(EVERGREEN)
#endif // SB_IS(MODULAR)
STARBOARD_WRAP_SIMPLE_MAIN(InitAndRunAllTests);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import("//starboard/build/config/base_configuration.gni")

sb_is_modular = true

sb_is_evergreen = true

cobalt_font_package = "empty"
Expand Down
8 changes: 4 additions & 4 deletions starboard/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
// COMPONENT_BUILD is defined when generating shared libraries for each project,
// rather than static libraries. This means we need to be careful about
// EXPORT/IMPORT.
//
// SB_IS_EVERGREEN is defined when the binaries generated will be composed

// SB_IS_MODULAR is defined when the binaries generated will be composed
// entirely of the Starboard implementation and will provide the Starboard API,
// with all client applications being built separately.

#if defined(COMPONENT_BUILD) || SB_IS(EVERGREEN)
#if defined(COMPONENT_BUILD) || SB_IS(MODULAR)

// STARBOARD_IMPLEMENTATION is defined when building the Starboard library
// sources, and shouldn't be defined when building sources that are clients of
Expand All @@ -54,7 +54,7 @@
#define SB_EXPORT_PRIVATE SB_IMPORT_PLATFORM
#define SB_IMPORT SB_EXPORT_PLATFORM
#endif
#else // defined(COMPONENT_BUILD) || SB_IS(EVERGREEN)
#else // defined(COMPONENT_BUILD) || SB_IS(MODULAR)
#define SB_EXPORT
#define SB_EXPORT_PRIVATE
#define SB_IMPORT
Expand Down
2 changes: 1 addition & 1 deletion starboard/extension/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ target(gtest_target_type, "extension_test") {
"//testing/gmock",
"//testing/gtest",
]
if (sb_is_evergreen) {
if (sb_is_modular) {
deps += cobalt_platform_dependencies
}
}
2 changes: 1 addition & 1 deletion starboard/linux/shared/platform_configuration/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ config("platform_configuration") {
"rt",
]

if (!sb_is_evergreen) {
if (!sb_is_modular) {
ldflags += [ "-static-libstdc++" ]
}

Expand Down
2 changes: 1 addition & 1 deletion third_party/boringssl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static_library("crypto") {
configs -= [ "//starboard/build/config:size" ]
configs += [ "//starboard/build/config:speed" ]

if (sb_is_evergreen) {
if (sb_is_modular) {
calling_convention = sabi_variables.calling_convention
if ((calling_convention != "aarch64" && calling_convention != "eabi" &&
calling_convention != "sysv" && calling_convention != "windows") ||
Expand Down
2 changes: 1 addition & 1 deletion third_party/boringssl/src/crypto/cpu-starboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static bool starboard_cpuid_setup_arm(void) { return true; }
void OPENSSL_cpuid_setup_starboard(void) {
if (!starboard_cpuid_setup_arm() ||
!starboard_cpuid_setup_x86() ) {
#if !SB_IS(EVERGREEN)
#if !SB_IS(MODULAR)
// Fall back on original implementation if the platform
// does not yet support Starboard CPU detection
OPENSSL_cpuid_setup();
Expand Down
5 changes: 3 additions & 2 deletions third_party/inspector_protocol/crdtp/json_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace crdtp {
namespace json {
namespace platform {
bool StrToD(const char* str, double* result) {
#if SB_IS(EVERGREEN)
#if SB_IS(MODULAR)
#error "The std::locale::classic() is not supported for Evergreen. Please use base::StringToDouble()."
#endif
std::istringstream is(str);
Expand All @@ -26,7 +26,8 @@ bool StrToD(const char* str, double* result) {
}

std::string DToStr(double value) {
#if SB_IS(EVERGREEN)
//Ask Kaido/Yavor if this is needed.
#if SB_IS(MODULAR)
#error "The std::locale::classic() is not supported for Evergreen. Please use base::NumberToString()."
#endif
std::stringstream ss;
Expand Down
8 changes: 4 additions & 4 deletions third_party/libjpeg-turbo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ if (nasm_exists && (current_cpu == "x86" || current_cpu == "x64")) {
}

# TODO(b/206642994): look into whether we should condition on the
# floating_point_fpu SABI variable, rather than sb_is_evergreen, here as we did
# floating_point_fpu SABI variable, rather than sb_is_modular, here as we did
# in third_party/libjpeg-turbo/libjpeg.gyp.
if (is_starboard && sb_is_evergreen && current_cpu == "arm" && arm_use_neon) {
if (is_starboard && sb_is_modular && current_cpu == "arm" && arm_use_neon) {
config("simd_arm_config") {
cflags = [ "-mfpu=neon" ]
}
Expand Down Expand Up @@ -205,7 +205,7 @@ static_library("simd") {
}
configs += [ "//build/config/compiler:optimize_speed" ]

if (is_starboard && sb_is_evergreen && current_cpu == "arm") {
if (is_starboard && sb_is_modular && current_cpu == "arm") {
configs += [ ":simd_arm_config" ]
}
} else {
Expand Down Expand Up @@ -316,7 +316,7 @@ static_library("libjpeg") {
# TODO(b/236258535): Enable neon instructions once the code is updated
# to use SbCPUFeatures() at runtime.
if ((is_msan && (current_cpu == "x86" || current_cpu == "x64")) ||
(is_starboard && sb_is_evergreen)) {
(is_starboard && sb_is_modular)) {
sources += [ "jsimd_none.c" ]
} else {
public_deps += [ ":simd" ]
Expand Down
Loading

0 comments on commit 84b3eec

Please sign in to comment.