| # 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. | 
 | # | 
 | # 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 = [] | 
 |   } | 
 |  | 
 |   # Generate the rust sources using the scanner. | 
 |   compiled_action("gen_${target_name}_client_protocol") { | 
 |     tool = "//src/lib/ui/wayland/bindings/scanner" | 
 |     sources = [ invoker.protocol ] | 
 |     outputs = [ target_crate_root + "_client_protocol.rs" ] | 
 |     args = [ | 
 |       "--target", | 
 |       "client", | 
 |       "-i", | 
 |       rebase_path(invoker.protocol, root_build_dir), | 
 |       "-o", | 
 |       rebase_path(target_crate_root + "_client_protocol.rs", root_build_dir), | 
 |     ] | 
 |     foreach(dep, protocol_deps) { | 
 |       args += [ | 
 |         "-d", | 
 |         get_label_info(dep, "name") + "_client_protocol", | 
 |       ] | 
 |     } | 
 |   } | 
 |   compiled_action("gen_${target_name}_server_protocol") { | 
 |     tool = "//src/lib/ui/wayland/bindings/scanner" | 
 |     sources = [ invoker.protocol ] | 
 |     outputs = [ target_crate_root + "_server_protocol.rs" ] | 
 |     args = [ | 
 |       "--target", | 
 |       "server", | 
 |       "-i", | 
 |       rebase_path(invoker.protocol, root_build_dir), | 
 |       "-o", | 
 |       rebase_path(target_crate_root + "_server_protocol.rs", root_build_dir), | 
 |     ] | 
 |     foreach(dep, protocol_deps) { | 
 |       args += [ | 
 |         "-d", | 
 |         get_label_info(dep, "name") + "_server_protocol", | 
 |       ] | 
 |     } | 
 |   } | 
 |  | 
 |   # Build the client and server libraries. | 
 |   rustc_library(target_name + "_client_protocol") { | 
 |     edition = "2018" | 
 |     non_rust_deps = [ ":gen_${target_name}" ] | 
 |     deps = [ | 
 |       "//src/lib/trace/rust:trace", | 
 |       "//src/lib/ui/wayland/core", | 
 |       "//src/lib/zircon/rust:fuchsia-zircon", | 
 |       "//third_party/rust_crates:anyhow", | 
 |       "//third_party/rust_crates:bitflags", | 
 |     ] | 
 |     foreach(dep, protocol_deps) { | 
 |       deps += [ dep + "_client_protocol" ] | 
 |     } | 
 |     source_root = target_crate_root + "_client_protocol.rs" | 
 |  | 
 |     sources = [ target_crate_root + "_client_protocol.rs" ] | 
 |   } | 
 |   rustc_library(target_name + "_server_protocol") { | 
 |     edition = "2018" | 
 |     non_rust_deps = [ ":gen_${target_name}" ] | 
 |     deps = [ | 
 |       "//src/lib/trace/rust:trace", | 
 |       "//src/lib/ui/wayland/core", | 
 |       "//src/lib/zircon/rust:fuchsia-zircon", | 
 |       "//third_party/rust_crates:anyhow", | 
 |       "//third_party/rust_crates:bitflags", | 
 |     ] | 
 |     foreach(dep, protocol_deps) { | 
 |       deps += [ dep + "_server_protocol" ] | 
 |     } | 
 |     source_root = target_crate_root + "_server_protocol.rs" | 
 |  | 
 |     sources = [ target_crate_root + "_server_protocol.rs" ] | 
 |   } | 
 | } |