| # 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/fidl/toolchain.gni") |
| import("//build/go/go_binary.gni") |
| import("//build/go/go_library.gni") |
| import("//build/host.gni") |
| import("//build/rust/fidl_rust.gni") |
| import("//build/testing/golden_files.gni") |
| import("//tools/fidl/fidlc/testdata/info.gni") |
| import("//tools/fidl/lib/fidlgentest/fidlgentest_go_test.gni") |
| |
| if (is_host) { |
| go_library("codegen") { |
| source_dir = "codegen" |
| deps = [ "//tools/fidl/lib/fidlgen" ] |
| sources = [ |
| "alias.tmpl", |
| "bits.tmpl", |
| "codegen.go", |
| "const.tmpl", |
| "enum.tmpl", |
| "ir.go", |
| "ir_test.go", |
| "protocol.tmpl", |
| "service.tmpl", |
| "sourcefile.tmpl", |
| "struct.tmpl", |
| "table.tmpl", |
| "union.tmpl", |
| ] |
| } |
| |
| go_library("main") { |
| deps = [ |
| ":codegen", |
| "//tools/fidl/lib/fidlgen", |
| ] |
| sources = [ "main.go" ] |
| } |
| |
| go_binary("fidlgen_rust") { |
| library = ":main" |
| sdk_category = "partner" |
| } |
| |
| fidlgentest_go_test("fidlgen_rust_lib_tests") { |
| library = ":codegen" |
| deps = [ "//third_party/golibs:github.com/google/go-cmp" ] |
| } |
| |
| golden_files("fidlgen_rust_golden_tests") { |
| testonly = true |
| |
| formatter = { |
| script = "$rustc_prefix/bin/rustfmt" |
| inputs = [ "//rustfmt.toml" ] |
| args = [ |
| "--config-path", |
| rebase_path(inputs[0], root_build_dir), |
| ] |
| } |
| |
| deps = [] |
| comparisons = [] |
| foreach(info, fidl_testdata_info) { |
| if (info.denylist + [ "fidlgen_rust" ] - [ "fidlgen_rust" ] == |
| info.denylist) { |
| deps += [ "${info.target}_rust_generate($fidl_toolchain)" ] |
| _library_underscore = string_replace(info.library, ".", "_") |
| comparisons += [ |
| { |
| golden = "goldens/${info.name}.rs.golden" |
| candidate = "${info.fidl_gen_dir}/${info.target_name}/rust/fidl_${_library_underscore}.rs" |
| }, |
| ] |
| } |
| } |
| } |
| } |
| |
| install_host_tools("host") { |
| deps = [ ":fidlgen_rust" ] |
| outputs = [ "fidlgen_rust" ] |
| } |
| |
| group("goldens") { |
| testonly = true |
| |
| denylist_key = "device_build_denylist" |
| if (is_host) { |
| denylist_key = "host_build_denylist" |
| } |
| |
| deps = [] |
| foreach(info, fidl_testdata_info) { |
| if (info[denylist_key] + [ "fidlgen_rust" ] - [ "fidlgen_rust" ] == |
| info[denylist_key]) { |
| deps += [ "${info.target}_rust" ] |
| } |
| } |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":fidlgen_rust_golden_tests($host_toolchain)", |
| ":fidlgen_rust_lib_tests($host_toolchain)", |
| ":goldens", |
| ":goldens($host_toolchain)", |
| ] |
| } |