15f9996aaSopenharmony_ci# Copyright 2016 The Chromium Authors. All rights reserved.
25f9996aaSopenharmony_ci# Use of this source code is governed by a BSD-style license that can be
35f9996aaSopenharmony_ci# found in the LICENSE file.
45f9996aaSopenharmony_ci
55f9996aaSopenharmony_ciimport("//build/config/sanitizers/sanitizers.gni")
65f9996aaSopenharmony_ci
75f9996aaSopenharmony_cideclare_args() {
85f9996aaSopenharmony_ci  # This arg is used when we want to tell the JIT-generating v8 code
95f9996aaSopenharmony_ci  # that we want to have it generate for an architecture that is different
105f9996aaSopenharmony_ci  # than the architecture that v8 will actually run on; we then run the
115f9996aaSopenharmony_ci  # code under an emulator. For example, we might run v8 on x86, but
125f9996aaSopenharmony_ci  # generate arm code and run that under emulation.
135f9996aaSopenharmony_ci  #
145f9996aaSopenharmony_ci  # This arg is defined here rather than in the v8 project because we want
155f9996aaSopenharmony_ci  # some of the common architecture-specific args (like arm_float_abi or
165f9996aaSopenharmony_ci  # mips_arch_variant) to be set to their defaults either if the current_cpu
175f9996aaSopenharmony_ci  # applies *or* if the v8_current_cpu applies.
185f9996aaSopenharmony_ci  #
195f9996aaSopenharmony_ci  # As described below, you can also specify the v8_target_cpu to use
205f9996aaSopenharmony_ci  # indirectly by specifying a `custom_toolchain` that contains v8_$cpu in the
215f9996aaSopenharmony_ci  # name after the normal toolchain.
225f9996aaSopenharmony_ci  #
235f9996aaSopenharmony_ci  # For example, `gn gen --args="custom_toolchain=...:clang_x64_v8_arm64"`
245f9996aaSopenharmony_ci  # is equivalent to setting --args=`v8_target_cpu="arm64"`. Setting
255f9996aaSopenharmony_ci  # `custom_toolchain` is more verbose but makes the toolchain that is
265f9996aaSopenharmony_ci  # (effectively) being used explicit.
275f9996aaSopenharmony_ci  #
285f9996aaSopenharmony_ci  # v8_target_cpu can only be used to target one architecture in a build,
295f9996aaSopenharmony_ci  # so if you wish to build multiple copies of v8 that are targeting
305f9996aaSopenharmony_ci  # different architectures, you will need to do something more
315f9996aaSopenharmony_ci  # complicated involving multiple toolchains along the lines of
325f9996aaSopenharmony_ci  # custom_toolchain, above.
335f9996aaSopenharmony_ci  v8_target_cpu = ""
345f9996aaSopenharmony_ci}
355f9996aaSopenharmony_ci
365f9996aaSopenharmony_ciif (v8_target_cpu == "") {
375f9996aaSopenharmony_ci  if (current_toolchain == "//build/toolchain/linux:clang_x64_v8_arm64") {
385f9996aaSopenharmony_ci    v8_target_cpu = "arm64"
395f9996aaSopenharmony_ci  } else if (current_toolchain == "//build/toolchain/linux:clang_x86_v8_arm") {
405f9996aaSopenharmony_ci    v8_target_cpu = "arm"
415f9996aaSopenharmony_ci  } else if (current_toolchain ==
425f9996aaSopenharmony_ci             "//build/toolchain/linux:clang_x64_v8_x86_64") {
435f9996aaSopenharmony_ci    v8_target_cpu = "x86_64"
445f9996aaSopenharmony_ci  } else if (is_msan) {
455f9996aaSopenharmony_ci    # If we're running under a sanitizer, if we configure v8 to generate
465f9996aaSopenharmony_ci    # code that will be run under a simulator, then the generated code
475f9996aaSopenharmony_ci    # also gets the benefits of the sanitizer.
485f9996aaSopenharmony_ci    v8_target_cpu = "arm64"
495f9996aaSopenharmony_ci  } else {
505f9996aaSopenharmony_ci    v8_target_cpu = target_cpu
515f9996aaSopenharmony_ci  }
525f9996aaSopenharmony_ci}
535f9996aaSopenharmony_ci
545f9996aaSopenharmony_cideclare_args() {
555f9996aaSopenharmony_ci  # This argument is declared here so that it can be overridden in toolchains.
565f9996aaSopenharmony_ci  # It should never be explicitly set by the user.
575f9996aaSopenharmony_ci  v8_current_cpu = v8_target_cpu
585f9996aaSopenharmony_ci}
59