# Copyright 2019 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")

assert(is_chromeos)

config("compiler_cpu_abi") {
  # Lacros currently uses the *-generic-crosstoolchain.gni files generated
  # by the simplechrome sdk in build/args/chromeos. These target triples
  # match the target toolchain defaults in these directories. Passing them
  # redundantly is harmless and prepares for using Chromium's toolchain.
  # Non-Lacros Chrome OS builds use per-board toolchains, which might use
  # different triples. So don't do this there.
  if (is_chromeos_device && is_chromeos_lacros) {
    if (current_cpu == "x64") {
      asmflags = [ "--target=x86_64-cros-linux-gnu" ]
      cflags = [ "--target=x86_64-cros-linux-gnu" ]
      ldflags = [ "--target=x86_64-cros-linux-gnu" ]
    } else if (current_cpu == "arm") {
      asmflags = [ "--target=armv7a-cros-linux-gnueabihf" ]
      cflags = [ "--target=armv7a-cros-linux-gnueabihf" ]
      ldflags = [ "--target=armv7a-cros-linux-gnueabihf" ]
    } else if (current_cpu == "arm64") {
      asmflags = [ "--target=aarch64-cros-linux-gnu" ]
      cflags = [ "--target=aarch64-cros-linux-gnu" ]
      ldflags = [ "--target=aarch64-cros-linux-gnu" ]
    } else {
      assert(false, "add support for $current_cpu here")
    }
  }
}

config("runtime_library") {
  # These flags are added by the Chrome OS toolchain compiler wrapper,
  # or are implicitly passed by Chome OS's toolchain's clang due to the cmake
  # flags that clang was built with.
  # Passing them redundantly is harmless and prepares for using Chromium's
  # toolchain for Lacros.
  if (is_chromeos_device) {
    ldflags = [
      "--rtlib=compiler-rt",
      "--unwindlib=libunwind",
    ]
  }
}