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.
5 import("//build/rust/rust_target.gni")
7 # Defines a Rust executable.
9 # This is identical to the built-in gn intrinsic 'executable' but
10 # supports some additional parameters, as below:
13 # Edition of the Rust language to be used.
14 # Options are "2015", "2018" and "2021". Defaults to "2021".
16 # test_deps (optional)
17 # List of GN targets on which this crate's tests depend, in addition
20 # build_native_rust_unit_tests (optional)
21 # Builds native unit tests (under #[cfg(test)]) written inside the Rust
22 # crate. This will create a `<name>_unittests` executable in the output
23 # directory when set to true.
24 # Chromium code should not set this, and instead prefer to split the code
25 # into a library and write gtests against it. See how to do that in
26 # //testing/rust_gtest_interop/README.md.
28 # unit_test_target (optional)
29 # Overrides the default name for the unit tests target
32 # A list of conditional compilation flags to enable. This can be used
33 # to set features for crates built in-tree which are also published to
34 # crates.io. Each feature in the list will be passed to rustc as
38 # Additional input files needed for compilation (such as `include!`ed files)
40 # test_inputs (optional)
41 # Same as above but for the unit tests target
45 # rust_executable("foo_bar") {
47 # "//boo/public/rust/bar",
49 # sources = [ "src/main.rs" ]
52 # This template is intended to serve the same purpose as 'rustc_library'
54 template("rust_executable") {
55 rust_target(target_name) {
56 forward_variables_from(invoker,
58 TESTONLY_AND_VISIBILITY + [ "configs" ])
59 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
60 executable_configs = invoker.configs
61 target_type = "executable"
62 assert(!defined(cxx_bindings))
66 set_defaults("rust_executable") {
67 configs = default_executable_configs