/[packages]/cauldron/rust/current/SOURCES/0001-Try-to-get-the-target-triple-from-rustc-itself.patch
ViewVC logotype

Contents of /cauldron/rust/current/SOURCES/0001-Try-to-get-the-target-triple-from-rustc-itself.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1357861 - (show annotations) (download)
Fri Jan 18 08:40:20 2019 UTC (5 years, 8 months ago) by akien
File size: 3309 byte(s)
- Sync with Fedora: Thu Jan 17 2019 Josh Stone <jistone@redhat.com> - 1.32.0-1
  o Update to 1.32.0.
1 From 72cd8aedc2901d6a6b598eadc001cc39040ae487 Mon Sep 17 00:00:00 2001
2 From: Josh Stone <jistone@redhat.com>
3 Date: Wed, 12 Dec 2018 16:51:31 -0800
4 Subject: [PATCH] Try to get the target triple from rustc itself
5
6 The prior method was trying to pick the triple out of the sysroot path.
7 A FIXME comment already notes that this doesn't work with custom
8 toolchains in rustup. It also fails with distro-installed toolchains,
9 where the sysroot may simply be `/usr`.
10
11 The output of `rustc -Vv` is a more reliable source, as it contains a
12 line like `host: x86_64-unknown-linux-gnu`. This should be enough to
13 identify the triple for any `rustc`, but just in case, the path-based
14 code is kept as a fallback.
15 ---
16 src/loader.rs | 41 ++++++++++++++++++++++++++++++++++++++---
17 1 file changed, 38 insertions(+), 3 deletions(-)
18
19 diff --git a/src/loader.rs b/src/loader.rs
20 index 645c95139164..fe92bef1c596 100644
21 --- a/src/loader.rs
22 +++ b/src/loader.rs
23 @@ -108,9 +108,33 @@ impl AnalysisLoader for CargoAnalysisLoader {
24 }
25 }
26
27 +fn extract_target_triple(sys_root_path: &Path) -> String {
28 + // First try to get the triple from the rustc version output,
29 + // otherwise fall back on the rustup-style toolchain path.
30 + extract_rustc_host_triple()
31 + .unwrap_or_else(|| extract_rustup_target_triple(sys_root_path))
32 +}
33 +
34 +fn extract_rustc_host_triple() -> Option<String> {
35 + let rustc = env::var("RUSTC").unwrap_or(String::from("rustc"));
36 + let verbose_version = Command::new(rustc)
37 + .arg("--verbose")
38 + .arg("--version")
39 + .output()
40 + .ok()
41 + .and_then(|out| String::from_utf8(out.stdout).ok())?;
42 +
43 + // Extracts the triple from a line like `host: x86_64-unknown-linux-gnu`
44 + verbose_version
45 + .lines()
46 + .find(|line| line.starts_with("host: "))
47 + .and_then(|host| host.split_whitespace().nth(1))
48 + .map(String::from)
49 +}
50 +
51 // FIXME: This can fail when using a custom toolchain in rustup (often linked to
52 // `/$rust_repo/build/$target/stage2`)
53 -fn extract_target_triple(sys_root_path: &Path) -> String {
54 +fn extract_rustup_target_triple(sys_root_path: &Path) -> String {
55 // Extracts nightly-x86_64-pc-windows-msvc from
56 // $HOME/.rustup/toolchains/nightly-x86_64-pc-windows-msvc
57 let toolchain = sys_root_path
58 @@ -169,7 +193,7 @@ mod tests {
59 r#"C:\Users\user\.rustup\toolchains\nightly-x86_64-pc-windows-msvc"#,
60 );
61 assert_eq!(
62 - extract_target_triple(path),
63 + extract_rustup_target_triple(path),
64 String::from("x86_64-pc-windows-msvc")
65 );
66 }
67 @@ -180,8 +204,19 @@ mod tests {
68 "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu",
69 );
70 assert_eq!(
71 - extract_target_triple(path),
72 + extract_rustup_target_triple(path),
73 String::from("x86_64-unknown-linux-gnu")
74 );
75 }
76 +
77 + #[test]
78 + fn target_triple() {
79 + let sys_root_path = sys_root_path();
80 + let target_triple = extract_target_triple(&sys_root_path);
81 + let target_path = sys_root_path
82 + .join("lib")
83 + .join("rustlib")
84 + .join(&target_triple);
85 + assert!(target_path.is_dir(), "{:?} is not a directory!", target_path);
86 + }
87 }
88 --
89 2.19.2
90

  ViewVC Help
Powered by ViewVC 1.1.30