0

Is anyone able to offer advice on cross-compiling V8 using a Buildroot toolchain?

I need to embed the V8 monolith lib into a C++ app currently using CMake. Under Buildroot cmake packages are automagically provided with a toolchain.cmake file to ensure to correct compiler, sysroot and C++ libs are used etc.

I'm able to set sysroot using gn args and understand there is a custom_toolchain arg I can set to a path for a toolchain definition file of some description?

Documentation seems a little lacking. Does anyone have experience compiling V8 for a builroot based project or in defining a "custom toolchain" ?

J.Marler
  • 21
  • 5

1 Answers1

2

I was able to cross compile V8 as follows.

In tools/toolchain/BUILD.gn I added:

gcc_toolchain("arm64-buildroot") {
  toolprefix = "/path/to/buildroot/output/host/bin/aarch64-linux-"

  cc = "${toolprefix}gcc"
  cxx = "${toolprefix}g++"

  readelf = "${toolprefix}readelf"
  nm = "${toolprefix}nm"
  ar = "${toolprefix}ar"
  ld = cxx

  toolchain_args = {
    current_cpu = "arm64"
    current_os = "linux"
    is_clang = false
  }
}

Ran gn gen out/arm64 and set the build arguments with gn args out/arm64:

custom_toolchain = "//tools/toolchain:arm64-buildroot"
target_cpu = "arm64"
target_os = "linux"
target_sysroot = "/path/to/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot"
is_clang = false
use_gold = false
is_component_build = false
v8_monolithic = true
v8_use_external_startup_data = false

Then to build the library:

ninja -C out/arm64 v8_monolith

For more information see: https://gn.googlesource.com/gn/+/master/docs/reference.md#example-of-defining-a-toolchain

Ezra Bühler
  • 330
  • 2
  • 12