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