BUILD.gn (2749B)
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 5 import("//chromium/build/config/rust.gni") 6 7 if (toolchain_has_rust) { 8 config("edition_2024") { 9 rustflags = [ "--edition=2024" ] 10 } 11 12 config("edition_2021") { 13 rustflags = [ "--edition=2021" ] 14 } 15 16 config("edition_2018") { 17 rustflags = [ "--edition=2018" ] 18 } 19 20 config("edition_2015") { 21 rustflags = [ "--edition=2015" ] 22 } 23 24 if (enable_rust_cxx) { 25 # The required dependencies for cxx-generated bindings, that must be included 26 # on the C++ side. 27 static_library("cxx_cppdeps") { 28 sources = [ 29 "//third_party/rust/chromium_crates_io/vendor/cxx-v1/include/cxx.h", 30 "//third_party/rust/chromium_crates_io/vendor/cxx-v1/src/cxx.cc", 31 32 # Our version-independent forwarding header, which we patch cxx.cc to 33 # use since we want it to use an absolute path for its include. 34 "//third_party/rust/cxx/v1/cxx.h", 35 ] 36 37 defines = [ "RUST_CXX_NO_EXCEPTIONS" ] 38 39 # We cannot depend on base/base_export.h because base depends on us. 40 if (is_component_build) { 41 if (is_win) { 42 defines += [ "CXX_RS_EXPORT=__declspec(dllexport)" ] 43 } else { 44 defines += 45 [ "CXX_RS_EXPORT=__attribute__((visibility(\"default\")))" ] 46 } 47 } else { 48 defines += [ "CXX_RS_EXPORT=" ] 49 } 50 51 deps = [ 52 # Depending on the C++ bindings side of cxx then requires also depending 53 # on the Rust bindings, since one calls the other. And the Rust bindings 54 # require the Rust standard library. 55 ":cxx_rustdeps", 56 ] 57 } 58 59 group("cxx_rustdeps") { 60 # The required dependencies for cxx-generated bindings, that must be 61 # included on the Rust side. 62 public_deps = [ "//third_party/rust/cxx/v1:lib" ] 63 } 64 } 65 } 66 67 # Enables code behind #[cfg(test)]. This should only be used for targets where 68 # testonly=true. 69 config("test") { 70 rustflags = [ 71 "--cfg", 72 "test", 73 ] 74 } 75 76 # TODO(crbug.com/gn/104): GN rust_proc_macro targets are missing this 77 # command line flag, for the proc_macro crate which is provided by rustc for 78 # compiling proc-macros. 79 config("proc_macro_extern") { 80 rustflags = [ 81 "--extern", 82 "proc_macro", 83 ] 84 } 85 86 # Forbids unsafe code in crates with this config. 87 config("forbid_unsafe") { 88 rustflags = [ "-Funsafe_code" ] 89 } 90 91 config("panic_immediate_abort") { 92 visibility = [ "//chromium/build/rust/std/rules:*" ] 93 if (is_official_build) { 94 rustflags = [ 95 "--cfg", 96 "feature=\"panic_immediate_abort\"", 97 ] 98 } 99 } 100 101 config("is_gtest_unittests") { 102 rustflags = [ 103 "--cfg", 104 "is_gtest_unittests", 105 ] 106 }