• 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 #include "gn/rust_substitution_type.h"
6 
7 #include <stddef.h>
8 #include <stdlib.h>
9 
10 #include "gn/err.h"
11 #include "gn/substitution_type.h"
12 #include "gn/c_substitution_type.h"
13 
14 const SubstitutionTypes RustSubstitutions = {
15     &kRustSubstitutionCrateName,       &kRustSubstitutionCrateType,
16     &kRustSubstitutionRustDeps,        &kRustSubstitutionRustFlags,
17     &kRustSubstitutionRustEnv,         &kRustSubstitutionExterns,
18     &kRustSubstitutionSources,
19 };
20 
21 // Valid for Rust tools.
22 const Substitution kRustSubstitutionCrateName = {"{{crate_name}}",
23                                                  "crate_name"};
24 const Substitution kRustSubstitutionCrateType = {"{{crate_type}}",
25                                                  "crate_type"};
26 const Substitution kRustSubstitutionExterns = {"{{externs}}", "externs"};
27 const Substitution kRustSubstitutionRustDeps = {"{{rustdeps}}", "rustdeps"};
28 const Substitution kRustSubstitutionRustEnv = {"{{rustenv}}", "rustenv"};
29 const Substitution kRustSubstitutionRustFlags = {"{{rustflags}}", "rustflags"};
30 const Substitution kRustSubstitutionSources = {"{{sources}}", "sources"};
31 
IsValidRustSubstitution(const Substitution * type)32 bool IsValidRustSubstitution(const Substitution* type) {
33   return IsValidToolSubstitution(type) || IsValidSourceSubstitution(type) ||
34          type == &SubstitutionOutputDir ||
35          type == &SubstitutionOutputExtension ||
36          type == &kRustSubstitutionCrateName ||
37          type == &kRustSubstitutionCrateType ||
38          type == &kRustSubstitutionExterns ||
39          type == &kRustSubstitutionRustDeps ||
40          type == &kRustSubstitutionRustEnv ||
41          type == &kRustSubstitutionRustFlags ||
42          type == &kRustSubstitutionSources;
43 }
44 
45 // Rust substitution types which we also make available to action targets.
IsValidRustScriptArgsSubstitution(const Substitution * type)46 bool IsValidRustScriptArgsSubstitution(const Substitution* type) {
47   return type == &kRustSubstitutionRustEnv ||
48          type == &kRustSubstitutionRustFlags;
49 }
50 
IsValidRustLinkerSubstitution(const Substitution * type)51 bool IsValidRustLinkerSubstitution(const Substitution* type) {
52   return IsValidRustSubstitution(type) ||
53          type == &CSubstitutionLdFlags;
54 }
55