blob: b3ca528932cb362a4a3cd7da419a09d316b5270d [file] [log] [blame]
# Copyright 2020 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/compiled_action.gni")
import("//build/fidl/fidl.gni")
import("//build/rust/rustc_library.gni")
import("//build/testing/golden_files.gni")
import("//zircon/tools/zither/zither_golden_files.gni")
import("vdso.gni")
public_generated = [
{
arg = "--public-header"
output = "internal/cdecls.inc"
},
{
arg = "--next-public-header"
output = "internal/cdecls-next.inc"
},
]
testonly_generated = [
{
arg = "--testonly-public-header"
output = "internal/testonly-cdecls.inc"
},
]
private_generated = [
{
arg = "--category"
output = "category.inc"
},
{
arg = "--syscall-numbers"
output = "zx-syscall-numbers.h"
},
{
arg = "--kernel-header"
output = "kernel.inc"
},
{
arg = "--kernel-wrappers"
output = "kernel-wrappers.inc"
},
{
arg = "--private-header"
output = "syscalls.inc"
},
]
go_generated = [
{
arg = "--go-syscall-stubs"
output = "src/syscall/zx/syscalls_fuchsia.go"
},
{
arg = "--go-syscall-arm64-asm"
output = "src/syscall/zx/syscalls_fuchsia_arm64.s"
},
{
arg = "--go-syscall-x86-asm"
output = "src/syscall/zx/syscalls_fuchsia_amd64.s"
},
{
arg = "--go-vdso-keys"
output = "src/runtime/vdso_keys_fuchsia.go"
},
{
arg = "--go-vdso-arm64-calls"
output = "src/runtime/vdsocalls_fuchsia_arm64.s"
},
{
arg = "--go-vdso-x86-calls"
output = "src/runtime/vdsocalls_fuchsia_amd64.s"
},
]
rust_generated = [
{
arg = "--rust"
output = "zircon/rust/syscalls/definitions.rs"
},
]
group("vdso") {
deps = [ ":zx($fidl_toolchain)" ]
}
group("tests") {
testonly = true
deps = [ ":goldens($default_toolchain)" ]
}
# This is the zx library used by internal FIDL backends. For the library
# imported by `using zx;` in regular FIDL libraries, see
# //zircon/vdso/zx/BUILD.gn.
fidl("zx") {
visibility = [
":*",
"//zircon/tools/zither:tests",
]
sources = [
"bti.fidl",
"cache.fidl",
"channel.fidl",
"clock.fidl",
"cprng.fidl",
"debug.fidl",
"debuglog.fidl",
"errors.fidl",
"event.fidl",
"eventpair.fidl",
"exception.fidl",
"fifo.fidl",
"framebuffer.fidl",
"futex.fidl",
"guest.fidl",
"handle.fidl",
"interrupt.fidl",
"iommu.fidl",
"ioports.fidl",
"job.fidl",
"ktrace.fidl",
"misc.fidl",
"msi.fidl",
"mtrace.fidl",
"object.fidl",
"overview.fidl",
"pager.fidl",
"pc.fidl",
"pci.fidl",
"pmt.fidl",
"port.fidl",
"process.fidl",
"profile.fidl",
"resource.fidl",
"restricted.fidl",
"rights.fidl",
"smc.fidl",
"socket.fidl",
"stream.fidl",
"syscall.fidl",
"system.fidl",
"task.fidl",
"thread.fidl",
"timer.fidl",
"vcpu.fidl",
"vmar.fidl",
"vmo.fidl",
"zx_common.fidl",
]
# TODO(fxbug.dev/110021): Burn these down.
experimental_flags = [ "zx_c_types" ]
# TODO(fxbug.dev/109734): Burn these down.
excluded_checks = [ "vector-bounds-not-specified" ]
}
zither_golden_files("ifs") {
fidl = ":zx"
backend = "zircon_ifs"
goldens = [ "//src/zircon/lib/zircon/zircon.ifs" ]
}
# TODO(fxbug.dev/51002): Consumption of this header in assembly should be
# migrated over to using the assembly backend directly, at which point this
# header should be generated by the C backend, complete with C-style casts.
zither_golden_files("zx.asm.checked-in") {
fidl = ":zx"
backend = "asm"
goldens = [ "//zircon/system/public/zircon/errors.h" ]
}
# Depended on by //zircon/public/sysroot/sdk:sysroot_sdk.
group("sysroot_sdk") {
deps = [ ":zx.asm.checked-in" ]
}
# TODO(joshuaseaton): Do not let our use of a "library zx" here propagate up to
# SDK build logic that would then consider this an "SDK library": there is
# already another library zx in the SDK and so this prevents collision.
barrier_metadata = {
fidl_json_barrier = []
}
# This provides the public headers that go with the vDSO API, which are
# seen as <zircon/...>.
group("public") {
visibility = [
"//src/zircon/lib/zircon/*",
"//zircon/kernel/lib/userabi/vdso/*",
"//zircon/public/sysroot/*",
]
public_configs = [ ":public.config" ]
public_deps = [ ":generate($default_toolchain)" ]
metadata = barrier_metadata
}
default_root_gen_dir =
get_label_info(":anything($default_toolchain)", "root_gen_dir")
syscall_public_gen_dir = "$default_root_gen_dir/include/zircon/syscalls"
config("public.config") {
visibility = [ ":public" ]
include_dirs = [ "$default_root_gen_dir/include" ]
}
# This provides the private headers used by the kernel and vDSO
# implementation, which are seen as <lib/syscalls/...>.
group("private") {
visibility = [
"//zircon/kernel/lib/syscalls/*",
"//zircon/kernel/lib/userabi/*",
"//zircon/system/ulib/syscalls-headers/*",
]
public_configs = [ ":private.config" ]
public_deps = [ ":generate($default_toolchain)" ]
metadata = barrier_metadata
}
default_target_gen_dir =
get_label_info(":anything($default_toolchain)", "target_gen_dir")
syscall_private_gen_dir = "$default_target_gen_dir/include/lib/syscalls"
config("private.config") {
visibility = [ ":private" ]
include_dirs = [ "$default_target_gen_dir/include" ]
}
syscall_rust_gen_dir = "$default_target_gen_dir"
rustc_library("fuchsia-zircon-sys") {
version = "0.3.3"
edition = "2018"
generated = rust_generated[0]
source_root = "$syscall_rust_gen_dir/" + generated.output
sources = [ source_root ]
deps = [
":generate($default_toolchain)",
"//src/lib/zircon/rust:fuchsia-zircon-types",
]
visibility = [
":*",
# //src/lib/zircon/rust:fuchsia-zircon re-exports the contents of this
# crate.
"//src/lib/zircon/rust:*",
]
metadata = barrier_metadata
}
# The kazoo compiler translates FIDL's IR into syscall-oriented outputs.
# These are logically distinct things that are used by different modules in
# the kernel or in public library code. But they all depend on the same
# inputs, the front-end work is the same for each one, and the back-end
# work is not very costly. So doing a single kazoo run to generate them
# all together is faster than parallelizing the independent generation
# steps that duplicate redundant process overhead and front-end work.
# Helper template to invoke Kazoo.
#
# Parameters
#
# * public_gen_dir
# - Required: The directory under which the public source will be
# generated.
# - Type: path
#
# * private_gen_dir
# - Required: The directory under which the private source will be
# generated.
# - Type: path
#
# * rust_gen_dir
# - Required: The directory under which the rust bindings will generated.
# - Type: path
#
# * go_gen_dir
# - Optional: The directory under which the source specific to the go
# runtime will be generated.
# - Type: path
#
# * exclude_testonly
# - Optional: Whether to exclude generating test-only syscalls.
# - Type: bool
# - Default: true
#
# * testonly
# - Optional: Usual GN meaning.
#
template("kazoo") {
compiled_action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"public_gen_dir",
"private_gen_dir",
"rust_gen_dir",
"go_gen_dir",
"exclude_testonly",
])
if (!defined(exclude_testonly)) {
exclude_testonly = true
}
visibility = [ ":*" ]
tool = "//zircon/tools/kazoo"
args = []
categories = [
{
gen_dir = public_gen_dir
generated = public_generated
},
{
gen_dir = private_gen_dir
generated = private_generated
},
{
gen_dir = rust_gen_dir
generated = rust_generated
},
]
if (defined(go_gen_dir)) {
categories += [
{
gen_dir = go_gen_dir
generated = go_generated
},
]
}
if (exclude_testonly) {
args += [ "--exclude=testonly" ]
} else {
categories += [
{
gen_dir = public_gen_dir
generated = testonly_generated
},
]
}
outputs = []
foreach(category, categories) {
foreach(gen, category.generated) {
output = category.gen_dir + "/" + gen.output
args += [
gen.arg,
rebase_path(output, root_build_dir),
]
outputs += [ output ]
}
}
deps = [ ":zx($fidl_toolchain)" ]
fidl_target_gen_dir = get_label_info(deps[0], "target_gen_dir")
sources = [ "$fidl_target_gen_dir/zx.fidl.json" ]
args += [ rebase_path(sources[0], root_build_dir) ]
metadata = {
generated_sources = rebase_path(outputs, root_build_dir)
}
}
}
if (current_toolchain == default_toolchain) {
kazoo("generate") {
public_gen_dir = syscall_public_gen_dir
private_gen_dir = syscall_private_gen_dir
rust_gen_dir = syscall_rust_gen_dir
exclude_testonly = exclude_testonly_syscalls
}
#
# Golden testing.
#
golden_candidate_dir = "$target_gen_dir/golden-candidates"
public_golden_candidate_dir = "$golden_candidate_dir/public"
private_golden_candidate_dir = "$golden_candidate_dir/private"
rust_golden_candidate_dir = "$golden_candidate_dir/rust"
go_golden_candidate_dir = "$golden_candidate_dir/go"
kazoo("all_outputs") {
testonly = true
public_gen_dir = public_golden_candidate_dir
private_gen_dir = private_golden_candidate_dir
go_gen_dir = go_golden_candidate_dir
rust_gen_dir = rust_golden_candidate_dir
exclude_testonly = false
}
golden_files("goldens") {
testonly = true
categories = [
{
gen_dir = public_golden_candidate_dir
generated = public_generated + testonly_generated
golden_subdir = "public"
},
{
gen_dir = private_golden_candidate_dir
generated = private_generated
golden_subdir = "private"
},
{
gen_dir = go_golden_candidate_dir
generated = go_generated
golden_subdir = "go"
},
{
gen_dir = rust_golden_candidate_dir
generated = rust_generated
golden_subdir = "rust"
},
]
comparisons = []
foreach(category, categories) {
foreach(gen, category.generated) {
comparisons += [
{
golden =
"//zircon/vdso/goldens/${category.golden_subdir}/" + gen.output
candidate = category.gen_dir + "/" + gen.output
},
]
}
}
deps = [ ":all_outputs" ]
}
}