blob: 62cf43d52395df4faa0b4319e56fc6a89e7cd576 [file] [log] [blame]
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This build configuration extends GN's cross-compilation concepts of "target",
# "host" and "current" with "arch" which is used to refer to the embedded
# architecture that the bare metal images are being built for.
#
# The concepts of "target", "host" and "current" are used when bulding tests
# and utilities for the non-embedded device. Note that there hasn't been any
# thought given to support building for anything other than the host so it
# probably won't work.
#
# In summary:
# - host{_os,_cpu,_toolchain} is for the system running the build
# - target{_os,_cpu,_toolchain} is for the system that will run utilities and tests
# - arch{,_toolchain} is for the embedded system that will run the bare metal images
# Configuration of the build toolchain.
declare_args() {
# Enable extra debugging.
is_debug = true
# Set to true to build with gcc (default is clang).
use_gcc = false
# The architecture to build the bare metal images for.
arch = ""
# Set by arch toolchain. Prefix for binutils tools.
arch_tool_prefix = ""
}
# Check that we support the attempted build
assert(host_os == "linux", "Only linux builds are currently supported")
# Check that the requested architecture is supported
assert(arch == "aarch64" || arch == "fake", "Unsupported arch: $arch")
# Setup the standard variables
if (target_os == "") {
target_os = host_os
}
if (target_cpu == "") {
target_cpu = host_cpu
}
if (current_os == "") {
current_os = target_os
}
if (current_cpu == "") {
current_cpu = target_cpu
}
assert(target_os == host_os, "Cross compiles not yet supported")
assert(target_cpu == host_cpu, "Cross compiles not yet supported")
# All binary targets will get this list of configs by default
_shared_binary_target_configs = [
"//build:compiler_defaults",
"//build:sections",
"//build:lto",
]
# Apply that default list to the binary target types.
set_defaults("executable") {
configs = _shared_binary_target_configs
# Executables get this additional configuration
configs += [ "//build:executable_ldconfig" ]
}
set_defaults("static_library") {
configs = _shared_binary_target_configs
}
set_defaults("shared_library") {
configs = _shared_binary_target_configs
}
set_defaults("source_set") {
configs = _shared_binary_target_configs
}
# Select host, target and arch toolchains
if (use_gcc) {
host_toolchain = "//build/toolchain/host:gcc"
target_toolchain = "//build/toolchain/host:gcc"
fake_toolchain = "//build/toolchain/host:gcc_fake_arch"
arch_toolchain = "//build/toolchain/arch:gcc_${arch}"
} else {
host_toolchain = "//build/toolchain/host:clang"
target_toolchain = "//build/toolchain/host:clang"
fake_toolchain = "//build/toolchain/host:clang_fake_arch"
arch_toolchain = "//build/toolchain/arch:clang_${arch}"
}
# The default toolchain is the target toolchain for building utilities and tests
set_default_toolchain(target_toolchain)