|  | # Copyright 2017 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/config/fuchsia/zircon.gni") | 
|  | import("//build/rust/rustc_binary.gni") | 
|  | import("//build/rust/rustc_library.gni") | 
|  | import("//build/rust/rustc_test.gni") | 
|  | import("//build/test/test_package.gni") | 
|  | import("//build/testing/environments.gni") | 
|  |  | 
|  | common_sources = [ | 
|  | "src/channel.rs", | 
|  | "src/clock.rs", | 
|  | "src/cprng.rs", | 
|  | "src/debuglog.rs", | 
|  | "src/event.rs", | 
|  | "src/eventpair.rs", | 
|  | "src/fifo.rs", | 
|  | "src/guest.rs", | 
|  | "src/handle.rs", | 
|  | "src/info.rs", | 
|  | "src/interrupt.rs", | 
|  | "src/job.rs", | 
|  | "src/lib.rs", | 
|  | "src/port.rs", | 
|  | "src/process.rs", | 
|  | "src/profile.rs", | 
|  | "src/property.rs", | 
|  | "src/resource.rs", | 
|  | "src/rights.rs", | 
|  | "src/signals.rs", | 
|  | "src/socket.rs", | 
|  | "src/stream.rs", | 
|  | "src/task.rs", | 
|  | "src/thread.rs", | 
|  | "src/time.rs", | 
|  | "src/version.rs", | 
|  | "src/vmar.rs", | 
|  | "src/vmo.rs", | 
|  | ] | 
|  |  | 
|  | if (is_fuchsia) { | 
|  | rustc_library("fuchsia-zircon") { | 
|  | version = "0.3.3" | 
|  | edition = "2018" | 
|  | deps = [ | 
|  | ":fuchsia-zircon-status", | 
|  | ":fuchsia-zircon-sys", | 
|  | "//third_party/rust_crates:bitflags", | 
|  | ] | 
|  |  | 
|  | sources = common_sources | 
|  | } | 
|  | } | 
|  |  | 
|  | # Generate Zircon rust bindings using the GN version of the Kazoo tool. | 
|  | # The source is still the .json file generated during the ZN build. | 
|  | compiled_action("generate-rust-zircon-syscalls-definitions") { | 
|  | _zx_json_target = "//zircon/vdso:zx($default_toolchain)" | 
|  | tool = "//zircon/tools/kazoo" | 
|  | sources = | 
|  | [ get_label_info(_zx_json_target, "target_gen_dir") + "/zx.fidl.json" ] | 
|  | outputs = [ "$root_gen_dir/zircon/rust/syscalls/definitions.rs" ] | 
|  | args = [ | 
|  | "--rust=" + rebase_path(outputs[0], root_build_dir), | 
|  | rebase_path(sources[0], root_build_dir), | 
|  | ] | 
|  | deps = [ _zx_json_target ] | 
|  | } | 
|  |  | 
|  | rustc_library("fuchsia-zircon-sys") { | 
|  | version = "0.3.3" | 
|  | edition = "2018" | 
|  | _outputs = get_target_outputs(":generate-rust-zircon-syscalls-definitions") | 
|  | source_root = _outputs[0] | 
|  | deps = [ | 
|  | ":fuchsia-zircon-types", | 
|  | ":generate-rust-zircon-syscalls-definitions", | 
|  | ] | 
|  |  | 
|  | sources = [ _outputs[0] ] | 
|  | } | 
|  |  | 
|  | rustc_library("fuchsia-zircon-types") { | 
|  | version = "0.1.0" | 
|  | edition = "2018" | 
|  | source_root = "fuchsia-zircon-types/src/lib.rs" | 
|  |  | 
|  | sources = [ "fuchsia-zircon-types/src/lib.rs" ] | 
|  | } | 
|  |  | 
|  | rustc_library("fuchsia-zircon-status") { | 
|  | version = "0.1.0" | 
|  | edition = "2018" | 
|  | source_root = "fuchsia-zircon-status/src/lib.rs" | 
|  | deps = [ ":fuchsia-zircon-sys" ] | 
|  |  | 
|  | sources = [ "fuchsia-zircon-status/src/lib.rs" ] | 
|  | } | 
|  |  | 
|  | rustc_test("fuchsia-zircon-status-tests") { | 
|  | name = "fuchsia_zircon_status_tests" | 
|  | edition = "2018" | 
|  | source_root = "fuchsia-zircon-status/src/lib.rs" | 
|  |  | 
|  | deps = [ "//src/lib/zircon/rust:fuchsia-zircon-sys" ] | 
|  |  | 
|  | sources = [ "fuchsia-zircon-status/src/lib.rs" ] | 
|  | } | 
|  |  | 
|  | # Certain unit tests for fuchsia-zircon need dependencies which can't be added | 
|  | # to the main library's without causing circular dependencies. Only the test | 
|  | # artifact is used, not the main artifact. | 
|  | # TODO: If we add test-only deps to rustc_artifact, this can merge back in. | 
|  | rustc_test("fuchsia-zircon-unittest") { | 
|  | edition = "2018" | 
|  | deps = [ | 
|  | ":fuchsia-zircon-status", | 
|  | ":fuchsia-zircon-sys", | 
|  | "//third_party/rust_crates:bitflags", | 
|  |  | 
|  | # Test-only deps | 
|  | ":fuchsia-zircon", | 
|  | "//src/lib/fdio/rust:fdio", | 
|  | "//src/lib/fuchsia-runtime", | 
|  | "//third_party/rust_crates:matches", | 
|  | ] | 
|  |  | 
|  | # TODO(fxbug.dev/46723): Fix the leaks and remove this. | 
|  | non_rust_deps = [ "//build/config/sanitizers:suppress-lsan.DO-NOT-USE-THIS" ] | 
|  |  | 
|  | sources = common_sources | 
|  | } | 
|  |  | 
|  | rustc_binary("exit_with_code_util") { | 
|  | edition = "2018" | 
|  | source_root = "test_util/exit_with_code_util.rs" | 
|  | deps = [ ":fuchsia-zircon" ] | 
|  |  | 
|  | sources = [ "test_util/exit_with_code_util.rs" ] | 
|  | } | 
|  |  | 
|  | rustc_binary("sleep_forever_util") { | 
|  | edition = "2018" | 
|  | source_root = "test_util/sleep_forever_util.rs" | 
|  | deps = [ ":fuchsia-zircon" ] | 
|  |  | 
|  | sources = [ "test_util/sleep_forever_util.rs" ] | 
|  | } | 
|  |  | 
|  | test_package("fuchsia-zircon-tests") { | 
|  | deps = [ | 
|  | ":exit_with_code_util", | 
|  | ":fuchsia-zircon-status-tests", | 
|  | ":fuchsia-zircon-unittest", | 
|  | ":sleep_forever_util", | 
|  | ] | 
|  |  | 
|  | tests = [ | 
|  | { | 
|  | name = "fuchsia_zircon_unittest" | 
|  | dest = "fuchsia_zircon_tests" | 
|  | environments = basic_envs | 
|  | }, | 
|  | { | 
|  | name = "fuchsia_zircon_status_tests" | 
|  | dest = "fuchsia_zircon_status_tests" | 
|  | environments = basic_envs | 
|  | }, | 
|  | ] | 
|  |  | 
|  | binaries = [ | 
|  | { | 
|  | name = "exit_with_code_util" | 
|  | }, | 
|  | { | 
|  | name = "sleep_forever_util" | 
|  | }, | 
|  | ] | 
|  | } | 
|  |  | 
|  | group("tests") { | 
|  | testonly = true | 
|  | deps = [ ":fuchsia-zircon-tests" ] | 
|  | } |