• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TOOLS_GN_RUST_TARGET_VALUES_H_
6 #define TOOLS_GN_RUST_TARGET_VALUES_H_
7 
8 #include <map>
9 
10 #include "base/containers/flat_map.h"
11 #include "gn/label.h"
12 #include "gn/source_file.h"
13 
14 // Holds the values (outputs, args, script name, etc.) for either an action or
15 // an action_foreach target.
16 class RustValues {
17  public:
18   RustValues();
19   ~RustValues();
20 
21   // Library crate types are specified here. Shared library crate types must be
22   // specified, all other crate types can be automatically deduced from the
23   // target type (e.g. executables use crate_type = "bin", static_libraries use
24   // crate_type = "staticlib") unless explicitly set.
25   enum CrateType {
26     CRATE_AUTO = 0,
27     CRATE_BIN,
28     CRATE_CDYLIB,
29     CRATE_DYLIB,
30     CRATE_PROC_MACRO,
31     CRATE_RLIB,
32     CRATE_STATICLIB,
33   };
34 
35   // Name of this crate.
crate_name()36   std::string& crate_name() { return crate_name_; }
crate_name()37   const std::string& crate_name() const { return crate_name_; }
38 
39   // Main source file for this crate.
crate_root()40   const SourceFile& crate_root() const { return crate_root_; }
set_crate_root(SourceFile & s)41   void set_crate_root(SourceFile& s) { crate_root_ = s; }
42 
43   // Crate type for compilation.
crate_type()44   CrateType crate_type() const { return crate_type_; }
set_crate_type(CrateType s)45   void set_crate_type(CrateType s) { crate_type_ = s; }
46 
47   // Any renamed dependencies for the `extern` flags.
aliased_deps()48   const std::map<Label, std::string>& aliased_deps() const {
49     return aliased_deps_;
50   }
aliased_deps()51   std::map<Label, std::string>& aliased_deps() { return aliased_deps_; }
52 
53  private:
54   std::string crate_name_;
55   SourceFile crate_root_;
56   CrateType crate_type_ = CRATE_AUTO;
57   std::map<Label, std::string> aliased_deps_;
58 
59   DISALLOW_COPY_AND_ASSIGN(RustValues);
60 };
61 
62 #endif  // TOOLS_GN_RUST_TARGET_VALUES_H_
63