blob: d3cb36e2470203e4322705575b026151105cde6c [file] [log] [blame] [edit]
# Copyright 2018 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/rust/rustc_library.gni")
# Generates a rust library for a given wayland protocol.xml file. The protocol
# will be built as a crate with the same name as the target.
#
# protocol (required)
# The path to the XML protocol specification to be scanned.
#
# deps (optional, default = [])
# Additional protocol dependencies for this protocol. These labels should
# correspond another `wayland_protocol` target.
#
# need_fuchsia_zircon (optional, default = false)
# Whether the generated rust library should depend on the fuchsia-zircon
# crate.
#
# Ex:
# wayland_protocol("base") {
# protocol = "base_protocol.xml"
# }
#
# wayland_protocol("derived") {
# protocol = "derived_protocol.xml"
# deps = [ ":base" ]
# }
#
template("wayland_protocol") {
assert(defined(invoker.protocol), "protocol must be defined for $target_name")
target_crate_root = "$target_gen_dir/$target_name"
if (defined(invoker.deps)) {
protocol_deps = invoker.deps
} else {
protocol_deps = []
}
# Build the client and server libraries.
foreach(type,
[
"client",
"server",
]) {
# Generate the rust sources using the scanner.
compiled_action("gen_${target_name}_${type}_protocol") {
tool = "//src/lib/ui/wayland/bindings/scanner"
sources = [ invoker.protocol ]
outputs = [ target_crate_root + "_${type}_protocol.rs" ]
args = [
"--target",
"${type}",
"-i",
rebase_path(invoker.protocol, root_build_dir),
"-o",
rebase_path(target_crate_root + "_${type}_protocol.rs", root_build_dir),
]
foreach(dep, protocol_deps) {
args += [
"-d",
get_label_info(dep, "name") + "_${type}_protocol",
]
}
}
rustc_library(target_name + "_${type}_protocol") {
edition = "2018"
non_rust_deps = [ ":gen_${target_name}" ]
deps = [
"//src/lib/trace/rust:trace",
"//src/lib/ui/wayland/core",
"//third_party/rust_crates:anyhow",
"//third_party/rust_crates:bitflags",
]
if (defined(invoker.need_fuchsia_zircon) && invoker.need_fuchsia_zircon) {
deps += [ "//src/lib/zircon/rust:fuchsia-zircon" ]
}
foreach(dep, protocol_deps) {
deps += [ dep + "_${type}_protocol" ]
}
source_root = target_crate_root + "_${type}_protocol.rs"
sources = [ target_crate_root + "_${type}_protocol.rs" ]
}
}
}