rust_executable.gni (2598B)
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 5 import("//chromium/build/rust/rust_target.gni") 6 7 # Defines a Rust executable. 8 # 9 # This is identical to the built-in gn intrinsic 'executable' but 10 # supports some additional parameters, as below: 11 # 12 # edition (optional) 13 # Edition of the Rust language to be used. 14 # Options are "2015", "2018" and "2021". Defaults to "2021". 15 # 16 # test_deps (optional) 17 # List of GN targets on which this crate's tests depend, in addition 18 # to deps. 19 # 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. 27 # 28 # unit_test_target (optional) 29 # Overrides the default name for the unit tests target 30 # 31 # features (optional) 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 35 # '--cfg feature=XXX' 36 # 37 # inputs (optional) 38 # Additional input files needed for compilation (such as `include!`ed files) 39 # 40 # test_inputs (optional) 41 # Same as above but for the unit tests target 42 # 43 # Example of usage: 44 # 45 # rust_executable("foo_bar") { 46 # deps = [ 47 # "//boo/public/rust/bar", 48 # ] 49 # sources = [ "src/main.rs" ] 50 # } 51 # 52 # This template is intended to serve the same purpose as 'rustc_library' 53 # in Fuchsia. 54 template("rust_executable") { 55 rust_target(target_name) { 56 forward_variables_from(invoker, 57 "*", 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)) 63 64 # Executable targets should be unique names as they all get placed in the 65 # root output dir. We want their exe file name to be the same as the GN 66 # target, not a mangled name including the full GN path, and the exe file 67 # name comes from the crate name. 68 if (!defined(invoker.crate_name)) { 69 crate_name = target_name 70 } 71 } 72 } 73 74 set_defaults("rust_executable") { 75 configs = default_executable_configs 76 }