Skip to content

Commit

Permalink
[vm] Build a runnable Fuchsia package containing Dart
Browse files Browse the repository at this point in the history
Everything in the build/fuchsia director (except for tests.cmx) was
copied and modified from:
https://fuchsia.googlesource.com/samples/+/refs/heads/master/build

This doesn't include any tests yet, but its runnable on the emulator.

Change-Id: Id64ae71062447c789ca4d10ed3a4a09e0a6d7b99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152589
Reviewed-by: Siva Annamalai <[email protected]>
Reviewed-by: Ryan Macnak <[email protected]>
Commit-Queue: Liam Appelbe <[email protected]>
  • Loading branch information
liamappelbe authored and [email protected] committed Jul 10, 2020
1 parent 57cf6eb commit 089d6fc
Show file tree
Hide file tree
Showing 14 changed files with 1,095 additions and 0 deletions.
18 changes: 18 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ group("observatory_archive") {
group("compressed_observatory_archive") {
deps = [ "runtime/observatory:copy_compressed_observatory_archive" ]
}

if (is_fuchsia) {
import("third_party/fuchsia/sdk/linux/build/component.gni")
import("third_party/fuchsia/sdk/linux/build/package.gni")

fuchsia_component("dart_sdk_fuchsia_test_component") {
testonly = true
data_deps = [
"runtime/bin:dart",
]
manifest = "build/fuchsia/tests.cmx"
}

fuchsia_package("dart_sdk_fuchsia_test_package") {
testonly = true
deps = [ ":dart_sdk_fuchsia_test_component" ]
}
}
6 changes: 6 additions & 0 deletions build/config/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ if (is_posix) {
[ "//build/config/gcc:symbol_visibility_hidden" ]
}
}
if (is_fuchsia) {
_native_compiler_configs += [
"//third_party/fuchsia/sdk/linux/build/config:compiler",
"//third_party/fuchsia/sdk/linux/build/config:runtime_library",
]
}

if (is_linux) {
_native_compiler_configs += [ "//build/config/linux:sdk" ]
Expand Down
19 changes: 19 additions & 0 deletions build/fuchsia/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

config("compiler_defaults") {
if (current_os == "linux") {
cflags = [
"-fPIC",
"-pthread",
]
}
}

config("executable_ldconfig") {
ldflags = [
"-Wl,-rpath=\$ORIGIN/",
"-Wl,-rpath-link=",
]
}
162 changes: 162 additions & 0 deletions build/fuchsia/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if (target_os == "") {
target_os = host_os
}

if (target_cpu == "") {
target_cpu = host_cpu
}

if (current_cpu == "") {
current_cpu = target_cpu
}
if (current_os == "") {
current_os = target_os
}

is_fuchsia = current_os == "fuchsia"
is_linux = current_os == "linux"

declare_args() {
is_debug = true
}

# Set the host_toolchain
declare_args() {
host_toolchain = ""
}

# ==============================================================================
# TOOLCHAIN SETUP
# ==============================================================================
#
# Here we set the default toolchain, as well as the variable host_toolchain
# which will identify the toolchain corresponding to the local system when
# doing cross-compiles. When not cross-compiling, this will be the same as the
# default toolchain.
#
# We do this before anything else to make sure we complain about any
# unsupported os/cpu combinations as early as possible.

if (host_toolchain == "") {
# This should only happen in the top-level context.
# In a specific toolchain context, the toolchain_args()
# block should have propagated a value down.

if (host_os == "linux") {
host_toolchain = "//build/fuchsia/toolchain/linux:clang_$host_cpu"
} else if (host_os == "mac") {
host_toolchain = "//build/fuchsia/toolchain/mac:$host_cpu"
} else {
assert(false, "Unsupported host_os: $host_os")
}
}

# Set toolchain based on target_os and target_cpu
_default_toolchain = ""

if (target_os == "linux") {
_default_toolchain = "//build/fuchsia/toolchain/linux:clang_$target_cpu"
} else if (target_os == "fuchsia") {
_default_toolchain = "//build/fuchsia/toolchain/fuchsia:$target_cpu"
} else {
assert(false, "Unsupported target_os: $target_os")
}

set_default_toolchain(_default_toolchain)

# Set compiler defaults

# Holds all configs used for running the compiler.
default_compiler_configs = [
"//build/fuchsia:compiler_defaults",
"//build/fuchsia/config/compiler:assembler_debug_dir",
"//build/fuchsia/config/compiler:compiler",
"//build/fuchsia/config/compiler:compiler_arm_fpu",
"//build/fuchsia/config/compiler:c++",
"//build/fuchsia/config/compiler:default_include_dirs",
"//build/fuchsia/config/compiler:default_optimization",
"//build/fuchsia/config/compiler:default_symbols",
"//build/fuchsia/config/compiler:no_exceptions",
"//build/fuchsia/config/compiler:no_rtti",
"//build/fuchsia/config/compiler:runtime_library",
"//build/fuchsia/config/compiler:extra_warnings",
"//build/fuchsia/config/compiler:symbol_visibility_hidden",
]

if (is_fuchsia) {
default_compiler_configs += [
"//third_party/fuchsia-sdk/build/config:compiler",
"//third_party/fuchsia-sdk/build/config:runtime_library",
]

# these are additional flags recommended
default_compiler_configs += [ "//build/fuchsia/config/compiler:default_stack_frames" ]
}

# Debug/release-related defines.
if (is_debug) {
default_compiler_configs += [ "//build/fuchsia/config:debug" ]
} else {
default_compiler_configs += [ "//build/fuchsia/config:release" ]
}

# Static libraries and source sets use only the compiler ones.
set_defaults("static_library") {
configs = default_compiler_configs
}
set_defaults("source_set") {
configs = default_compiler_configs
}

# Executable defaults.
default_executable_configs = default_compiler_configs + [
"//build/fuchsia:executable_ldconfig",
"//build/fuchsia/config:default_libs",
]
set_defaults("executable") {
configs = default_executable_configs
}

# Shared library and loadable module defaults (also for components in component
# mode).
default_shared_library_configs =
default_compiler_configs + [ "//build/fuchsia/config:default_libs" ]

set_defaults("shared_library") {
configs = default_shared_library_configs
}
set_defaults("loadable_module") {
configs = default_shared_library_configs
}

if (is_fuchsia) {
# Sets default dependencies for executable and shared_library targets.
#
# Variables
# no_default_deps: If true, no standard dependencies will be added.
foreach(_target_type,
[
"executable",
"shared_library",
]) {
template(_target_type) {
target(_target_type, target_name) {
forward_variables_from(invoker, "*", [ "no_default_deps" ])
if (!defined(deps)) {
deps = []
}
if (!defined(data_deps)) {
data_deps = []
}
if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) {
data_deps += [ "//build/fuchsia/config/clang:c++-runtime-deps" ]
deps += [ "//third_party/fuchsia-sdk/build/config:runtime_library_group" ]
}
}
}
}
}
37 changes: 37 additions & 0 deletions build/fuchsia/config/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Debug/release ----------------------------------------------------------------

config("debug") {
defines = [
"_DEBUG",
"DYNAMIC_ANNOTATIONS_ENABLED=1",
"WTF_USE_DYNAMIC_ANNOTATIONS=1",
]

if (current_cpu == "x64") {
# Enable libstdc++ debugging facilities to help catch problems early.
defines += [ "_GLIBCXX_DEBUG=1" ]
}
}

config("release") {
defines = [ "NDEBUG" ]
defines += [ "NVALGRIND" ]
defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
}

# Default libraries ------------------------------------------------------------

# This config defines the default libraries applied to all targets.
config("default_libs") {
if (is_linux) {
libs = [
"dl",
"pthread",
"rt",
]
}
}
31 changes: 31 additions & 0 deletions build/fuchsia/config/clang/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/fuchsia/config/clang/clang.gni")

# This adds the runtime deps for C++ for usage when cross compiling.
group("c++-runtime-deps") {
data_deps = [
":clang-runtime-libs",
]
}

copy("clang-runtime-libs") {
if (target_cpu == "arm64") {
arch = "aarch64"
} else if (target_cpu == "x64") {
arch = "x86_64"
}
vendor = "unknown"

sys = target_os
sources = [
"${clang_base_path}/lib/${arch}-${vendor}-${sys}/c++/libc++.so.2.0",
"${clang_base_path}/lib/${arch}-${vendor}-${sys}/c++/libc++abi.so.1.0",
"${clang_base_path}/lib/${arch}-${vendor}-${sys}/c++/libunwind.so.1.0",
]
outputs = [
"${root_out_dir}/lib/{{source_name_part}}",
]
}
7 changes: 7 additions & 0 deletions build/fuchsia/config/clang/clang.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

declare_args() {
clang_base_path = "//buildtools/linux-x64/clang"
}
Loading

0 comments on commit 089d6fc

Please sign in to comment.