Skip to content

Commit 515fa51

Browse files
committed
Make Sysroot::install async
So that we can call it from async functions.
1 parent e90a9d5 commit 515fa51

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

collector/src/bin/collector.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,8 @@ fn main_result() -> anyhow::Result<i32> {
10551055
}
10561056
};
10571057
let sha = commit.sha.to_string();
1058-
let sysroot = Sysroot::install(sha.clone(), &target_triple, &backends)
1058+
let sysroot = rt
1059+
.block_on(Sysroot::install(sha.clone(), &target_triple, &backends))
10591060
.with_context(|| {
10601061
format!("failed to install sysroot for {:?}", commit)
10611062
})?;
@@ -1245,7 +1246,13 @@ fn main_result() -> anyhow::Result<i32> {
12451246
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
12461247
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
12471248
let commit = get_commit_or_fake_it(last_sha).expect("success");
1248-
let mut sysroot = Sysroot::install(commit.sha, &target_triple, &codegen_backends.0)?;
1249+
1250+
let rt = build_async_runtime();
1251+
let mut sysroot = rt.block_on(Sysroot::install(
1252+
commit.sha,
1253+
&target_triple,
1254+
&codegen_backends.0,
1255+
))?;
12491256
sysroot.preserve(); // don't delete it
12501257

12511258
// Print the directory containing the toolchain.

collector/src/toolchain.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ pub struct Sysroot {
2020
}
2121

2222
impl Sysroot {
23-
pub fn install(sha: String, triple: &str, backends: &[CodegenBackend]) -> anyhow::Result<Self> {
23+
pub async fn install(
24+
sha: String,
25+
triple: &str,
26+
backends: &[CodegenBackend],
27+
) -> anyhow::Result<Self> {
2428
let unpack_into = "cache";
2529

2630
fs::create_dir_all(unpack_into)?;
@@ -31,12 +35,12 @@ impl Sysroot {
3135
triple: triple.to_owned(),
3236
};
3337

34-
download.get_and_extract(Component::Rustc)?;
35-
download.get_and_extract(Component::Std)?;
36-
download.get_and_extract(Component::Cargo)?;
37-
download.get_and_extract(Component::RustSrc)?;
38+
download.get_and_extract(Component::Rustc).await?;
39+
download.get_and_extract(Component::Std).await?;
40+
download.get_and_extract(Component::Cargo).await?;
41+
download.get_and_extract(Component::RustSrc).await?;
3842
if backends.contains(&CodegenBackend::Cranelift) {
39-
download.get_and_extract(Component::Cranelift)?;
43+
download.get_and_extract(Component::Cranelift).await?;
4044
}
4145

4246
let sysroot = download.into_sysroot()?;
@@ -141,7 +145,7 @@ impl SysrootDownload {
141145
})
142146
}
143147

144-
fn get_and_extract(&self, component: Component) -> anyhow::Result<()> {
148+
async fn get_and_extract(&self, component: Component) -> anyhow::Result<()> {
145149
let archive_path = self.directory.join(format!(
146150
"{}-{}-{}.tar.xz",
147151
self.rust_sha, self.triple, component,
@@ -168,10 +172,11 @@ impl SysrootDownload {
168172
];
169173
for url in &urls {
170174
log::debug!("requesting: {}", url);
171-
let resp = reqwest::blocking::get(url)?;
175+
let resp = reqwest::get(url).await?;
172176
log::debug!("{}", resp.status());
173177
if resp.status().is_success() {
174-
let reader = XzDecoder::new(BufReader::new(resp));
178+
let bytes: Vec<u8> = resp.bytes().await?.into();
179+
let reader = XzDecoder::new(BufReader::new(bytes.as_slice()));
175180
match self.extract(component, reader) {
176181
Ok(()) => return Ok(()),
177182
Err(err) => {

0 commit comments

Comments
 (0)