rust_executable.gni 2.3 KB

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