1 // Copyright 2019 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
5 #include "gn/rust_variables.h"
6
7 namespace variables {
8
9 // Rust target variables ------------------------------------------------------
10
11 const char kRustAliasedDeps[] = "aliased_deps";
12 const char kRustAliasedDeps_HelpShort[] =
13 "aliased_deps: [scope] Set of crate-dependency pairs.";
14 const char kRustAliasedDeps_Help[] =
15 R"(aliased_deps: [scope] Set of crate-dependency pairs.
16
17 Valid for `rust_library` targets and `executable`, `static_library`, and
18 `shared_library` targets that contain Rust sources.
19
20 A scope, each key indicating the renamed crate and the corresponding value
21 specifying the label of the dependency producing the relevant binary.
22
23 All dependencies listed in this field *must* be listed as deps of the target.
24
25 executable("foo") {
26 sources = [ "main.rs" ]
27 deps = [ "//bar" ]
28 }
29
30 This target would compile the `foo` crate with the following `extern` flag:
31 `rustc ...command... --extern bar=<build_out_dir>/obj/bar`
32
33 executable("foo") {
34 sources = [ "main.rs" ]
35 deps = [ ":bar" ]
36 aliased_deps = {
37 bar_renamed = ":bar"
38 }
39 }
40
41 With the addition of `aliased_deps`, above target would instead compile with:
42 `rustc ...command... --extern bar_renamed=<build_out_dir>/obj/bar`
43 )";
44
45 const char kRustCrateName[] = "crate_name";
46 const char kRustCrateName_HelpShort[] =
47 "crate_name: [string] The name for the compiled crate.";
48 const char kRustCrateName_Help[] =
49 R"(crate_name: [string] The name for the compiled crate.
50
51 Valid for `rust_library` targets and `executable`, `static_library`,
52 `shared_library`, and `source_set` targets that contain Rust sources.
53
54 If crate_name is not set, then this rule will use the target name.
55 )";
56
57 const char kRustCrateType[] = "crate_type";
58 const char kRustCrateType_HelpShort[] =
59 "crate_type: [string] The type of linkage to use on a shared_library.";
60 const char kRustCrateType_Help[] =
61 R"(crate_type: [string] The type of linkage to use on a shared_library.
62
63 Valid for `rust_library` targets and `executable`, `static_library`,
64 `shared_library`, and `source_set` targets that contain Rust sources.
65
66 Options for this field are "cdylib", "staticlib", "proc-macro", and "dylib".
67 This field sets the `crate-type` attribute for the `rustc` tool on static
68 libraries, as well as the appropriate output extension in the
69 `rust_output_extension` attribute. Since outputs must be explicit, the `lib`
70 crate type (where the Rust compiler produces what it thinks is the
71 appropriate library type) is not supported.
72
73 It should be noted that the "dylib" crate type in Rust is unstable in the set
74 of symbols it exposes, and most usages today are potentially wrong and will
75 be broken in the future.
76
77 Static libraries, rust libraries, and executables have this field set
78 automatically.
79 )";
80
81 const char kRustCrateRoot[] = "crate_root";
82 const char kRustCrateRoot_HelpShort[] =
83 "crate_root: [string] The root source file for a binary or library.";
84 const char kRustCrateRoot_Help[] =
85 R"(crate_root: [string] The root source file for a binary or library.
86
87 Valid for `rust_library` targets and `executable`, `static_library`,
88 `shared_library`, and `source_set` targets that contain Rust sources.
89
90 This file is usually the `main.rs` or `lib.rs` for binaries and libraries,
91 respectively.
92
93 If crate_root is not set, then this rule will look for a lib.rs file (or
94 main.rs for executable) or a single file in sources, if sources contains
95 only one file.
96 )";
97
InsertRustVariables(VariableInfoMap * info_map)98 void InsertRustVariables(VariableInfoMap* info_map) {
99 info_map->insert(std::make_pair(
100 kRustAliasedDeps,
101 VariableInfo(kRustAliasedDeps_HelpShort, kRustAliasedDeps_Help)));
102 info_map->insert(std::make_pair(
103 kRustCrateName,
104 VariableInfo(kRustCrateName_HelpShort, kRustCrateName_Help)));
105 info_map->insert(std::make_pair(
106 kRustCrateType,
107 VariableInfo(kRustCrateType_HelpShort, kRustCrateType_Help)));
108 info_map->insert(std::make_pair(
109 kRustCrateRoot,
110 VariableInfo(kRustCrateRoot_HelpShort, kRustCrateRoot_Help)));
111 }
112
113 } // namespace variables
114