@@ -12,12 +12,9 @@ const PRELUDE: &str = r#"//! This file is generated code. Please edit the genera
12
12
13
13
fn generate_target_mapping ( f : & mut File , target_specs : & RustcTargetSpecs ) -> std:: io:: Result < ( ) > {
14
14
writeln ! ( f, "use super::Target;" ) ?;
15
+ writeln ! ( f, "use std::borrow::Cow;" ) ?;
15
16
writeln ! ( f) ?;
16
- writeln ! (
17
- f,
18
- "pub(crate) fn get(target_triple: &str) -> Option<Target> {{"
19
- ) ?;
20
- writeln ! ( f, " Some(match target_triple {{" ) ?;
17
+ writeln ! ( f, "pub(crate) const LIST: &[(&str, Target)] = &[" ) ?;
21
18
22
19
for ( triple, spec) in & target_specs. 0 {
23
20
let full_arch = triple. split_once ( '-' ) . unwrap ( ) . 0 ;
@@ -27,20 +24,20 @@ fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std
27
24
let env = spec. env . as_deref ( ) . unwrap_or ( "" ) ;
28
25
let abi = spec. abi . as_deref ( ) . unwrap_or ( "" ) ;
29
26
30
- writeln ! ( f, " {triple:?} => Target {{" ) ?;
31
- writeln ! ( f, " full_arch: {full_arch:?}.into()," ) ?;
32
- writeln ! ( f, " arch: {arch:?}.into()," ) ?;
33
- writeln ! ( f, " vendor: {vendor:?}.into()," ) ?;
34
- writeln ! ( f, " os: {os:?}.into()," ) ?;
35
- writeln ! ( f, " env: {env:?}.into()," ) ?;
36
- writeln ! ( f, " abi: {abi:?}.into()," ) ?;
27
+ writeln ! ( f, " (" ) ?;
28
+ writeln ! ( f, " {triple:?}," ) ?;
29
+ writeln ! ( f, " Target {{" ) ?;
30
+ writeln ! ( f, " full_arch: Cow::Borrowed({full_arch:?})," ) ?;
31
+ writeln ! ( f, " arch: Cow::Borrowed({arch:?})," ) ?;
32
+ writeln ! ( f, " vendor: Cow::Borrowed({vendor:?})," ) ?;
33
+ writeln ! ( f, " os: Cow::Borrowed({os:?})," ) ?;
34
+ writeln ! ( f, " env: Cow::Borrowed({env:?})," ) ?;
35
+ writeln ! ( f, " abi: Cow::Borrowed({abi:?})," ) ?;
37
36
writeln ! ( f, " }}," ) ?;
37
+ writeln ! ( f, " )," ) ?;
38
38
}
39
39
40
- writeln ! ( f, " _ => return None," ) ?;
41
-
42
- writeln ! ( f, " }})" ) ?;
43
- writeln ! ( f, "}}" ) ?;
40
+ writeln ! ( f, "];" ) ?;
44
41
45
42
Ok ( ( ) )
46
43
}
0 commit comments