about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-01-21 21:01:49 +0800
committerJieyou Xu <jieyouxu@outlook.com>2025-01-29 08:10:05 +0000
commitdd616d6a16288a0e8d79405650db2e68762a4367 (patch)
treee82ef747cc8619c50c3f84e5f5d4e18a8ecf0a59
parentccc9ba5c30c675824e9ca62b960830ff4a1858ea (diff)
downloadrust-dd616d6a16288a0e8d79405650db2e68762a4367.tar.gz
rust-dd616d6a16288a0e8d79405650db2e68762a4367.zip
run-make-support: add `sysroot` helper
Convenience helper for `rustc --print=sysroot`.
-rw-r--r--src/tools/run-make-support/src/external_deps/rustc.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs
index 8894ea7fb20..b70db7130f6 100644
--- a/src/tools/run-make-support/src/external_deps/rustc.rs
+++ b/src/tools/run-make-support/src/external_deps/rustc.rs
@@ -1,5 +1,6 @@
 use std::ffi::{OsStr, OsString};
-use std::path::Path;
+use std::path::{Path, PathBuf};
+use std::str::FromStr as _;
 
 use crate::command::Command;
 use crate::env::env_var;
@@ -390,3 +391,10 @@ impl Rustc {
         self
     }
 }
+
+/// Query the sysroot path corresponding `rustc --print=sysroot`.
+#[track_caller]
+pub fn sysroot() -> PathBuf {
+    let path = rustc().print("sysroot").run().stdout_utf8();
+    PathBuf::from_str(path.trim()).unwrap()
+}