pub fn is_bazel_supported_platform(target: &str) -> BazelTargetSupport {
  // Ensure the target is represented as an expression
  let target_exp = match target.starts_with("cfg(") {
    true => target.to_owned(),
    false => format!("cfg(target = \"{}\")", target),
  };

  let expression = match Expression::parse(&target_exp) {
    Ok(exp) => exp,
    // If the target expression cannot be parsed it is not considered a Bazel platform
    Err(_) => return BazelTargetSupport::Unsupported,
  };

  let mut specific_match = false;
  let mut matches_all = true;

  // Attempt to match the expression
  for target_info in SUPPORTED_PLATFORM_TRIPLES
    .iter()
    .map(|x| get_builtin_target_by_triple(x).unwrap())
  {
    let target_matches = expression.eval(|pred| {
      match pred {
        Predicate::Target(tp) => tp.matches(target_info),
        Predicate::KeyValue { key, val } => (*key == "target") && (*val == target_info.triple),
        // For now there is no other kind of matching
        _ => false,
      }
    });

    if target_matches {
      specific_match = true;
    } else {
      matches_all = false;
    }
  }

  match (specific_match, matches_all) {
    (true, true) => BazelTargetSupport::AllTargetsMatch,
    (true, false) => BazelTargetSupport::SpecificTargetMatches,
    _ => BazelTargetSupport::Unsupported,
  }
}
/// Determines if the target matches those supported by and defined in rules_rust
Determines if the target matches those supported by and defined in rules_rust
Determines if the target matches those supported by and defined in rules_rust
pub fn is_bazel_supported_platform(target: &str) -> BazelTargetSupport {
  // Ensure the target is represented as an expression
  let target_exp = match target.starts_with("cfg(") {
    true => target.to_owned(),
    false => format!("cfg(target = \"{}\")", target),
  };
  let expression = match Expression::parse(&target_exp) {
    Ok(exp) => exp,
    // If the target expression cannot be parsed it is not considered a Bazel platform
    Err(_) => return BazelTargetSupport::Unsupported,
  };
  let mut specific_match = false;
  let mut matches_all = true;
  // Attempt to match the expression
  for target_info in SUPPORTED_PLATFORM_TRIPLES
    .iter()
    .map(|x| get_builtin_target_by_triple(x).unwrap())
  {
    let target_matches = expression.eval(|pred| {
      match pred {
        Predicate::Target(tp) => tp.matches(target_info),
        Predicate::KeyValue { key, val } => (*key == "target") && (*val == target_info.triple),
        // For now there is no other kind of matching
        _ => false,
      }
    });
    if target_matches {
      specific_match = true;
    } else {
      matches_all = false;
    }
  }
  match (specific_match, matches_all) {
    (true, true) => BazelTargetSupport::AllTargetsMatch,
    (true, false) => BazelTargetSupport::SpecificTargetMatches,
    _ => BazelTargetSupport::Unsupported,
  }
}
pub fn is_bazel_supported_platform ( target : & str ) -> BazelTargetSupport { // Ensure the target is represented as an expression let target_exp = match target . starts_with ( " " ) { true => target . to_owned ( ) , false => format ! ( " \" \" " target ) , } ; let expression = match Expression :: parse ( & target_exp ) { Ok ( exp ) => exp , // If the target expression cannot be parsed it is not considered a Bazel platform Err ( _ ) => return BazelTargetSupport :: Unsupported , } ; let mut specific_match = false ; let mut matches_all = true ; // Attempt to match the expression for target_info in SUPPORTED_PLATFORM_TRIPLES . iter ( ) . map ( | x | get_builtin_target_by_triple ( x ) . unwrap ( ) ) { let target_matches = expression . eval ( | pred | { match pred { Predicate :: Target ( tp ) => tp . matches ( target_info ) , Predicate :: KeyValue { key , val } => ( * key == " " ) && ( * val == target_info . triple ) , // For now there is no other kind of matching _ => false , } } ) ; if target_matches { specific_match = true ; } else { matches_all = false ; } } match ( specific_match , matches_all ) { ( true , true ) => BazelTargetSupport :: AllTargetsMatch , ( true , false ) => BazelTargetSupport :: SpecificTargetMatches , _ => BazelTargetSupport :: Unsupported , } }
Determines if the target matches those supported by and defined in rules_rust
Determines if the target matches those supported by and defined in rules_rust
target
&str
target
&str