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