Skip to content

Commit

Permalink
Reland "Revert "Add an --os=fuchsia option to build.py:""
Browse files Browse the repository at this point in the history
This reverts commit d39d4d0.

Reason for revert: Relanding with fix

Change-Id: I6d6911b6cdc578a3b576b237db94c7f1db9824b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151600
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
  • Loading branch information
liamappelbe authored and commit-bot@chromium.org committed Jun 18, 2020
1 parent ae6a489 commit 764e728
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 31 deletions.
11 changes: 11 additions & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@ deps = {
"dep_type": "cipd",
},

Var("dart_root") + "/third_party/fuchsia/sdk/linux": {
"packages": [
{
"package": "fuchsia/sdk/gn/linux-amd64",
"version": "git_revision:8d5242d4f6ff8b7634b492700e60b0fd09abefa3"
}
],
"condition": 'host_os == "linux" and host_cpu == "x64"',
"dep_type": "cipd",
},

Var("dart_root") + "/pkg/front_end/test/fasta/types/benchmark_data": {
"packages": [
{
Expand Down
15 changes: 15 additions & 0 deletions build/config/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ if (current_os == "win") {
is_nacl = false
is_posix = true
is_win = false
} else if (current_os == "fuchsia") {
is_android = false
is_chromeos = false
is_fuchsia = true
is_ios = false
is_linux = false
is_mac = false
is_nacl = false
is_posix = true
is_win = false
}

# =============================================================================
Expand Down Expand Up @@ -384,6 +394,11 @@ if (is_win) {
} else if (is_mac) {
host_toolchain = "//build/toolchain/mac:clang_x64"
set_default_toolchain(host_toolchain)
} else if (is_fuchsia) {
assert(host_os == "linux")
assert(host_cpu == "x64")
host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
set_default_toolchain("//build/toolchain/fuchsia")
}

# ==============================================================================
Expand Down
4 changes: 3 additions & 1 deletion build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ config("compiler") {
# 3. When using the sanitizers.
# Otherwise there is a performance hit, in particular on ia32.
if (is_android || is_asan || is_lsan || is_msan || is_tsan || is_ubsan ||
(is_linux && current_cpu != "x86")) {
(is_linux && current_cpu != "x86") || is_fuchsia) {
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
}
Expand Down Expand Up @@ -276,6 +276,8 @@ config("compiler") {
if (is_win) {
# Up-to-date toolchain MSVC doesn't support c++11 flag any longer.
cc_std = [ "/std:c++14" ]
} else if (is_fuchsia) {
cc_std = [ "-std=c++17" ]
} else {
cc_std = [ "-std=c++11" ]
}
Expand Down
10 changes: 10 additions & 0 deletions build/fuchsia/sdk.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
# for details. 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() {
using_fuchsia_gn_sdk = true
fuchsia_sdk_root = "//third_party/fuchsia/sdk/$host_os"
fuchsia_sdk_path = "//third_party/fuchsia/sdk/$host_os"
fuchsia_toolchain_path = "//third_party/fuchsia/toolchain/$host_os"
}
164 changes: 164 additions & 0 deletions build/toolchain/fuchsia/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
# for details. 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/config/sysroot.gni")
import("//build/toolchain/ccache.gni")
import("//build/toolchain/gcc_toolchain.gni")
import("//build/toolchain/goma.gni")

if (use_goma) {
assert(!use_ccache, "Goma and ccache can't be used together.")
compiler_prefix = "$goma_dir/gomacc "
} else if (use_ccache) {
compiler_prefix = "ccache "
} else {
compiler_prefix = ""
}

toolchain("fuchsia") {
assert(target_cpu == "x64", "We currently only support 'x64' for fuchsia.")
toolchain_bin =
rebase_path("//buildtools/$host_os-$target_cpu/clang/bin", root_out_dir)
fuchsia_sdk = rebase_path("//third_party/fuchsia/sdk/$host_os", root_out_dir)

# We can't do string interpolation ($ in strings) on things with dots in
# them. To allow us to use $cc below, for example, we create copies of
# these values in our scope.
cc = "${toolchain_bin}/clang"
cxx = "${toolchain_bin}/clang++"
ar = "${toolchain_bin}/llvm-ar"
ld = "${toolchain_bin}/clang++"
readelf = "${toolchain_bin}/llvm-readelf"
nm = "${toolchain_bin}/llvm-nm"
strip = "${toolchain_bin}/llvm-strip"

target_triple_flags = "--target=x86_64-fuchsia"
sysroot_flags = "--sysroot ${fuchsia_sdk}/arch/${target_cpu}/sysroot"
lto_flags = ""

# These library switches can apply to all tools below.
lib_switch = "-l"
lib_dir_switch = "-L"

tool("cc") {
depfile = "{{output}}.d"
command = "$compiler_prefix $cc -MD -MF $depfile $target_triple_flags $sysroot_flags $lto_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs =
[ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
}

tool("cxx") {
depfile = "{{output}}.d"
command = "$compiler_prefix $cxx -MD -MF $depfile $target_triple_flags $sysroot_flags $lto_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs =
[ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
}

tool("asm") {
depfile = "{{output}}.d"
command = "$compiler_prefix $cc -MD -MF $depfile $target_triple_flags $sysroot_flags $lto_flags {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs =
[ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
}

tool("alink") {
rspfile = "{{output}}.rsp"
command = "rm -f {{output}} && $ar rcs {{output}} @$rspfile"
description = "AR {{output}}"
rspfile_content = "{{inputs}}"
outputs =
[ "{{target_out_dir}}/{{target_output_name}}{{output_extension}}" ]
default_output_extension = ".a"
output_prefix = "lib"
}

tool("solink") {
soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
sofile = "{{root_out_dir}}/$soname" # Possibly including toolchain dir.
unstripped_sofile =
"{{root_out_dir}}/so.unstripped/$soname" # Possibly including toolchain
# dir.
rspfile = sofile + ".rsp"

# These variables are not built into GN but are helpers that implement
# (1) linking to produce a .so, (2) extracting the symbols from that file
# to a temporary file, (3) if the temporary file has differences from the
# existing .TOC file, overwrite it, otherwise, don't change it.
tocfile = sofile + ".TOC"
temporary_tocname = sofile + ".tmp"
link_command = "$compiler_prefix $ld $target_triple_flags $sysroot_flags $lto_flags -shared {{ldflags}} -o $unstripped_sofile -Wl,--build-id -Wl,-soname=$soname @$rspfile"
toc_command = "{ $readelf -d $unstripped_sofile | grep SONAME ; $nm -gD -f posix $unstripped_sofile | cut -f1-2 -d' '; } > $temporary_tocname"
replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi"
strip_command = "$strip -o $sofile $unstripped_sofile"

command =
"$link_command && $toc_command && $replace_command && $strip_command"
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"

description = "SOLINK $sofile"

default_output_extension = ".so"

output_prefix = "lib"

# Since the above commands only updates the .TOC file when it changes, ask
# Ninja to check if the timestamp actually changed to know if downstream
# dependencies should be recompiled.
restat = true

# Tell GN about the output files. It will link to the sofile but use the
# tocfile for dependency management.
outputs = [
sofile,
unstripped_sofile,
tocfile,
]

link_output = sofile
depend_output = tocfile
}

tool("link") {
exename = "{{target_output_name}}{{output_extension}}"
outfile = "{{root_out_dir}}/$exename"
rspfile = "$outfile.rsp"
unstripped_outfile = "{{root_out_dir}}/exe.stripped/$exename"
command = "$compiler_prefix $ld $target_triple_flags $sysroot_flags $lto_flags {{ldflags}} -o $unstripped_outfile -Wl,--build-id -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}} && ${strip} -o $outfile $unstripped_outfile"
description = "LINK $outfile"
rspfile_content = "{{inputs}}"
outputs = [
unstripped_outfile,
outfile,
]
}

tool("stamp") {
command = "touch {{output}}"
description = "STAMP {{output}}"
}

tool("copy") {
command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
description = "COPY {{source}} {{output}}"
}

# When invoking this toolchain not as the default one, these args will be
# passed to the build. They are ignored when this is the default toolchain.
toolchain_args = {
current_cpu = target_cpu
current_os = target_os

# These values need to be passed through unchanged.
target_os = target_os
target_cpu = target_cpu

is_clang = true
}
}
12 changes: 10 additions & 2 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ config("dart_config") {
}

if (is_fuchsia) {
if (using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
lib_dirs = [ "../out/DebugFuchsiaX64/lib" ]
}
if (using_fuchsia_gn_sdk || using_fuchsia_sdk) {
# TODO(chinmaygarde): Currenty these targets need to be build in the
# Fuchsia tree as well as outside it using the SDK. However, not all
# Fuchsia features are available in the SDK. As these features are added,
Expand Down Expand Up @@ -223,7 +226,12 @@ library_for_all_configs("libdart") {
defines = [ "DART_ENABLE_WASM" ]
}
if (is_fuchsia) {
if (using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
extra_deps += [
"$fuchsia_sdk_root/pkg/fdio",
"$fuchsia_sdk_root/pkg/trace-engine",
]
} else if (using_fuchsia_sdk) {
extra_deps += [
"$fuchsia_sdk_root/pkg:fdio",
"$fuchsia_sdk_root/pkg:trace-engine",
Expand Down
30 changes: 25 additions & 5 deletions runtime/bin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ template("build_libdart_builtin") {
public_configs = [ ":libdart_builtin_config" ]
deps = []
if (is_fuchsia) {
if (using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
public_deps = [ "$fuchsia_sdk_root/pkg/fdio" ]
} else if (using_fuchsia_sdk) {
public_deps = [ "$fuchsia_sdk_root/pkg:fdio" ]
} else {
public_deps = [ "//zircon/public/lib/fdio" ]
Expand Down Expand Up @@ -314,7 +316,13 @@ template("build_gen_snapshot_dart_io") {
deps = []

if (is_fuchsia) {
if (using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
deps += [
"$fuchsia_sdk_root/fidl/fuchsia.netstack",
"$fuchsia_sdk_root/pkg/sys_cpp",
]
public_deps = [ "$fuchsia_sdk_root/pkg/fdio" ]
} else if (using_fuchsia_sdk) {
deps += [
"$fuchsia_sdk_root/fidl:fuchsia.netstack",
"$fuchsia_sdk_root/pkg:sys_cpp",
Expand Down Expand Up @@ -450,7 +458,13 @@ template("dart_io") {
deps += [ "//third_party/boringssl" ]

if (is_fuchsia) {
if (using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
deps += [
"$fuchsia_sdk_root/fidl/fuchsia.netstack",
"$fuchsia_sdk_root/pkg/sys_cpp",
]
public_deps = [ "$fuchsia_sdk_root/pkg/fdio" ]
} else if (using_fuchsia_sdk) {
deps += [
"$fuchsia_sdk_root/fidl:fuchsia.netstack",
"$fuchsia_sdk_root/pkg:sys_cpp",
Expand Down Expand Up @@ -779,7 +793,9 @@ template("dart_executable") {
# have them. They are needed for running Fuchsia binaries built for the
# host.
if (is_linux) {
configs += [ "../../build/config/gcc:executable_ldconfig" ]
# TODO(liama): Commenting this line out because it causes problems for
# --os=fuchsia. If no one complains, remove it.
# configs += [ "../../build/config/gcc:executable_ldconfig" ]
} else if (is_mac) {
configs += [ "../../build/config/mac:mac_dynamic_flags" ]
}
Expand Down Expand Up @@ -1007,7 +1023,11 @@ executable("run_vm_tests") {
}

if (is_fuchsia) {
if (!using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
include_dirs += [ "$fuchsia_sdk_path/pkg/trace-engine/include" ]
libs = [ "zircon" ]
}
if (!using_fuchsia_gn_sdk && !using_fuchsia_sdk) {
deps += [ "//zircon/system/ulib/trace" ]
}
}
Expand Down
10 changes: 7 additions & 3 deletions runtime/bin/process_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -744,16 +744,20 @@ class ProcessStarter {
}
actions[3] = {
.action = FDIO_SPAWN_ACTION_SET_NAME,
.name.data = program_arguments_[0],
.name = {
.data = program_arguments_[0],
},
};

// Then fill in the namespace actions.
if (ns != nullptr) {
for (size_t i = 0; i < flat_ns->count; i++) {
actions[fixed_actions_cnt + i] = {
.action = FDIO_SPAWN_ACTION_ADD_NS_ENTRY,
.ns.prefix = flat_ns->path[i],
.ns.handle = flat_ns->handle[i],
.ns = {
.prefix = flat_ns->path[i],
.handle = flat_ns->handle[i],
},
};
}
free(flat_ns);
Expand Down
4 changes: 4 additions & 0 deletions runtime/bin/snapshot_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ static AppSnapshot* TryReadAppSnapshotElf(
*isolate_data_buffer = nullptr,
*isolate_instructions_buffer = nullptr;
Dart_LoadedElf* handle = nullptr;
#if !defined(HOST_OS_FUCHSIA)
if (force_load_elf_from_memory) {
#endif
File* const file =
File::Open(/*namespc=*/nullptr, script_name, File::kRead);
if (file == nullptr) return nullptr;
Expand All @@ -216,11 +218,13 @@ static AppSnapshot* TryReadAppSnapshotElf(
&isolate_data_buffer, &isolate_instructions_buffer);
delete memory;
file->Release();
#if !defined(HOST_OS_FUCHSIA)
} else {
handle = Dart_LoadELF(script_name, file_offset, &error, &vm_data_buffer,
&vm_instructions_buffer, &isolate_data_buffer,
&isolate_instructions_buffer);
}
#endif
if (handle == nullptr) {
Syslog::PrintErr("Loading failed: %s\n", error);
return nullptr;
Expand Down
4 changes: 3 additions & 1 deletion runtime/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ library_for_all_configs("libdart_platform") {
extra_deps = []

if (is_fuchsia) {
if (using_fuchsia_sdk) {
if (using_fuchsia_gn_sdk) {
extra_deps += [ "$fuchsia_sdk_root/pkg/sys_cpp" ]
} else if (using_fuchsia_sdk) {
extra_deps += [ "$fuchsia_sdk_root/pkg:sys_cpp" ]
} else {
extra_deps += [ "//sdk/lib/sys/cpp" ]
Expand Down
Loading

0 comments on commit 764e728

Please sign in to comment.