Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 1 | rust: Fix BOOTSTRAP_CARGO failure during Rust Oe-selftest |
| 2 | |
| 3 | BOOTSTRAP_CARGO command fails due to codegen flags like `-Cpanic` were |
| 4 | prevented from being reflected in the current target configuration which |
| 5 | leads to Rust build(rust version 1.70) failure in Oe-selftest. |
| 6 | |
| 7 | Upstream-Status: Backport [https://github.com/rust-lang/rust/commit/9dffb52738e0b2ccd15af36d4607a709b21e020c] |
| 8 | |
| 9 | Signed-off-by: Yash Shinde <yashinde145@gmail.com> |
| 10 | --- |
| 11 | diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs |
| 12 | --- a/src/tools/compiletest/src/common.rs |
| 13 | +++ b/src/tools/compiletest/src/common.rs |
| 14 | @@ -431,7 +431,6 @@ |
| 15 | .unwrap() |
| 16 | }; |
| 17 | |
| 18 | - let mut current = None; |
| 19 | let mut all_targets = HashSet::new(); |
| 20 | let mut all_archs = HashSet::new(); |
| 21 | let mut all_oses = HashSet::new(); |
| 22 | @@ -452,14 +451,11 @@ |
| 23 | } |
| 24 | all_pointer_widths.insert(format!("{}bit", cfg.pointer_width)); |
| 25 | |
| 26 | - if target == config.target { |
| 27 | - current = Some(cfg); |
| 28 | - } |
| 29 | all_targets.insert(target.into()); |
| 30 | } |
| 31 | |
| 32 | Self { |
| 33 | - current: current.expect("current target not found"), |
| 34 | + current: Self::get_current_target_config(config), |
| 35 | all_targets, |
| 36 | all_archs, |
| 37 | all_oses, |
| 38 | @@ -471,6 +467,89 @@ |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | + fn get_current_target_config(config: &Config) -> TargetCfg { |
| 43 | + let mut arch = None; |
| 44 | + let mut os = None; |
| 45 | + let mut env = None; |
| 46 | + let mut abi = None; |
| 47 | + let mut families = Vec::new(); |
| 48 | + let mut pointer_width = None; |
| 49 | + let mut endian = None; |
| 50 | + let mut panic = None; |
| 51 | + |
| 52 | + for config in |
| 53 | + rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines() |
| 54 | + { |
| 55 | + let (name, value) = config |
| 56 | + .split_once("=\"") |
| 57 | + .map(|(name, value)| { |
| 58 | + ( |
| 59 | + name, |
| 60 | + Some( |
| 61 | + value |
| 62 | + .strip_suffix("\"") |
| 63 | + .expect("key-value pair should be properly quoted"), |
| 64 | + ), |
| 65 | + ) |
| 66 | + }) |
| 67 | + .unwrap_or_else(|| (config, None)); |
| 68 | + |
| 69 | + match name { |
| 70 | + "target_arch" => { |
| 71 | + arch = Some(value.expect("target_arch should be a key-value pair").to_string()); |
| 72 | + } |
| 73 | + "target_os" => { |
| 74 | + os = Some(value.expect("target_os sould be a key-value pair").to_string()); |
| 75 | + } |
| 76 | + "target_env" => { |
| 77 | + env = Some(value.expect("target_env should be a key-value pair").to_string()); |
| 78 | + } |
| 79 | + "target_abi" => { |
| 80 | + abi = Some(value.expect("target_abi should be a key-value pair").to_string()); |
| 81 | + } |
| 82 | + "target_family" => { |
| 83 | + families |
| 84 | + .push(value.expect("target_family should be a key-value pair").to_string()); |
| 85 | + } |
| 86 | + "target_pointer_width" => { |
| 87 | + pointer_width = Some( |
| 88 | + value |
| 89 | + .expect("target_pointer_width should be a key-value pair") |
| 90 | + .parse::<u32>() |
| 91 | + .expect("target_pointer_width should be a valid u32"), |
| 92 | + ); |
| 93 | + } |
| 94 | + "target_endian" => { |
| 95 | + endian = Some(match value.expect("target_endian should be a key-value pair") { |
| 96 | + "big" => Endian::Big, |
| 97 | + "little" => Endian::Little, |
| 98 | + _ => panic!("target_endian should be either 'big' or 'little'"), |
| 99 | + }); |
| 100 | + } |
| 101 | + "panic" => { |
| 102 | + panic = Some(match value.expect("panic should be a key-value pair") { |
| 103 | + "abort" => PanicStrategy::Abort, |
| 104 | + "unwind" => PanicStrategy::Unwind, |
| 105 | + _ => panic!("panic should be either 'abort' or 'unwind'"), |
| 106 | + }); |
| 107 | + } |
| 108 | + _ => (), |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + TargetCfg { |
| 113 | + arch: arch.expect("target configuration should specify target_arch"), |
| 114 | + os: os.expect("target configuration should specify target_os"), |
| 115 | + env: env.expect("target configuration should specify target_env"), |
| 116 | + abi: abi.expect("target configuration should specify target_abi"), |
| 117 | + families, |
| 118 | + pointer_width: pointer_width |
| 119 | + .expect("target configuration should specify target_pointer_width"), |
| 120 | + endian: endian.expect("target configuration should specify target_endian"), |
| 121 | + panic: panic.expect("target configuration should specify panic"), |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | // #[cfg(bootstrap)] |
| 126 | // Needed only for one cycle, remove during the bootstrap bump. |
| 127 | fn collect_all_slow(config: &Config) -> HashMap<String, TargetCfg> { |