summaryrefslogtreecommitdiffstats
path: root/debian/patches/u-fix-get-toml-when-test.patch
blob: 09ba0552ef18eba0fd0f688362a41fa229503170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Description: Fix get_toml() when cfg(test)
 When cfg(test), Config::parse doesn't parse a config.toml but uses default
 values, failing when the initial rustc is needed. This is a workaround before
 upstream issue gets solved.
Bug: https://github.com/rust-lang/rust/issues/105766
Last-Update: 2023-03-29
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: rust/src/bootstrap/src/core/config/config.rs
===================================================================
--- rust.orig/src/bootstrap/src/core/config/config.rs
+++ rust/src/bootstrap/src/core/config/config.rs
@@ -1093,8 +1093,32 @@ impl Config {
 
     pub fn parse(args: &[String]) -> Config {
         #[cfg(test)]
-        fn get_toml(_: &Path) -> TomlConfig {
-            TomlConfig::default()
+        fn get_toml(file: &Path) -> TomlConfig {
+            // Debian: We use previous version as a custom rustc, which
+            // unfortunately won't be picked up because config.toml isn't
+            // read when cfg!(test). Making tests use the entirety of our
+            // config.toml isn't feasible either as it panicks on
+            // GitRepo::Llvm (d-bootstrap-custom-debuginfo-path.patch), so
+            // only give paths of initial rustc and cargo.
+            let contents =
+                t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
+            // Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
+            // TomlConfig and sub types to be monomorphized 5x by toml.
+            toml::from_str(&contents)
+                .and_then(|table: toml::Value| TomlConfig::deserialize(table))
+                .map(|table| {
+                    let mut config = TomlConfig::default();
+                    let mut build = Build::default();
+                    let cbuild = table.build.unwrap();
+                    build.rustc = cbuild.rustc;
+                    build.cargo = cbuild.cargo;
+                    config.build = Some(build);
+                    config
+                })
+                .unwrap_or_else(|err| {
+                    eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
+                    crate::detail_exit(2);
+                })
         }
 
         #[cfg(not(test))]