a7d8ff38创建于 2024年4月20日历史提交
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Toolchain-related configuration that may be needed outside the context of the
# toolchain() rules themselves.

import("//build/misc/overrides/build.gni")

declare_args() {
  # If this is set to true, or if LLVM_FORCE_HEAD_REVISION is set to 1
  # in the environment, we use the revision in the llvm repo to determine
  # the CLANG_REVISION to use, instead of the version hard-coded into
  # //tools/clang/scripts/update.py. This should only be used in
  # conjunction with setting LLVM_FORCE_HEAD_REVISION in the
  # environment when `gclient runhooks` is run as well.
  llvm_force_head_revision = false

  # Compile with Xcode version of clang instead of hermetic version shipped
  # with the build. Used on iOS to ship official builds (as they are built
  # with the version of clang shipped with Xcode).
  use_xcode_clang = false

  # Compile with Android SDK version of clang instead of hermetic version shipped
  # with the build. Used on Android to ship official builds (as they are built
  # with the version of clang shipped with Android SDK).
  use_android_clang = false

  # Used for binary size analysis.
  # Currently disabled on LLD because of a bug (fixed upstream).
  # See https://crbug.com/716209.
  generate_linker_map = is_ohos && is_official_build

  # Use absolute file paths in the compiler diagnostics and __FILE__ macro
  # if needed.
  msvc_use_absolute_paths = false
}

if (generate_linker_map) {
  assert(
      is_official_build,
      "Linker map files should only be generated when is_official_build = true")
  assert(current_os == "ohos" || target_os == "linux",
         "Linker map files should only be generated for ohos and Linux")
}

# The path to the hermetic install of Xcode. Only relevant when
hermetic_xcode_path =
    rebase_path("//build/${target_os}_files/Xcode.app", "", root_build_dir)

declare_args() {
  if (is_clang) {
    # Clang compiler version. Clang files are placed at version-dependent paths.
    clang_version = "15.0.4"
  }
  use_custom_clang = true
}

# Check target_os here instead of is_ios as this file is loaded for secondary
# toolchain (host toolchain in particular) but the argument is the same for
# all toolchains.
assert(!use_xcode_clang || target_os == "ios",
       "Using Xcode's clang is only supported in iOS builds")

# Extension for shared library files (including leading dot).
executable_extension = ""
if (is_mac) {
  shlib_extension = ".dylib"
  dylib_extension = ".dylib.so"
  rlib_extension = ".rlib"
} else if (is_ohos && is_component_build) {
  # By appending .z, we prevent name collisions with libraries already loaded by the ohos.
  shlib_extension = ".z.so"
  dylib_extension = ".dylib.so"
  rlib_extension = ".rlib"
} else if (is_mingw) {
  shlib_extension = ".dll"
  executable_extension = ".exe"
  dylib_extension = ".dll"
  rlib_extension = ".rlib"
} else if (is_posix) {
  shlib_extension = ".so"
  dylib_extension = ".dylib.so"
  rlib_extension = ".rlib"
} else if (is_win) {
  shlib_extension = ".dll"
} else {
  assert(false, "Platform not supported")
}

# Prefix for shared library files.
if (is_posix) {
  shlib_prefix = "lib"
} else {
  shlib_prefix = ""
}

# While other "tool"s in a toolchain are specific to the target of that
# toolchain, the "stamp" and "copy" tools are really generic to the host;
# but each toolchain must define them separately.  GN doesn't allow a
# template instantiation inside a toolchain definition, so some boilerplate
# has to be repeated in each toolchain to define these two tools.  These
# four variables reduce the duplication in that boilerplate.
stamp_description = "STAMP {{output}}"
copy_description = "COPY {{source}} {{output}}"
if (host_os == "win") {
  _tool_wrapper_path =
      rebase_path("//build/toolchain/win/tool_wrapper.py", root_build_dir)
  stamp_command = "cmd /c type nul > \"{{output}}\""
  copy_command =
      "$python_path $_tool_wrapper_path recursive-mirror {{source}} {{output}}"
} else {
  stamp_command = "touch {{output}}"
  copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
}