diff --git a/BUILD.gn b/BUILD.gn index 5ca0ff24cb5..3ff8e03ad7d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2,6 +2,8 @@ # 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/dart_host_sdk_toolchain.gni") + # This target will be built if no target is specified when invoking ninja. group("default") { if (is_fuchsia || is_fuchsia_host) { @@ -72,6 +74,14 @@ group("create_sdk") { ] } +if (dart_host_sdk_toolchain != host_toolchain) { + group("create_host_sdk") { + deps = [ + "sdk:create_sdk($dart_host_sdk_toolchain)", + ] + } +} + group("dart2js") { deps = [ "utils/compiler:dart2js", diff --git a/build/compiled_action.gni b/build/compiled_action.gni index 3951275e5ec..e332763732e 100644 --- a/build/compiled_action.gni +++ b/build/compiled_action.gni @@ -66,6 +66,8 @@ # saves unnecessarily compiling your tool for the target platform. But if you # need a target build of your tool as well, just leave off the if statement. +import("dart_host_sdk_toolchain.gni") + if (host_os == "win") { _host_executable_suffix = ".exe" } else { @@ -97,7 +99,7 @@ template("compiled_action") { outputs = invoker.outputs # Constuct the host toolchain version of the tool. - host_tool = invoker.tool + "($host_toolchain)" + host_tool = invoker.tool + "($dart_host_toolchain)" # Get the path to the executable. Currently, this assumes that the tool # does not specify output_name so that the target name is the name to use. @@ -150,7 +152,7 @@ template("compiled_action_foreach") { outputs = invoker.outputs # Constuct the host toolchain version of the tool. - host_tool = invoker.tool + "($host_toolchain)" + host_tool = invoker.tool + "($dart_host_toolchain)" # Get the path to the executable. Currently, this assumes that the tool # does not specify output_name so that the target name is the name to use. diff --git a/build/dart_host_sdk_toolchain.gni b/build/dart_host_sdk_toolchain.gni new file mode 100644 index 00000000000..95005db5eaf --- /dev/null +++ b/build/dart_host_sdk_toolchain.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2017, 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() { + # In a cross-build, this should be set to the toolchain to use to build a Dart + # SDK to run on the host that targets the host. This is distinct from + # 'host_toolchain', which in a cross-build builds artifacts to run on the host + # that target the target architecture. + dart_host_sdk_toolchain = host_toolchain +} + +# dart_host_toolchain should be used in the Dart tree instead of host_toolchain. +# It will ensure that we are selecting the correct host toolchain. +dart_host_toolchain = host_toolchain +if (current_toolchain == dart_host_sdk_toolchain) { + dart_host_toolchain = dart_host_sdk_toolchain +} diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 16f41373e6f..fdb2779eede 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -2,6 +2,7 @@ # 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/dart_host_sdk_toolchain.gni") import("runtime_args.gni") config("dart_public_config") { @@ -55,48 +56,52 @@ config("dart_no_snapshot_config") { config("dart_os_config") { defines = [] - if (target_os == "android") { - defines += [ "TARGET_OS_ANDROID" ] - } else if (target_os == "fuchsia") { - defines += [ "TARGET_OS_FUCHSIA" ] - } else if (target_os == "ios") { - defines += [ "TARGET_OS_MACOS" ] - defines += [ "TARGET_OS_MACOS_IOS" ] - } else if (target_os == "linux") { - defines += [ "TARGET_OS_LINUX" ] - } else if (target_os == "mac") { - defines += [ "TARGET_OS_MACOS" ] - } else if (target_os == "win") { - defines += [ "TARGET_OS_WINDOWS" ] - } else { - print("Unknown target_os: $target_os") - assert(false) + if (current_toolchain != dart_host_sdk_toolchain) { + if (target_os == "android") { + defines += [ "TARGET_OS_ANDROID" ] + } else if (target_os == "fuchsia") { + defines += [ "TARGET_OS_FUCHSIA" ] + } else if (target_os == "ios") { + defines += [ "TARGET_OS_MACOS" ] + defines += [ "TARGET_OS_MACOS_IOS" ] + } else if (target_os == "linux") { + defines += [ "TARGET_OS_LINUX" ] + } else if (target_os == "mac") { + defines += [ "TARGET_OS_MACOS" ] + } else if (target_os == "win") { + defines += [ "TARGET_OS_WINDOWS" ] + } else { + print("Unknown target_os: $target_os") + assert(false) + } } } config("dart_arch_config") { defines = [] - if (dart_target_arch == "arm") { - defines += [ "TARGET_ARCH_ARM" ] - } else if (dart_target_arch == "armv6") { - defines += [ "TARGET_ARCH_ARM" ] - defines += [ "TARGET_ARCH_ARM_6" ] - } else if (dart_target_arch == "armv5te") { - defines += [ "TARGET_ARCH_ARM" ] - defines += [ "TARGET_ARCH_ARM_5TE" ] - } else if (dart_target_arch == "arm64") { - defines += [ "TARGET_ARCH_ARM64" ] - } else if (dart_target_arch == "x64") { - defines += [ "TARGET_ARCH_X64" ] - } else if (dart_target_arch == "ia32" || dart_target_arch == "x86") { - defines += [ "TARGET_ARCH_IA32" ] - } else if (dart_target_arch == "dbc") { - defines += [ "TARGET_ARCH_DBC" ] - defines += [ "USING_SIMULATOR" ] - } else { - print("Invalid dart_target_arch: $dart_target_arch") - assert(false) + if (current_toolchain != dart_host_sdk_toolchain) { + if (dart_target_arch == "arm") { + defines += [ "TARGET_ARCH_ARM" ] + } else if (dart_target_arch == "armv6") { + defines += [ "TARGET_ARCH_ARM" ] + defines += [ "TARGET_ARCH_ARM_6" ] + } else if (dart_target_arch == "armv5te") { + defines += [ "TARGET_ARCH_ARM" ] + defines += [ "TARGET_ARCH_ARM_5TE" ] + } else if (dart_target_arch == "arm64") { + defines += [ "TARGET_ARCH_ARM64" ] + } else if (dart_target_arch == "x64") { + defines += [ "TARGET_ARCH_X64" ] + } else if (dart_target_arch == "ia32" || dart_target_arch == "x86") { + defines += [ "TARGET_ARCH_IA32" ] + } else if (dart_target_arch == "dbc") { + defines += [ "TARGET_ARCH_DBC" ] + defines += [ "USING_SIMULATOR" ] + } else { + print("Invalid dart_target_arch: $dart_target_arch") + assert(false) + } } } @@ -179,10 +184,10 @@ template("libdart_library") { } static_library(target_name) { configs += [ - ":dart_arch_config", - ":dart_config", - ":dart_os_config", - ] + extra_configs + ":dart_arch_config", + ":dart_config", + ":dart_os_config", + ] + extra_configs if (is_fuchsia) { configs -= [ "//build/config:symbol_visibility_hidden" ] } diff --git a/runtime/observatory/BUILD.gn b/runtime/observatory/BUILD.gn index 33573d56afd..94f0ce0c87f 100644 --- a/runtime/observatory/BUILD.gn +++ b/runtime/observatory/BUILD.gn @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("../../build/dart_host_sdk_toolchain.gni") import("../../build/executable_suffix.gni") import("../../build/prebuilt_dart_sdk.gni") import("observatory_sources.gni") @@ -10,10 +11,10 @@ import("observatory_sources.gni") pub_build_deps = [] pub_build_args = [] if (!prebuilt_dart_exe_works) { - pub_build_deps += [ "../bin:dart_bootstrap($host_toolchain)" ] + pub_build_deps += [ "../bin:dart_bootstrap($dart_host_toolchain)" ] - dart_out_dir = - get_label_info("../bin:dart_bootstrap($host_toolchain)", "root_out_dir") + dart_out_dir = get_label_info("../bin:dart_bootstrap($dart_host_toolchain)", + "root_out_dir") dart_bootstrap = rebase_path("$dart_out_dir/dart_bootstrap$executable_suffix") pub_build_args = [ diff --git a/utils/compile_platform.gni b/utils/compile_platform.gni index e539da55c6b..89169ebf7d4 100644 --- a/utils/compile_platform.gni +++ b/utils/compile_platform.gni @@ -2,6 +2,7 @@ # 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/dart_host_sdk_toolchain.gni") import("../build/prebuilt_dart_sdk.gni") _dart_root = get_path_info("..", "abspath") @@ -35,9 +36,9 @@ template("compile_platform") { depfile = outputs[0] + ".d" if (!prebuilt_dart_exe_works) { - deps += [ "$_dart_root/runtime/bin:dart_bootstrap($host_toolchain)" ] + deps += [ "$_dart_root/runtime/bin:dart_bootstrap($dart_host_toolchain)" ] dart_out_dir = get_label_info( - "$_dart_root/runtime/bin:dart_bootstrap($host_toolchain)", + "$_dart_root/runtime/bin:dart_bootstrap($dart_host_toolchain)", "root_out_dir") args += [ "--dart-executable", diff --git a/utils/compiler/BUILD.gn b/utils/compiler/BUILD.gn index 00f992150f3..2f442548b13 100644 --- a/utils/compiler/BUILD.gn +++ b/utils/compiler/BUILD.gn @@ -3,6 +3,7 @@ # BSD-style license that can be found in the LICENSE file. import("../../build/compiled_action.gni") +import("../../build/dart_host_sdk_toolchain.gni") import("../../build/prebuilt_dart_sdk.gni") import("../../utils/compile_platform.gni") import("../../utils/generate_patch_sdk.gni") @@ -84,7 +85,7 @@ generate_patched_sdk("patched_dart2js_sdk") { deps = [ # TODO(ahe): This is needed by ../../tools/patch_sdk.dart to compute # dependencies. - "../../runtime/vm:kernel_platform_files($host_toolchain)", + "../../runtime/vm:kernel_platform_files($dart_host_toolchain)", ] input_patches_dir = "../../sdk/lib/_internal/js_runtime/lib" patched_sdk_dir = "patched_dart2js_sdk" diff --git a/utils/generate_patch_sdk.gni b/utils/generate_patch_sdk.gni index f704b2407cd..95fdc46fb5d 100644 --- a/utils/generate_patch_sdk.gni +++ b/utils/generate_patch_sdk.gni @@ -2,6 +2,7 @@ # 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/dart_host_sdk_toolchain.gni") import("../build/prebuilt_dart_sdk.gni") _dart_root = get_path_info("..", "abspath") @@ -28,7 +29,7 @@ template("generate_patched_sdk") { } if (!prebuilt_dart_exe_works) { - deps += [ "$_dart_root/runtime/bin:dart_bootstrap($host_toolchain)" ] + deps += [ "$_dart_root/runtime/bin:dart_bootstrap($dart_host_toolchain)" ] } script = "$_dart_root/tools/patch_sdk.py" @@ -55,7 +56,7 @@ template("generate_patched_sdk") { args = [ "--quiet" ] if (!prebuilt_dart_exe_works) { dart_out_dir = get_label_info( - "$_dart_root/runtime/bin:dart_bootstrap($host_toolchain)", + "$_dart_root/runtime/bin:dart_bootstrap($dart_host_toolchain)", "root_out_dir") dart_bootstrap = rebase_path("$dart_out_dir/dart_bootstrap$executable_suffix") diff --git a/utils/kernel-service/BUILD.gn b/utils/kernel-service/BUILD.gn index e84716914fb..02e55ca29b2 100644 --- a/utils/kernel-service/BUILD.gn +++ b/utils/kernel-service/BUILD.gn @@ -2,12 +2,13 @@ # 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/dart_host_sdk_toolchain.gni") import("../application_snapshot.gni") application_snapshot("kernel-service") { dfe_script = "kernel-service.dart" deps = [ - "../../runtime/vm:kernel_platform_files($host_toolchain)", + "../../runtime/vm:kernel_platform_files($dart_host_toolchain)", ] main_dart = dfe_script training_args = [