• 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_NINJA_RUST_BINARY_TARGET_WRITER_H_
6 #define TOOLS_GN_NINJA_RUST_BINARY_TARGET_WRITER_H_
7 
8 #include "gn/ninja_binary_target_writer.h"
9 #include "gn/output_file.h"
10 #include "gn/rust_tool.h"
11 #include "gn/target.h"
12 
13 // Writes a .ninja file for a binary target type (an executable, a shared
14 // library, or a static library).
15 class NinjaRustBinaryTargetWriter : public NinjaBinaryTargetWriter {
16  public:
17   NinjaRustBinaryTargetWriter(const Target* target, std::ostream& out);
18   ~NinjaRustBinaryTargetWriter() override;
19 
20   void Run() override;
21 
22  private:
23   struct ExternCrate {
24     const Target* target;
25     bool has_direct_access;
26   };
27 
28   void WriteCompilerVars();
29   void WriteSources(const OutputFile& input_dep,
30                     const std::vector<OutputFile>& order_only_deps);
31   void WriteExternsAndDeps(const std::vector<const Target*>& deps,
32                            const std::vector<ExternCrate>& transitive_rust_deps,
33                            const std::vector<OutputFile>& rustdeps,
34                            const std::vector<OutputFile>& nonrustdeps);
35   // Unlike C/C++, Rust compiles all sources of a crate in one command.
36   // Write a ninja variable `sources` that contains all sources and input files.
37   void WriteSourcesAndInputs();
38   void WriteEdition();
39   void AppendSourcesAndInputsToImplicitDeps(
40       UniqueVector<OutputFile>* deps) const;
41 
42   const RustTool* tool_;
43 
44   NinjaRustBinaryTargetWriter(const NinjaRustBinaryTargetWriter&) = delete;
45   NinjaRustBinaryTargetWriter& operator=(const NinjaRustBinaryTargetWriter&) =
46       delete;
47 };
48 
49 #endif  // TOOLS_GN_NINJA_RUST_BINARY_TARGET_WRITER_H_
50