summaryrefslogtreecommitdiffstats
path: root/chromium/build/rust/BUILD.gn
blob: 3359bf939c8903ccec48525688f9ae6350a99011 (plain)
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
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

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

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

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

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

  defines = [ "RUST_CXX_NO_EXCEPTIONS" ]

  if (is_win) {
    defines += [ "CXX_RS_EXPORT=__declspec(dllexport)" ]
  } else {
    defines += [ "CXX_RS_EXPORT=__attribute__((visibility(\"default\")))" ]
  }

  # 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.
  # Normally the Rust stdlib is brought in as a dependency by depending
  # on any first-party Rust target. But in this case, it's conceivable
  # that pure-C++ targets will not depend on any 1p Rust code so we'll add
  # the Rust stdlib explicitly.
  deps = [
    ":cxx_rustdeps",
    "//build/rust/std",
  ]
}

# The required dependencies for cxx-generated bindings, that must be included
# on the Rust side.
group("cxx_rustdeps") {
  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",
  ]
}

# The required dependencies for autocxx-generated bindings, that must be included
# on the Rust side.
group("autocxx_rustdeps") {
  # Depend upon cxx as well as autocxx due to https://github.com/google/autocxx/issues/36
  public_deps = [
    "//third_party/rust/autocxx/v0_17:lib",
    "//third_party/rust/cxx/v1:lib",
  ]
}