xref: /aosp_15_r20/external/angle/build/rust/tests/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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_cpp_test_with_cpp_linkage",
27      "//build/rust/tests/bindgen_static_fns_test",
28      "//build/rust/tests/bindgen_test",
29      "//build/rust/tests/test_aliased_deps",
30      "//build/rust/tests/test_aliased_deps:test_aliased_deps_exe",
31      "//build/rust/tests/test_bin_crate",
32      "//build/rust/tests/test_rlib_crate:target1",
33      "//build/rust/tests/test_rlib_crate:target2",
34      "//build/rust/tests/test_rlib_crate:test_rlib_crate_associated_bin",
35      "//build/rust/tests/test_rlib_crate_testonly:testonly_target",
36      "//build/rust/tests/test_rust_metadata:test_rust_metadata_cc_exe",
37      "//build/rust/tests/test_rust_metadata:test_rust_metadata_exe",
38      "//build/rust/tests/test_rust_multiple_dep_versions_exe",
39      "//build/rust/tests/test_simple_rust_exe",
40
41      # TODO(crbug.com/40226863): Enable the additional target below
42      # once `rs_bindings_from_cc` is distributed via `gclient sync`.  In the
43      # meantime see the instructions in
44      # `//build/rust/run_rs_bindings_from_cc.py`.
45      #"test_rs_bindings_from_cc:test_rs_bindings_from_cc",
46    ]
47
48    if (!(is_apple && is_official_build)) {
49      # TODO: crbug.com/372055517 - Apple lld has an ordering dependency bug
50      # when LTO is enabled, and this particular build target runs into that.
51      deps += [ "//build/rust/tests/bindgen_cpp_test" ]
52    }
53
54    if (enable_chromium_prelude) {
55      deps += [ "//build/rust/chromium_prelude:import_test" ]
56    }
57    if (enable_rust_cxx) {
58      deps += [
59        "//build/rust/tests/test_cpp_including_rust",
60        "//build/rust/tests/test_rust_calling_cpp",
61        "//build/rust/tests/test_rust_exe",
62        "//build/rust/tests/test_rust_static_library",
63      ]
64    }
65    if (build_with_chromium) {
66      # This tests integration with a 3p library that downstream projects
67      # don't need to have.
68      deps += [ "//build/rust/tests/test_serde_json_lenient" ]
69    }
70
71    if (can_build_rust_unit_tests) {
72      deps += [
73        "//build/rust/tests/bindgen_static_fns_test:bindgen_static_fns_test_lib_unittests",
74        "//build/rust/tests/bindgen_test:bindgen_test_lib_unittests",
75        "//build/rust/tests/test_aliased_deps:test_aliased_deps_unittests",
76        "//build/rust/tests/test_rlib_crate:target1_test_rlib_crate_v0_2_unittests",
77        "//build/rust/tests/test_rlib_crate:target2_test_rlib_crate_v0_2_unittests",
78        "//build/rust/tests/test_rust_metadata:test_rust_metadata_unittests",
79        "//build/rust/tests/test_rust_multiple_dep_versions_exe/v1:test_lib_v1_unittests",
80        "//build/rust/tests/test_rust_multiple_dep_versions_exe/v2:test_lib_v2_unittests",
81        "//build/rust/tests/test_rust_static_library_non_standard_arrangement:foo_tests",
82
83        # TODO(crbug.com/40226863): Enable the additional target below
84        # once `rs_bindings_from_cc` is distributed via `gclient sync`.  In the
85        # meantime see the instructions in
86        # `//build/rust/run_rs_bindings_from_cc.py`.
87        #"test_rs_bindings_from_cc:test_rs_bindings_from_cc_unittests",
88      ]
89
90      if (enable_rust_cxx) {
91        deps += [
92          "//build/rust/tests/test_cpp_including_rust:test_cpp_including_rust_unittests",
93          "//build/rust/tests/test_rust_exe:test_rust_exe_unittests",
94          "//build/rust/tests/test_rust_static_library:test_rust_static_library_unittests",
95          "//build/rust/tests/test_rust_unittests",
96        ]
97      }
98    }
99
100    # Dylibs should only be built in component builds. We turn on flags which
101    # are incompatible with shared library compilation in non-component builds
102    # (such as code coverage https://crbug.com/1457533).
103    if (is_component_build && enable_rust_cxx) {
104      deps += [ "//build/rust/tests/test_rust_shared_library" ]
105      if (can_build_rust_unit_tests) {
106        deps += [ "//build/rust/tests/test_cpp_including_rust:test_cpp_including_rust_dylib_unittests" ]
107
108        # TODO(crbug.com/40266882): The shared library unittest EXE ends up
109        # requiring the DLL to run, even though it does not use the DLL.
110        if (!is_win && !is_mac) {
111          deps += [ "//build/rust/tests/test_rust_shared_library:test_rust_shared_library_unittests" ]
112        }
113      }
114    }
115
116    if (is_win) {
117      deps += [ "//build/rust/tests/windows_sys_test" ]
118      deps += [ "//build/rust/tests/test_control_flow_guard" ]
119    }
120  }
121}
122
123if (can_build_rust_unit_tests) {
124  # Generates a script that will run all the native Rust unit tests, in order
125  # to have them all part of a single test step on infra bots.
126  rust_unit_tests_group("build_rust_tests") {
127    deps = [ ":deps" ]
128  }
129}
130