xref: /aosp_15_r20/external/angle/build/rust/rust_executable.gni (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2021 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard Workerimport("//build/rust/rust_target.gni")
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker# Defines a Rust executable.
8*8975f5c5SAndroid Build Coastguard Worker#
9*8975f5c5SAndroid Build Coastguard Worker# This is identical to the built-in gn intrinsic 'executable' but
10*8975f5c5SAndroid Build Coastguard Worker# supports some additional parameters, as below:
11*8975f5c5SAndroid Build Coastguard Worker#
12*8975f5c5SAndroid Build Coastguard Worker#   edition (optional)
13*8975f5c5SAndroid Build Coastguard Worker#     Edition of the Rust language to be used.
14*8975f5c5SAndroid Build Coastguard Worker#     Options are "2015", "2018" and "2021". Defaults to "2021".
15*8975f5c5SAndroid Build Coastguard Worker#
16*8975f5c5SAndroid Build Coastguard Worker#   test_deps (optional)
17*8975f5c5SAndroid Build Coastguard Worker#     List of GN targets on which this crate's tests depend, in addition
18*8975f5c5SAndroid Build Coastguard Worker#     to deps.
19*8975f5c5SAndroid Build Coastguard Worker#
20*8975f5c5SAndroid Build Coastguard Worker#   build_native_rust_unit_tests (optional)
21*8975f5c5SAndroid Build Coastguard Worker#     Builds native unit tests (under #[cfg(test)]) written inside the Rust
22*8975f5c5SAndroid Build Coastguard Worker#     crate. This will create a `<name>_unittests` executable in the output
23*8975f5c5SAndroid Build Coastguard Worker#     directory when set to true.
24*8975f5c5SAndroid Build Coastguard Worker#     Chromium code should not set this, and instead prefer to split the code
25*8975f5c5SAndroid Build Coastguard Worker#     into a library and write gtests against it. See how to do that in
26*8975f5c5SAndroid Build Coastguard Worker#     //testing/rust_gtest_interop/README.md.
27*8975f5c5SAndroid Build Coastguard Worker#
28*8975f5c5SAndroid Build Coastguard Worker#   unit_test_target (optional)
29*8975f5c5SAndroid Build Coastguard Worker#     Overrides the default name for the unit tests target
30*8975f5c5SAndroid Build Coastguard Worker#
31*8975f5c5SAndroid Build Coastguard Worker#   features (optional)
32*8975f5c5SAndroid Build Coastguard Worker#     A list of conditional compilation flags to enable. This can be used
33*8975f5c5SAndroid Build Coastguard Worker#     to set features for crates built in-tree which are also published to
34*8975f5c5SAndroid Build Coastguard Worker#     crates.io. Each feature in the list will be passed to rustc as
35*8975f5c5SAndroid Build Coastguard Worker#     '--cfg feature=XXX'
36*8975f5c5SAndroid Build Coastguard Worker#
37*8975f5c5SAndroid Build Coastguard Worker#   inputs (optional)
38*8975f5c5SAndroid Build Coastguard Worker#     Additional input files needed for compilation (such as `include!`ed files)
39*8975f5c5SAndroid Build Coastguard Worker#
40*8975f5c5SAndroid Build Coastguard Worker#   test_inputs (optional)
41*8975f5c5SAndroid Build Coastguard Worker#     Same as above but for the unit tests target
42*8975f5c5SAndroid Build Coastguard Worker#
43*8975f5c5SAndroid Build Coastguard Worker# Example of usage:
44*8975f5c5SAndroid Build Coastguard Worker#
45*8975f5c5SAndroid Build Coastguard Worker#   rust_executable("foo_bar") {
46*8975f5c5SAndroid Build Coastguard Worker#     deps = [
47*8975f5c5SAndroid Build Coastguard Worker#       "//boo/public/rust/bar",
48*8975f5c5SAndroid Build Coastguard Worker#     ]
49*8975f5c5SAndroid Build Coastguard Worker#     sources = [ "src/main.rs" ]
50*8975f5c5SAndroid Build Coastguard Worker#   }
51*8975f5c5SAndroid Build Coastguard Worker#
52*8975f5c5SAndroid Build Coastguard Worker# This template is intended to serve the same purpose as 'rustc_library'
53*8975f5c5SAndroid Build Coastguard Worker# in Fuchsia.
54*8975f5c5SAndroid Build Coastguard Workertemplate("rust_executable") {
55*8975f5c5SAndroid Build Coastguard Worker  rust_target(target_name) {
56*8975f5c5SAndroid Build Coastguard Worker    forward_variables_from(invoker,
57*8975f5c5SAndroid Build Coastguard Worker                           "*",
58*8975f5c5SAndroid Build Coastguard Worker                           TESTONLY_AND_VISIBILITY + [ "configs" ])
59*8975f5c5SAndroid Build Coastguard Worker    forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
60*8975f5c5SAndroid Build Coastguard Worker    executable_configs = invoker.configs
61*8975f5c5SAndroid Build Coastguard Worker    target_type = "executable"
62*8975f5c5SAndroid Build Coastguard Worker    assert(!defined(cxx_bindings))
63*8975f5c5SAndroid Build Coastguard Worker
64*8975f5c5SAndroid Build Coastguard Worker    # Executable targets should be unique names as they all get placed in the
65*8975f5c5SAndroid Build Coastguard Worker    # root output dir. We want their exe file name to be the same as the GN
66*8975f5c5SAndroid Build Coastguard Worker    # target, not a mangled name including the full GN path, and the exe file
67*8975f5c5SAndroid Build Coastguard Worker    # name comes from the crate name.
68*8975f5c5SAndroid Build Coastguard Worker    if (!defined(invoker.crate_name)) {
69*8975f5c5SAndroid Build Coastguard Worker      crate_name = target_name
70*8975f5c5SAndroid Build Coastguard Worker    }
71*8975f5c5SAndroid Build Coastguard Worker  }
72*8975f5c5SAndroid Build Coastguard Worker}
73*8975f5c5SAndroid Build Coastguard Worker
74*8975f5c5SAndroid Build Coastguard Workerset_defaults("rust_executable") {
75*8975f5c5SAndroid Build Coastguard Worker  configs = default_executable_configs
76*8975f5c5SAndroid Build Coastguard Worker}
77