• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_PROJECT_WRITER_H_
6 #define TOOLS_GN_RUST_PROJECT_WRITER_H_
7 
8 #include "gn/err.h"
9 #include "gn/target.h"
10 
11 class Builder;
12 class BuildSettings;
13 
14 // rust-project.json is an output format describing the rust build graph. It is
15 // used by rust-analyzer (a LSP server), similar to compile-commands.json.
16 //
17 // an example output is in rust_project_writer.cc
18 class RustProjectWriter {
19  public:
20   // Write Rust build graph into a json file located by parameter file_name.
21   //
22   // Parameter quiet is not used.
23   static bool RunAndWriteFiles(const BuildSettings* build_setting,
24                                const Builder& builder,
25                                const std::string& file_name,
26                                bool quiet,
27                                Err* err);
28   static void RenderJSON(const BuildSettings* build_settings,
29                          std::vector<const Target*>& all_targets,
30                          std::ostream& rust_project);
31 
32  private:
33   // This function visits the deps graph of a target in a DFS fashion.
34   static void VisitDeps(const Target* target, TargetSet* visited);
35 };
36 
37 #endif  // TOOLS_GN_RUST_PROJECT_WRITER_H_
38