# Copyright 2013 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.

import("//build/config/sysroot.gni")
import("//build/toolchain/gcc_toolchain.gni")

if (!is_arkui_x) {
  import("//build/rust/rustc_toolchain.gni")
}

clang_toolchain("clang_arm") {
  toolprefix = "arm-linux-gnueabihf-"
  toolchain_args = {
    current_cpu = "arm"
    current_os = "linux"
  }
}

clang_toolchain("clang_arm64") {
  if (host_cpu == "arm64") {
    # Output linker map files for binary size analysis.
    enable_linker_map = true

    strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir)
    shlib_extension = ".so"
  } else {
    toolprefix = "aarch64-linux-gnu-"
  }
  toolchain_args = {
    current_cpu = "arm64"
    current_os = "linux"
  }
}

clang_toolchain("clang_riscv64") {
  toolprefix = "riscv64-unknown-linux-gnu-"
  toolchain_args = {
    current_cpu = "riscv64"
    current_os = "linux"
  }
}

gcc_toolchain("arm64") {
  if (host_cpu == "arm64") {
    toolprefix = ""

    # Output linker map files for binary size analysis.
    enable_linker_map = true
  } else {
    toolprefix = "aarch64-linux-gnu-"
  }

  cc = "${toolprefix}gcc"
  cxx = "${toolprefix}g++"

  ar = "${toolprefix}ar"
  ld = cxx
  readelf = "${toolprefix}readelf"
  nm = "${toolprefix}nm"

  toolchain_args = {
    current_cpu = "arm64"
    current_os = "linux"
    is_clang = false
  }
}

gcc_toolchain("arm") {
  toolprefix = "arm-linux-gnueabihf-"

  cc = "${toolprefix}gcc"
  cxx = "${toolprefix}g++"

  ar = "${toolprefix}ar"
  ld = cxx
  readelf = "${toolprefix}readelf"
  nm = "${toolprefix}nm"

  toolchain_args = {
    current_cpu = "arm"
    current_os = "linux"
    is_clang = false
  }
}

gcc_toolchain("riscv64") {
  toolprefix = "riscv64-unknown-linux-gnu-"

  cc = "${toolprefix}gcc"
  cxx = "${toolprefix}g++"

  ar = "${toolprefix}ar"
  ld = cxx
  readelf = "${toolprefix}readelf"
  nm = "${toolprefix}nm"

  toolchain_args = {
    current_cpu = "riscv64"
    current_os = "linux"
    is_clang = false
  }
}

clang_toolchain("clang_x86") {
  # Output linker map files for binary size analysis.
  enable_linker_map = true

  toolchain_args = {
    current_cpu = "x86"
    current_os = "linux"
  }
}

gcc_toolchain("x86") {
  cc = "gcc"
  cxx = "g++"

  readelf = "readelf"
  nm = "nm"
  ar = "ar"
  ld = cxx

  # Output linker map files for binary size analysis.
  enable_linker_map = true

  toolchain_args = {
    current_cpu = "x86"
    current_os = "linux"
    is_clang = false
  }
}

clang_toolchain("clang_x64") {
  # Output linker map files for binary size analysis.
  enable_linker_map = true

  strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir)
  toolchain_args = {
    current_cpu = "x64"
    current_os = "linux"
  }
  shlib_extension = ".so"
  if (!is_arkui_x) {
    rust_abi_target = "x86_64-unknown-linux-gnu"
  }
}

gcc_toolchain("x64") {
  cc = "gcc"
  cxx = "g++"

  readelf = "readelf"
  nm = "nm"
  ar = "ar"
  ld = cxx

  # Output linker map files for binary size analysis.
  enable_linker_map = true

  toolchain_args = {
    current_cpu = "x64"
    current_os = "linux"
    is_clang = false
  }
}