blob: 9741f165eec2c48a0d265407ce323e38849804f4 [file] [log] [blame]
Benjamin Brittain014f7ff2019-12-30 21:05:23 +00001# Copyright 2017 The Fuchsia Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Shai Barack6a58d992021-04-14 05:50:58 +00005import("//build/components.gni")
Benjamin Brittain014f7ff2019-12-30 21:05:23 +00006import("//build/rust/rustc_binary.gni")
7import("//build/rust/rustc_library.gni")
David 'Digit' Turner63412152024-07-22 14:15:53 +00008import("//build/rust/rustc_link_attribute.gni")
9
10# The Rust stdlib has an implicit link attribute to libfdio.
11# Any Rust executable should depend on this target to link
12# properly. See //build/rust/rustc_artifact.gni.
13rustc_link_attribute("fdio_for_rust_stdlib") {
14 lib_shared_target = "//sdk/lib/fdio"
15}
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000016
17rustc_library("fdio") {
18 with_unit_tests = true
19 version = "0.2.0"
Sarah Chan64bf58d2025-12-06 16:25:07 -080020 edition = "2024"
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000021 deps = [
Mitchell Kember0c5eddb2022-07-28 23:36:32 +000022 "//sdk/fidl/fuchsia.io:fuchsia.io_rust",
Vinicius Felizardod27abc62024-06-20 17:09:05 +000023 "//sdk/lib/fdio",
Adam Perry180a49c2024-10-03 06:38:50 +000024 "//sdk/rust/zx",
Charles Celerier6a01f512022-09-07 22:41:41 +000025 "//src/lib/fidl/rust/fidl",
Benjamin Brittainbe5562572020-01-03 20:46:46 +000026 "//src/lib/fuchsia-runtime",
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000027 "//third_party/rust_crates:bitflags",
Ben Keller9882dd02020-11-11 23:07:31 +000028 "//third_party/rust_crates:thiserror",
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000029 ]
30
Ben Keller9882dd02020-11-11 23:07:31 +000031 test_deps = [
Ben Keller9882dd02020-11-11 23:07:31 +000032 "//src/lib/fuchsia-async",
33 "//src/lib/fuchsia-runtime",
Jeff Martin6eea97e2022-05-05 15:01:41 +000034 "//third_party/rust_crates:assert_matches",
Tamir Dubersteinb5431bd2022-06-24 23:06:17 +000035 "//third_party/rust_crates:libc",
36 "//third_party/rust_crates:rand",
Ben Keller9882dd02020-11-11 23:07:31 +000037 "//third_party/rust_crates:tempfile",
38 ]
Adam Lesinski9f39a122020-07-22 21:17:36 +000039
Adam Lesinski9f39a122020-07-22 21:17:36 +000040 sources = [
41 "src/fdio_sys.rs",
42 "src/lib.rs",
Ben Keller9882dd02020-11-11 23:07:31 +000043 "src/spawn_builder.rs",
Adam Lesinski9f39a122020-07-22 21:17:36 +000044 ]
Tamir Duberstein7e64ca72022-05-05 21:42:18 +000045
Tamir Duberstein98a4fa42022-07-18 10:06:20 +000046 configs -= [ "//build/config/rust/lints:allow_unused_results" ]
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000047}
48
Chris Suter95d72202025-07-15 18:34:37 -070049rustc_library("fdio_zxio") {
50 with_unit_tests = true
51 version = "0.1.0"
Sarah Chan64bf58d2025-12-06 16:25:07 -080052 edition = "2024"
Chris Suter95d72202025-07-15 18:34:37 -070053 source_root = "src/fdio_zxio.rs"
54 sources = [
55 "src/fdio_sys.rs",
56 "src/fdio_zxio.rs",
57 "src/zxio_sys.rs",
58 ]
59 deps = [
60 "//sdk/lib/zxio",
61 "//sdk/rust/zx",
62 ]
63 test_deps = [
64 "//src/lib/fuchsia",
65 "//third_party/rust_crates:libc",
66 ]
67}
68
Ben Keller9882dd02020-11-11 23:07:31 +000069rustc_binary("spawn_test_target") {
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000070 version = "0.2.0"
Sarah Chan64bf58d2025-12-06 16:25:07 -080071 edition = "2024"
Ben Keller9882dd02020-11-11 23:07:31 +000072 source_root = "test/spawn_test_target.rs"
73 sources = [ "test/spawn_test_target.rs" ]
Tamir Duberstein7e64ca72022-05-05 21:42:18 +000074
Tamir Duberstein98a4fa42022-07-18 10:06:20 +000075 configs -= [ "//build/config/rust/lints:allow_unused_results" ]
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000076}
77
Ben Keller9882dd02020-11-11 23:07:31 +000078rustc_binary("spawn_builder_test_target") {
Sarah Chan64bf58d2025-12-06 16:25:07 -080079 edition = "2024"
Ben Keller9882dd02020-11-11 23:07:31 +000080 visibility = [ ":*" ]
81 source_root = "test/spawn_builder_test_target.rs"
82 sources = [ "test/spawn_builder_test_target.rs" ]
Tamir Duberstein7e64ca72022-05-05 21:42:18 +000083
Tamir Duberstein98a4fa42022-07-18 10:06:20 +000084 configs -= [ "//build/config/rust/lints:allow_unused_results" ]
Ben Keller9882dd02020-11-11 23:07:31 +000085}
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000086
Ben Keller9882dd02020-11-11 23:07:31 +000087fuchsia_component("test-component") {
88 testonly = true
89 visibility = [ ":*" ]
90 component_name = "fdio_lib_test"
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000091 deps = [
92 ":fdio_test",
Ben Keller9882dd02020-11-11 23:07:31 +000093 ":spawn_builder_test_target",
94 ":spawn_test_target",
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000095 ]
Adam Perry5a7797f2022-06-22 15:44:19 +000096 manifest = "meta/fdio_lib_test.cml"
Ben Keller9882dd02020-11-11 23:07:31 +000097}
Benjamin Brittain014f7ff2019-12-30 21:05:23 +000098
Chris Suter95d72202025-07-15 18:34:37 -070099fuchsia_unittest_component("fdio_zxio_test_component") {
100 visibility = [ ":*" ]
101 component_name = "fdio_zxio_test"
102 deps = [ ":fdio_zxio_test" ]
103}
104
Ben Keller9882dd02020-11-11 23:07:31 +0000105fuchsia_test_package("test-package") {
106 package_name = "fdio-rust-tests"
Chris Suter95d72202025-07-15 18:34:37 -0700107 test_components = [
108 ":test-component",
109 ":fdio_zxio_test_component",
110 ]
Ben Keller9882dd02020-11-11 23:07:31 +0000111}
Benjamin Brittain014f7ff2019-12-30 21:05:23 +0000112
Ben Keller9882dd02020-11-11 23:07:31 +0000113group("tests") {
114 testonly = true
115 deps = [ ":test-package" ]
Benjamin Brittain014f7ff2019-12-30 21:05:23 +0000116}