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_TOOL_H_ 6 #define TOOLS_GN_RUST_TOOL_H_ 7 8 #include <string> 9 #include <string_view> 10 11 #include "base/logging.h" 12 #include "gn/label.h" 13 #include "gn/label_ptr.h" 14 #include "gn/rust_values.h" 15 #include "gn/source_file.h" 16 #include "gn/substitution_list.h" 17 #include "gn/substitution_pattern.h" 18 #include "gn/target.h" 19 #include "gn/tool.h" 20 21 class RustTool : public Tool { 22 public: 23 // Rust tools 24 static const char* kRsToolBin; 25 static const char* kRsToolCDylib; 26 static const char* kRsToolDylib; 27 static const char* kRsToolMacro; 28 static const char* kRsToolRlib; 29 static const char* kRsToolStaticlib; 30 31 explicit RustTool(const char* n); 32 ~RustTool(); 33 34 // Manual RTTI and required functions --------------------------------------- 35 36 bool InitTool(Scope* block_scope, Toolchain* toolchain, Err* err); 37 bool ValidateName(const char* name) const override; 38 void SetComplete() override; 39 bool ValidateSubstitution(const Substitution* sub_type) const override; 40 bool MayLink() const; 41 42 RustTool* AsRust() override; 43 const RustTool* AsRust() const override; 44 45 std::string_view GetSysroot() const; 46 47 private: 48 std::string rust_sysroot_; 49 50 bool SetOutputExtension(const Value* value, std::string* var, Err* err); 51 bool ReadOutputsPatternList(Scope* scope, 52 const char* var, 53 SubstitutionList* field, 54 Err* err); 55 56 RustTool(const RustTool&) = delete; 57 RustTool& operator=(const RustTool&) = delete; 58 }; 59 60 #endif // TOOLS_GN_RUST_TOOL_H_ 61