Skip to content

Commit

Permalink
xtask: use API to download gen_init_cpio
Browse files Browse the repository at this point in the history
The raw endpoint[0] seems to return HTTP 429 every time now.

Link: https://raw.githubusercontent.com/torvalds/linux/refs/heads/master/usr/gen_init_cpio.c [0]
  • Loading branch information
tamird committed Dec 12, 2024
1 parent 1dfcfbc commit 8e8b85d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ netns-rs = { version = "0.1", default-features = false }
nix = { version = "0.29.0", default-features = false }
num_enum = { version = "0.7", default-features = false }
object = { version = "0.36", default-features = false }
octorust = { version = "0.7.0", default-features = false }
once_cell = { version = "1.20.1", default-features = false }
proc-macro2 = { version = "1", default-features = false }
proc-macro2-diagnostics = { version = "0.10.1", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ clap = { workspace = true, features = ["derive"] }
dialoguer = { workspace = true }
diff = { workspace = true }
indoc = { workspace = true }
octorust = { workspace = true, features = ["rustls-tls"] }
proc-macro2 = { workspace = true }
public-api = { workspace = true }
quote = { workspace = true }
rustdoc-json = { workspace = true }
rustup-toolchain = { workspace = true }
syn = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["rt"] }
which = { workspace = true }
60 changes: 35 additions & 25 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use anyhow::{anyhow, bail, Context as _, Result};
use cargo_metadata::{Artifact, CompilerMessage, Message, Target};
use clap::Parser;
use xtask::{exec, Errors, AYA_BUILD_INTEGRATION_BPF};
use xtask::{Errors, AYA_BUILD_INTEGRATION_BPF};

#[derive(Parser)]
enum Environment {
Expand Down Expand Up @@ -192,37 +192,47 @@ pub fn run(opts: Options) -> Result<()> {
.try_exists()
.context("failed to check existence of gen_init_cpio")?
{
let mut curl = Command::new("curl");
curl.args([
"-sfSL",
"https://raw.githubusercontent.com/torvalds/linux/master/usr/gen_init_cpio.c",
]);
let mut curl_child = curl
let client =
octorust::Client::new(String::from("aya-xtask-integration-test-run"), None)?;
let octorust::Response {
status: _,
headers: _,
body: octorust::types::ContentFile { content, .. },
} = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap()
.block_on(client.repos().get_content_file(
"torvalds",
"linux",
"usr/gen_init_cpio.c",
"master",
))?;

let mut clang = Command::new("clang");
clang
.args(["-g", "-O2", "-x", "c", "-", "-o"])
.arg(&gen_init_cpio);
let mut child = clang
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.with_context(|| format!("failed to spawn {curl:?}"))?;
let Child { stdout, .. } = &mut curl_child;
let curl_stdout = stdout.take().unwrap();
.with_context(|| format!("failed to spawn {clang:?}"))?;

let mut clang = Command::new("clang");
let clang = exec(
clang
.args(["-g", "-O2", "-x", "c", "-", "-o"])
.arg(&gen_init_cpio)
.stdin(curl_stdout),
);

let output = curl_child
let Child { stdin, .. } = &mut child;
let mut stdin = stdin.take().unwrap();
stdin
.write_all(content.as_bytes())
.with_context(|| format!("failed to write to {clang:?} stdin"))?;
std::mem::drop(stdin); // Send EOF.

let output = child
.wait_with_output()
.with_context(|| format!("failed to wait for {curl:?}"))?;
.with_context(|| format!("failed to wait for {clang:?}"))?;
let Output { status, .. } = &output;
if status.code() != Some(0) {
bail!("{curl:?} failed: {output:?}")
bail!("{clang:?} failed: {output:?}")
}

// Check the result of clang *after* checking curl; in case the download failed,
// only curl's output will be useful.
clang?;
}

let mut errors = Vec::new();
Expand Down

0 comments on commit 8e8b85d

Please sign in to comment.