xref: /aosp_15_r20/external/cronet/build/rust/tests/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2021 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/rust.gni")
6import("//build/rust/rust_unit_tests_group.gni")
7
8# Build some minimal binaries to exercise the Rust toolchain
9# only if that toolchain is enabled in gn args.
10group("tests") {
11  testonly = true
12
13  deps = [ ":deps" ]
14  if (can_build_rust_unit_tests) {
15    deps += [ ":build_rust_tests" ]
16  }
17}
18
19group("deps") {
20  testonly = true
21  deps = []
22
23  # All the rest require Rust.
24  if (toolchain_has_rust) {
25    deps += [
26      "//build/rust/tests/bindgen_static_fns_test",
27      "//build/rust/tests/bindgen_test",
28      "//build/rust/tests/test_aliased_deps",
29      "//build/rust/tests/test_aliased_deps:test_aliased_deps_exe",
30      "//build/rust/tests/test_bin_crate",
31      "//build/rust/tests/test_rlib_crate:target1",
32      "//build/rust/tests/test_rlib_crate:target2",
33      "//build/rust/tests/test_rlib_crate:test_rlib_crate_associated_bin",
34      "//build/rust/tests/test_rlib_crate_testonly:testonly_target",
35      "//build/rust/tests/test_rust_metadata:test_rust_metadata_cc_exe",
36      "//build/rust/tests/test_rust_metadata:test_rust_metadata_exe",
37      "//build/rust/tests/test_rust_multiple_dep_versions_exe",
38      "//build/rust/tests/test_simple_rust_exe",
39
40      # TODO(https://crbug.com/1329611): Enable the additional target below
41      # once `rs_bindings_from_cc` is distributed via `gclient sync`.  In the
42      # meantime see the instructions in
43      # `//build/rust/run_rs_bindings_from_cc.py`.
44      #"test_rs_bindings_from_cc:test_rs_bindings_from_cc",
45    ]
46
47    if (enable_chromium_prelude) {
48      deps += [ "//build/rust/chromium_prelude:import_test" ]
49    }
50    if (enable_cxx) {
51      deps += [
52        "//build/rust/tests/test_cpp_including_rust",
53        "//build/rust/tests/test_rust_calling_cpp",
54        "//build/rust/tests/test_rust_exe",
55        "//build/rust/tests/test_rust_static_library",
56      ]
57    }
58    if (build_with_chromium) {
59      # This tests integration with a 3p library that downstream projects
60      # don't need to have.
61      deps += [ "//build/rust/tests/test_serde_json_lenient" ]
62    }
63
64    if (can_build_rust_unit_tests) {
65      deps += [
66        "//build/rust/tests/bindgen_static_fns_test:bindgen_static_fns_test_lib_unittests",
67        "//build/rust/tests/bindgen_test:bindgen_test_lib_unittests",
68        "//build/rust/tests/test_aliased_deps:test_aliased_deps_unittests",
69        "//build/rust/tests/test_rlib_crate:target1_test_rlib_crate_v0_2_unittests",
70        "//build/rust/tests/test_rlib_crate:target2_test_rlib_crate_v0_2_unittests",
71        "//build/rust/tests/test_rust_metadata:test_rust_metadata_unittests",
72        "//build/rust/tests/test_rust_multiple_dep_versions_exe/v1:test_lib_v1_unittests",
73        "//build/rust/tests/test_rust_multiple_dep_versions_exe/v2:test_lib_v2_unittests",
74        "//build/rust/tests/test_rust_static_library_non_standard_arrangement:foo_tests",
75
76        # TODO(https://crbug.com/1329611): Enable the additional target below
77        # once `rs_bindings_from_cc` is distributed via `gclient sync`.  In the
78        # meantime see the instructions in
79        # `//build/rust/run_rs_bindings_from_cc.py`.
80        #"test_rs_bindings_from_cc:test_rs_bindings_from_cc_unittests",
81      ]
82
83      if (enable_cxx) {
84        deps += [
85          "//build/rust/tests/test_cpp_including_rust:test_cpp_including_rust_unittests",
86          "//build/rust/tests/test_rust_exe:test_rust_exe_unittests",
87          "//build/rust/tests/test_rust_static_library:test_rust_static_library_unittests",
88          "//build/rust/tests/test_rust_unittests",
89        ]
90      }
91    }
92
93    # Dylibs should only be built in component builds. We turn on flags which
94    # are incompatible with shared library compilation in non-component builds
95    # (such as code coverage https://crbug.com/1457533).
96    if (is_component_build && enable_cxx) {
97      deps += [ "//build/rust/tests/test_rust_shared_library" ]
98      if (can_build_rust_unit_tests) {
99        deps += [ "//build/rust/tests/test_cpp_including_rust:test_cpp_including_rust_dylib_unittests" ]
100
101        # TODO(crbug.com/1442273): The shared library unittest EXE ends up
102        # requiring the DLL to run, even though it does not use the DLL.
103        if (!is_win && !is_mac) {
104          deps += [ "//build/rust/tests/test_rust_shared_library:test_rust_shared_library_unittests" ]
105        }
106      }
107    }
108
109    if (is_win) {
110      deps += [ "//build/rust/tests/test_control_flow_guard" ]
111    }
112  }
113}
114
115if (can_build_rust_unit_tests) {
116  # Generates a script that will run all the native Rust unit tests, in order
117  # to have them all part of a single test step on infra bots.
118  rust_unit_tests_group("build_rust_tests") {
119    deps = [ ":deps" ]
120  }
121}
122