Skip to content

Commit

Permalink
Build shared library binaries instead of executables for test targets (
Browse files Browse the repository at this point in the history
…#4771)

b/389971583
  • Loading branch information
niranjanyardi authored Feb 5, 2025
1 parent 84539d6 commit b21b278
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 24 deletions.
15 changes: 1 addition & 14 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1792,22 +1792,9 @@ component("base") {
"process/process_metrics_posix.cc",
"sync_socket_posix.cc",

# ../../base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc:748:36: error: incomplete result type 'struct mallinfo' in function definition
# SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW {
"allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc",
"allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.h",

# In file included from ../../base/rand_util_posix.cc:26:
# ../../third_party/lss/linux_syscall_support.h:118:10: fatal error: 'linux/unistd.h' file not found
"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",
# base/posix/unix_domain_socket.cc:91:22: error: implicit conversion loses integer precision:
"posix/unix_domain_socket.cc",
"posix/unix_domain_socket.h",
"rand_util_posix.cc",
"system/sys_info_posix.cc",

# SHIM_ALWAYS_EXPORT size_t malloc_usable_size(void* address) __THROW {
# ^
Expand Down
4 changes: 0 additions & 4 deletions base/allocator/partition_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ component("partition_alloc") {
"partition_alloc_base/time/time_conversion_posix.cc",
]

# TODO: b/384652502 - Cobalt: Fix compiler errors building hermetically.
if (is_cobalt && is_cobalt_hermetic_build) {
sources -= [ "partition_alloc_base/rand_util_posix.cc" ]
}

if (is_android || is_chromeos_ash) {
sources += [ "partition_alloc_base/time/time_android.cc" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !defined(IS_COBALT_HERMETIC_BUILD)
#include "third_party/lss/linux_syscall_support.h"
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Waiting for this header to appear in the iOS SDK.
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace partition_alloc::internal::base {
// (https://chromium-review.googlesource.com/c/chromium/src/+/1545096) and land
// it or some form of it.
void RandBytes(void* output, size_t output_length) {
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !defined(IS_COBALT_HERMETIC_BUILD)
// We have to call `getrandom` via Linux Syscall Support, rather than through
// the libc wrapper, because we might not have an up-to-date libc (e.g. on
// some bots).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ SHIM_ALWAYS_EXPORT int mallopt(int cmd, int value) __THROW {

#endif // !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !defined(IS_COBALT_HERMETIC_BUILD)
SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW {
partition_alloc::SimplePartitionStatsDumper allocator_dumper;
Allocator()->DumpStats("malloc", true, &allocator_dumper);
Expand Down
2 changes: 1 addition & 1 deletion base/rand_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "base/time/time.h"
#include "build/build_config.h"

#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL) && !defined(IS_COBALT_HERMETIC_BUILD)
#include "third_party/lss/linux_syscall_support.h"
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Waiting for this header to appear in the iOS SDK.
Expand Down
7 changes: 6 additions & 1 deletion build/config/gcc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ if (is_component_build && !is_android) {
# Settings for executables.
config("executable_config") {
configs = executable_and_shared_library_configs_
ldflags = [ "-pie" ]
# TODO: b/384652502 - Cobalt: Fix linker errors for cobalt_toolchain
if (is_starboard && current_toolchain == cobalt_toolchain) {
ldflags = []
} else {
ldflags = [ "-pie" ]
}
if (is_android) {
ldflags += [
"-Bdynamic",
Expand Down
45 changes: 45 additions & 0 deletions cobalt/build/testing/cobalt_test_templates.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2025 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

template("cobalt_test") {
actual_target_name = target_name
shlib_target_name = actual_target_name
loader_target_name = "${actual_target_name}_loader"

shared_library(shlib_target_name) {
output_name = actual_target_name
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
testonly = true
if (!defined(data_deps)) {
data_deps = []
}
data_deps += [
":${loader_target_name}($starboard_toolchain)",
"//starboard:starboard_group($starboard_toolchain)",
]
}

if (current_toolchain == starboard_toolchain) {
executable(loader_target_name) {
sources = [ "//$starboard_path/starboard_loader.cc" ]
testonly = true
if (use_asan) {
sources += [ "//$starboard_path/sanitizer_options.cc" ]
}
defines = [ "SB_LOADER_MODULE=\"$actual_target_name\"" ]
configs += [ "//starboard/build/config:starboard_implementation" ]
deps = [ "//starboard:starboard_group($starboard_toolchain)" ]
}
}
}
8 changes: 8 additions & 0 deletions device/bluetooth/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ source_set("deprecated_experimental_mojo") {
]
}

# TODO: b/384652502 - Cobalt: Fix linker errors.
if (is_starboard) {
sources -= [
"bluez/metrics_recorder.cc",
"bluez/metrics_recorder.h",
]
}

deps = [
":bluetooth",
"//device/bluetooth/public/mojom:deprecated_experimental_interfaces",
Expand Down
18 changes: 17 additions & 1 deletion starboard/linux/x64x11/starboard_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <dlfcn.h>
#include <iostream>
#include "starboard/event.h"

int main(int argc, char** argv) {
return SbRunStarboardMain(argc, argv, SbEventHandle);
static const char* s_target_lib_path = "lib" SB_LOADER_MODULE ".so";
int start_result;

void* handle_ = dlopen(s_target_lib_path, RTLD_LAZY);
if (!handle_) {
std::cerr << "dlopen failure: " << dlerror() << std::endl;
}

void* callback = nullptr;
callback = dlsym(handle_, "SbEventHandle");
if (!callback) {
std::cerr << "dlsym failure: " << dlerror() << std::endl;
}
return SbRunStarboardMain(argc, argv,
reinterpret_cast<SbEventHandleCallback>(callback));
}
13 changes: 13 additions & 0 deletions testing/test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import("//build/config/gclient_args.gni")
import("//build/config/rts.gni")
import("//build/rust/rust_static_library.gni")
import("//build_overrides/build.gni")
if (is_starboard) {
import("//cobalt/build/configs/modular_variables.gni")
import("//cobalt/build/testing/cobalt_test_templates.gni")
}

declare_args() {
# Some component repos (e.g. ANGLE) import //testing but do not have
Expand Down Expand Up @@ -957,6 +961,15 @@ template("test") {
data_deps += [ ":${invoker.target_name}__rts_filters" ]
}
}
# TODO: b/384652502 - Cobalt: Remove use_custom_libc after setting
# is_starboard as a toolchain arg.
} else if (is_starboard && use_custom_libc) {
cobalt_test(target_name) {
forward_variables_from(invoker,
"*",
TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
testonly = true
}
} else if (!is_nacl) {
if (is_mac || is_win) {
assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Expand Down

0 comments on commit b21b278

Please sign in to comment.