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 #include "gn/rust_tool.h" 6 #include "gn/rust_values.h" 7 #include "gn/target.h" 8 RustValues()9RustValues::RustValues() : crate_type_(RustValues::CRATE_AUTO) {} 10 11 RustValues::~RustValues() = default; 12 13 // static InferredCrateType(const Target * target)14RustValues::CrateType RustValues::InferredCrateType(const Target* target) { 15 // TODO: Consider removing crate_type. It allows for things like 16 // 17 // executable("foo") { 18 // crate_type = "rlib" 19 // } 20 // 21 // Which doesn't make sense. 22 if (!target->source_types_used().RustSourceUsed()) { 23 return CRATE_AUTO; 24 } 25 if (!target->has_rust_values()) 26 return CRATE_AUTO; 27 28 CrateType crate_type = target->rust_values().crate_type(); 29 if (crate_type != CRATE_AUTO) { 30 return crate_type; 31 } 32 33 switch (target->output_type()) { 34 case Target::EXECUTABLE: 35 return CRATE_BIN; 36 case Target::SHARED_LIBRARY: 37 return CRATE_DYLIB; 38 case Target::STATIC_LIBRARY: 39 return CRATE_STATICLIB; 40 case Target::RUST_LIBRARY: 41 return CRATE_RLIB; 42 case Target::RUST_PROC_MACRO: 43 return CRATE_PROC_MACRO; 44 default: 45 return CRATE_AUTO; 46 } 47 } 48 49 // static IsRustLibrary(const Target * target)50bool RustValues::IsRustLibrary(const Target* target) { 51 return target->output_type() == Target::RUST_LIBRARY || 52 InferredCrateType(target) == CRATE_DYLIB || 53 InferredCrateType(target) == CRATE_PROC_MACRO; 54 } 55