File: BUILD.gn

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 3,072 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/rust.gni")

if (toolchain_has_rust) {
  config("edition_2024") {
    rustflags = [ "--edition=2024" ]
  }

  config("edition_2021") {
    rustflags = [ "--edition=2021" ]
  }

  config("edition_2018") {
    rustflags = [ "--edition=2018" ]
  }

  config("edition_2015") {
    rustflags = [ "--edition=2015" ]
  }

  if (enable_rust_cxx) {
    # The required dependencies for cxx-generated bindings, that must be included
    # on the C++ side.
    static_library("cxx_cppdeps") {
      sources = [
        "//third_party/rust/chromium_crates_io/vendor/cxx-v1/include/cxx.h",
        "//third_party/rust/chromium_crates_io/vendor/cxx-v1/src/cxx.cc",

        # Our version-independent forwarding header, which we patch cxx.cc to
        # use since we want it to use an absolute path for its include.
        "//third_party/rust/cxx/v1/cxx.h",
      ]

      defines = [ "RUST_CXX_NO_EXCEPTIONS" ]

      # We cannot depend on base/base_export.h because base depends on us.
      if (is_component_build) {
        if (is_win) {
          defines += [ "CXX_RS_EXPORT=__declspec(dllexport)" ]
        } else {
          defines +=
              [ "CXX_RS_EXPORT=__attribute__((visibility(\"default\")))" ]
        }
      } else {
        defines += [ "CXX_RS_EXPORT=" ]
      }

      deps = [
        # Depending on the C++ bindings side of cxx then requires also depending
        # on the Rust bindings, since one calls the other. And the Rust bindings
        # require the Rust standard library.
        ":cxx_rustdeps",
      ]
    }

    group("cxx_rustdeps") {
      # The required dependencies for cxx-generated bindings, that must be
      # included on the Rust side.
      public_deps = [ "//third_party/rust/cxx/v1:lib" ]
    }
  }
}

# Enables code behind #[cfg(test)]. This should only be used for targets where
# testonly=true.
config("test") {
  rustflags = [
    "--cfg",
    "test",
  ]
}

# TODO(crbug.com/gn/104): GN rust_proc_macro targets are missing this
# command line flag, for the proc_macro crate which is provided by rustc for
# compiling proc-macros.
config("proc_macro_extern") {
  rustflags = [
    "--extern",
    "proc_macro",
  ]
}

# Forbids unsafe code in crates with this config.  See also `allow_unsafe` which
# may be set in 1) `rust_static_library`, `rust_executable` and other targets,
# 2) `gnrt_config.toml` entries for individual third-party crates.
config("forbid_unsafe") {
  rustflags = [
    # `-F` = "forbid".  Documentation of the warning can be found in
    # https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unsafe-code
    "-Funsafe_code",
  ]
}

config("panic_immediate_abort") {
  visibility = [ "//build/rust/std/rules:*" ]
  if (is_official_build) {
    rustflags = [
      "--cfg",
      "feature=\"panic_immediate_abort\"",
    ]
  }
}

config("is_gtest_unittests") {
  rustflags = [
    "--cfg",
    "is_gtest_unittests",
  ]
}