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