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