#toolchain #manifest #parses #package #name #renames

rustup-toolchain-manifest

解析 Rust 工具链清单

3 个版本

0.2.2 2023年1月28日
0.2.1 2023年1月22日
0.2.0 2023年1月15日

#10 in #parses

每月 24 次下载
用于 ferrous-actions

BSD-3-Clause 协议

36KB
710

Rust 工具链清单

这是一个库,可以解析 v2 Rust 工具链清单并对其进行一些基本查询。它绝对不是官方的,Rust 工具链清单有能力在任何时候随意更改。它之所以被编写,仅仅是因为我找不到现有的库能做这个。

Rust 工具链清单格式显然随着时间的推移而扩展,其中一些方面,特别是处理缺失的包和重命名的方式,相当令人困惑。这个库是尽最大努力尝试逆向工程其底层含义。

这个包被命名为 rustup-toolchain-manifest 只是因为 rust-toolchain-manifest 好像已经被抢注了。

示例用法(来自 examples/readme.rs

fn main() {
    let toolchain = Toolchain::from_str("nightly-x86_64-unknown-linux-gnu")
        .expect("Failed to parse toolchain");
    println!("Toolchain specification:\n{:#?}\n", toolchain);

    let manifest_url = toolchain.manifest_url();
    println!("Downloading manifest from: {}", manifest_url);
    let manifest = reqwest::blocking::get(&manifest_url)
        .expect("Failed to fetch manifest")
        .text()
        .expect("Could not get response text");
    println!(
        "Successfully retrieved manifest of {} bytes.",
        manifest.len()
    );

    let manifest =
        Manifest::try_from(manifest.as_str()).expect("Failed to parse manifest");
    let install_spec = InstallSpec {
        profile: "default".into(),
        components: HashSet::new(),
        targets: ["wasm32-unknown-unknown"]
            .into_iter()
            .map(String::from)
            .collect(),
    };

    let target = toolchain
        .host
        .expect("Host missing for previously specified toolchain");
    println!(
        "Finding packages on {} for install specification:\n{:#?}\n",
        target, install_spec
    );
    let packages = manifest
        .find_packages_for_install(&target, &install_spec)
        .expect("Failed to find packages");
    println!("The following packages are required:");
    for (name, target) in packages {
        println!("{} ({})", name, target);
    }
}

输出

Toolchain specification:
Toolchain {
    channel: Nightly,
    date: None,
    host: Some(
        Triple {
            architecture: X86_64,
            vendor: Unknown,
            operating_system: Linux,
            environment: Gnu,
            binary_format: Elf,
        },
    ),
}

Downloading manifest from: https://static.rust-lang.org/dist/channel-rust-nightly.toml
Successfully retrieved manifest of 769388 bytes.
Finding packages on x86_64-unknown-linux-gnu for install specification:
InstallSpec {
    profile: "default",
    components: {},
    targets: {
        "wasm32-unknown-unknown",
    },
}

The following packages are required:
rustc (x86_64-unknown-linux-gnu)
clippy-preview (x86_64-unknown-linux-gnu)
rust-std (wasm32-unknown-unknown)
rust-std (x86_64-unknown-linux-gnu)
rustfmt-preview (x86_64-unknown-linux-gnu)
rust-docs (x86_64-unknown-linux-gnu)
cargo (x86_64-unknown-linux-gnu)

依赖

~1.6–2.4MB
~47K SLoC