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 dynamic_link_switch()47 const std::string& dynamic_link_switch() const { 48 return dynamic_link_switch_; 49 } set_dynamic_link_switch(std::string s)50 void set_dynamic_link_switch(std::string s) { 51 DCHECK(!complete_); 52 dynamic_link_switch_ = std::move(s); 53 } 54 55 private: 56 std::string rust_sysroot_; 57 std::string dynamic_link_switch_; 58 59 bool SetOutputExtension(const Value* value, std::string* var, Err* err); 60 bool ReadOutputsPatternList(Scope* scope, 61 const char* var, 62 SubstitutionList* field, 63 Err* err); 64 65 RustTool(const RustTool&) = delete; 66 RustTool& operator=(const RustTool&) = delete; 67 }; 68 69 #endif // TOOLS_GN_RUST_TOOL_H_ 70