blob: 8bf52219467e8897faa72c378b40f2be8679758e [file]
# Copyright 2022 The Fuchsia 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/assembly/developer_overrides.gni")
import("//build/bazel/bazel_action.gni")
import("//build/bazel/bazel_content_hashes.gni")
import("//build/bazel/bazel_inputs.gni")
import("//build/bazel/bazel_root_targets.gni")
import("//build/bazel/bazel_workspace.gni")
import("//build/bazel/generate_content_hash_file.gni")
import("//build/bazel/generate_prebuilt_dir_content_hash.gni")
import("//build/bazel/remote_services.gni")
import("//build/config/clang/clang.gni")
import("//build/images/vbmeta.gni")
import("//build/info/info.gni")
import("//build/product.gni")
import("//src/connectivity/policy/netcfg/delegated_network_provisioning.gni")
assert(
current_toolchain == default_toolchain,
"This BUILD.gn file should only be parsed in the default toolchain, to prevent generating Bazel workspace multiple times.")
# LINT.IfChange(fuchsia_internal_only_idk_hash)
generate_content_hash_file("fuchsia_internal_only_idk.hash") {
source_paths = [ "$root_build_dir/sdk/exported/bazel_internal_only_idk" ]
deps = [ "//sdk:bazel_internal_only_idk" ]
}
# LINT.ThenChange(//build/bazel/scripts/workspace_utils.py)
# Write the content of bazel_content_hash_definitions to a JSON file
# at `gn gen` time.
generated_file("bazel_content_hashes_json") {
outputs = [ "$root_build_dir/bazel_content_hashes.json" ]
contents = bazel_content_hash_definitions
output_conversion = "json"
}
# Generate content hash files for python and Clang toolchains.
#
# These will be used to trigger new runs of the bazel_sdk_test_xxx targets
# if the content of these directory changes. And the
# //build/bazel_sdk/tests/script/bazel_test.py script will ensure that their
# values are passed to the test workspace.
#
generate_prebuilt_dir_content_hash(prebuilt_content_hash_targets.python) {
source_dir = "//prebuilt/third_party/python3/${host_os}-${host_cpu}"
output = prebuilt_content_hash_files.python
cipd_name = "cpython3"
exclude_suffixes = [ ".pyc" ]
}
generate_prebuilt_dir_content_hash(prebuilt_content_hash_targets.clang) {
# clang_prefix points to the "bin" directory in clang toolchain, so go one
# level up to get the clang root dir.
source_dir = get_path_info(clang_prefix, "dir")
output = prebuilt_content_hash_files.clang
cipd_name = "clang"
}
# Pass the map of which developer overrides to use with which assembly label to
# Bazel.
generated_file("assembly_developer_overrides") {
outputs = [ "${root_gen_dir}/assembly_developer_overrides.json" ]
contents = all_product_assembly_overrides
output_conversion = "json"
}
group("tests") {
testonly = true
deps = [
"bazel_sdk:tests",
"fuchsia_idk:tests",
"scripts:tests",
]
}
# bazel_action_allowlist is a list of all GN actions that invoke Bazel.
#
# To convert/add new Bazel targets, instead of adding to this list, prefer:
#
# 1. Expanding existing bazel_build_groups in GN
# 2. Add targets as deps in the Bazel build graph
#
# NOTE: Bazel actions in GN are known to introduce performance overheads in
# builds when they are included. Each included bazel action is expected to make
# the entire build O(seconds) slower. While the Fuchsia build team is working on
# improving this, please request a review with us if you want to change this
# list.
group("bazel_action_allowlist") {
# Bazel assembly
visibility = [
"//boards/pkvm:*",
"//boards/vim3:*",
"//products/core:*",
"//products/microfuchsia:*",
"//products/minimal:*",
"//products/terminal:*",
"//products/workbench:*",
"//products/zedboot:*",
]
# Bazel assembly used in tests
visibility += [ "//build/images/updates/tests:bazel_pb_bazel_build_group" ]
# Bazel build related targets
visibility += [
"//build/bazel/assembly:verify_assembly_configs.bazel_build_group",
"//build/bazel/bazel_sdk:in_tree_fuchsia_sdk",
"//build/bazel/bazel_sdk:verify_fuchsia_sdk_repository",
"//build/bazel/bazel_sdk/docs:docs.bazel_build_group",
"//build/bazel/examples:*",
"//build/bazel/examples/hello_no_sdk",
"//build/bazel/examples/hello_world",
"//build/bazel/host:bazel_root_targets",
"//build/bazel/host:sdk_host_tools_arm64",
]
visibility += [ "//vendor/*" ]
visibility += [ "//local/*" ]
visibility += [
"//boards/vim3:bazel_drivers",
"//examples/assembly/*",
"//examples/drivers:bazel_drivers",
"//examples/drivers:bazel_test_packages.bazel_build",
"//sdk:final_fuchsia_idk.exported",
"//sdk/lib/driver/devicetree/examples/example-board:bazel_package.bazel_build",
"//src:bazel_tests.bazel_build",
"//src/devices/block/drivers/aml-sdmmc:aml-sdmmc-no-banjo-bazel-package.bazel_build",
"//src/devices/board/drivers/vim3-devicetree:bazel_package.bazel_build",
"//src/devices/clock/drivers/vim3-clk:bazel_package.bazel_build",
"//src/devices/gpio/drivers/aml-gpio:bazel_package.bazel_build",
"//src/devices/i2c/drivers/aml-i2c:bazel_package.bazel_build",
"//src/devices/usb/drivers/aml-usb-phy:bazel_package.bazel_build",
"//src/devices/usb/drivers/dwc3:bazel_package.bazel_build",
"//src/media/audio/drivers/aml-g12-tdm:aml-g12-composite-bazel-package.bazel_build",
"//src/ui/input/drivers/adc-buttons:bazel_package.bazel_build",
]
}
group("bazel_root_targets") {
public_deps = [
":bazel_root_targets_json",
"//build/bazel/host:bazel_root_host_tools(${host_toolchain})",
]
}
generated_file("bazel_root_targets_json") {
outputs = [ "$root_build_dir/bazel_root_targets.json" ]
contents = resolved_bazel_root_targets
output_conversion = "json"
}
# Generates a file containing information about the GN build variables
# that need to be exported to Bazel. They will be included in the `args.bzl`
# file generated by `generate_fuchsia_build_info()` and appear as Bazel Starlark
# constants available through @fuchsia_build_info//:args.bzl.
#
# For each such variable, specify its name, its value (as determined after all
# GN processing, including `args.gn`), its type, and the location where it is
# declared.
#
# The type is one of the following values, describing its type and how the
# corresponding GN value will be mapped to Starlark.
#
# - bool: A Boolean flag, mapped to True or False
# - string: A string, mapped to a Starlark string.
# - string_or_false: Either the false Boolean value, or a string. Always
# mapped to a Starlark string (false will be mapped to the empty string).
# - array_of_strings: An array of strings, mapped to a Starlark list of
# strings. The array must not contain a mix of types, such as integers
# and strings.
# - path: A string beginning with "//", mapped to a string with the "//"
# stripped, or a string containing an absolute path "/".
generated_file("gn_build_variables_for_bazel") {
outputs = [ "$root_build_dir/gn_build_variables_for_bazel.json" ]
output_conversion = "json"
contents = []
# Do not import this special case.
declaration = "args.gn"
contents += [
{
name = "target_cpu"
value = target_cpu
type = "string"
location = declaration
},
]
# LINT.IfChange
declaration = "//build/images/vbmeta.gni"
import(declaration)
contents += [
{
name = "use_vbmeta"
value = use_vbmeta
type = "bool"
location = declaration
},
]
# LINT.ThenChange(//build/images/vbmeta.gni)
# LINT.IfChange
declaration =
"//src/connectivity/policy/netcfg/delegated_network_provisioning.gni"
import(declaration)
contents += [
{
name = "delegated_network_provisioning"
value = delegated_network_provisioning
type = "bool"
location = declaration
},
]
# LINT.ThenChange(//src/connectivity/policy/netcfg/delegated_network_provisioning.gni)
# LINT.IfChange
declaration = "//build/info/info.gni"
import(declaration)
contents += [
{
name = "build_info_board"
value = build_info_board
type = "string"
location = declaration
},
{
name = "build_info_product"
value = build_info_product
type = "string"
location = declaration
},
{
name = "build_info_version"
value = build_info_version
type = "string"
location = declaration
},
{
name = "truncate_build_info_commit_date"
value = truncate_build_info_commit_date
type = "bool"
location = declaration
},
]
# LINT.ThenChange(//build/info/info.gni)
# LINT.IfChange
declaration = "//build/config/clang/clang_prefix.gni"
import(declaration)
contents += [
{
name = "clang_prefix"
value = clang_prefix
type = "path"
location = declaration
},
]
# LINT.ThenChange(//build/config/clang/clang_prefix.gni)
# LINT.IfChange
declaration = "//build/config/compilation_modes.gni"
import(declaration)
contents += [
{
name = "compilation_mode"
value = compilation_mode
type = "string"
location = declaration
},
]
# LINT.ThenChange(//build/config/compilation_modes.gni)
# LINT.IfChange
declaration = "//sdk/config.gni"
import(declaration)
contents += [
{
name = "sdk_id"
value = sdk_id
type = "string"
location = declaration
},
]
# LINT.ThenChange(//sdk/config.gni)
# LINT.IfChange
declaration = "//build/sdk/config.gni"
import(declaration)
contents += [
{
name = "idk_buildable_cpus"
value = idk_buildable_cpus
type = "array_of_strings"
location = declaration
},
{
name = "warn_on_sdk_changes"
value = warn_on_sdk_changes
type = "bool"
location = declaration
},
]
# LINT.ThenChange(//build/sdk/config.gni)
# BEGIN platform_version.gni
# LINT.IfChange(platform_version)
declaration = "//build/config/fuchsia/platform_version.gni"
import(declaration)
# GN supports a list of both integers and strings. Ensure all levels are
# strings as required by Bazel.
string_buildable_api_levels = []
foreach(api_level, idk_buildable_api_levels) {
string_buildable_api_levels += [ "${api_level}" ]
}
contents += [
{
name = "idk_buildable_api_levels"
value = string_buildable_api_levels
type = "array_of_strings"
location = declaration
},
]
# LINT.ThenChange(//build/config/fuchsia/platform_version.gni)
# LINT.IfChange(get_platform_version)
# This GN arg is defined in a Python file exposed through the .gni file above.
# GN supports a list of both integers and strings. Ensure all levels are
# strings as required by Bazel.
string_runtime_api_levels = []
foreach(api_level, platform_version.runtime_supported_api_levels) {
string_runtime_api_levels += [ "${api_level}" ]
}
contents += [
{
name = "runtime_supported_api_levels"
value = string_runtime_api_levels
type = "array_of_strings"
location = declaration
},
]
# LINT.ThenChange(//build/config/fuchsia/get_platform_version.py)
# END platform_version.gni
# LINT.IfChange
declaration = "//build/testing/config.gni"
import(declaration)
contents += [
{
name = "update_goldens"
value = update_goldens
type = "bool"
location = declaration
},
]
# LINT.ThenChange(//build/testing/config.gni)
}
if (current_toolchain == default_toolchain) {
group("bazel_args_json") {
deps = [
"//build/bazel/config:bazel_args_json($default_toolchain)",
"//build/bazel/config:bazel_args_json($host_toolchain)",
]
}
}