mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
xtask: use assets api for determining URL
Now that we have full JSON parsing inside xtask, actually parse the assets API endpoint to determine the correct URL. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
35857ab543
commit
e6209302e7
3 changed files with 68 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -3034,6 +3034,8 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustls",
|
"rustls",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"url",
|
"url",
|
||||||
"webpki",
|
"webpki",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ description = "Cargo-based build system for Xous"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Sean Cross <sean@xobs.io>"]
|
authors = ["Sean Cross <sean@xobs.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
rust-version = "1.59"
|
||||||
|
|
||||||
# Dependency policy: fully specify dependencies to the minor version number
|
# Dependency policy: fully specify dependencies to the minor version number
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -15,4 +16,4 @@ chrono = "0.4"
|
||||||
serde_json = "1.0.41"
|
serde_json = "1.0.41"
|
||||||
serde = { version = "1.0.130", features = ["derive"] }
|
serde = { version = "1.0.130", features = ["derive"] }
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
ureq = "2.4.0"
|
ureq = { version = "2.4.0", features = ["json"] }
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,7 @@ type DynError = Box<dyn std::error::Error>;
|
||||||
|
|
||||||
const PROGRAM_TARGET: &str = "riscv32imac-unknown-xous-elf";
|
const PROGRAM_TARGET: &str = "riscv32imac-unknown-xous-elf";
|
||||||
const KERNEL_TARGET: &str = "riscv32imac-unknown-xous-elf";
|
const KERNEL_TARGET: &str = "riscv32imac-unknown-xous-elf";
|
||||||
const TOOLCHAIN_URL_PREFIX: &str =
|
const TOOLCHAIN_RELEASE_URL: &str = "https://api.github.com/repos/betrusted-io/rust/releases";
|
||||||
"https://github.com/betrusted-io/rust/releases/latest/download/riscv32imac-unknown-xous_";
|
|
||||||
const TOOLCHAIN_URL_SUFFIX: &str = ".zip";
|
|
||||||
|
|
||||||
enum MemorySpec {
|
enum MemorySpec {
|
||||||
SvdFile(String),
|
SvdFile(String),
|
||||||
|
|
@ -1132,7 +1130,6 @@ fn ensure_compiler(
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let stdin = std::io::stdin();
|
let stdin = std::io::stdin();
|
||||||
let mut stdout = std::io::stdout();
|
let mut stdout = std::io::stdout();
|
||||||
println!();
|
|
||||||
if force_install {
|
if force_install {
|
||||||
println!("Downloading toolchain");
|
println!("Downloading toolchain");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1163,16 +1160,74 @@ fn ensure_compiler(
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
let toolchain_url = format!(
|
fn get_toolchain_url(major: u64, minor: u64, patch: u64) -> Result<String, String> {
|
||||||
"{}{}.{}.{}{}",
|
let j: serde_json::Value = ureq::get(TOOLCHAIN_RELEASE_URL)
|
||||||
TOOLCHAIN_URL_PREFIX, ver.major, ver.minor, ver.patch, TOOLCHAIN_URL_SUFFIX
|
.set("Accept", "application/vnd.github.v3+json")
|
||||||
);
|
.call()
|
||||||
|
.map_err(|e| format!("{}", e))?
|
||||||
|
.into_json()
|
||||||
|
.map_err(|e| format!("{}", e))?;
|
||||||
|
// let j: serde_json::Value = serde_json::from_str(CONTENT).expect("Cannot parse manifest file");
|
||||||
|
|
||||||
|
let releases = j.as_array().unwrap();
|
||||||
|
let mut tag_urls = std::collections::BTreeMap::new();
|
||||||
|
|
||||||
|
let target_prefix = format!("{}.{}.{}", major, minor, patch);
|
||||||
|
for r in releases {
|
||||||
|
// println!(">>> Value: {}", r);
|
||||||
|
|
||||||
|
let keys = match r.as_object() {
|
||||||
|
None => continue,
|
||||||
|
Some(r) => r,
|
||||||
|
};
|
||||||
|
let release = match keys.get("tag_name") {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => match s.as_str() {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => s,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if !release.starts_with(&target_prefix) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let assets = match keys.get("assets") {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => match s.as_array() {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => s,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let first_asset = match assets.get(0) {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => s,
|
||||||
|
};
|
||||||
|
|
||||||
|
let download_url = match first_asset.get("browser_download_url") {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => match s.as_str() {
|
||||||
|
None => continue,
|
||||||
|
Some(s) => s,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
// println!("Candidate Release: {}", download_url);
|
||||||
|
tag_urls.insert(release.to_owned(), download_url.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some((_k, v)) = tag_urls.into_iter().last() {
|
||||||
|
// println!("Found candidate entry: v{} url {}", k, v);
|
||||||
|
return Ok(v);
|
||||||
|
}
|
||||||
|
Err(format!("No toolchains found for Rust {}", target_prefix))
|
||||||
|
}
|
||||||
|
let toolchain_url = get_toolchain_url(ver.major, ver.minor, ver.patch)?;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Attempting to install toolchain for {} into {}",
|
"Attempting to install toolchain for {} into {}",
|
||||||
target, toolchain_path
|
target, toolchain_path
|
||||||
);
|
);
|
||||||
println!("Downloading from {}...", toolchain_url);
|
println!("Downloading toolchain from {}...", toolchain_url);
|
||||||
|
|
||||||
print!("Download in progress...");
|
print!("Download in progress...");
|
||||||
stdout.flush().unwrap();
|
stdout.flush().unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue