arm_toolchain/
lib.rs

1//! # ARM Toolchain Manager
2//!
3//! This is the support library for the ARM Toolchain Manager CLI. It provides a client
4//! for downloading, installing, using, and deleting versions of the open-source
5//! ARM Toolchain for Embedded. This library's author is not affiliated with ARM.
6//!
7//! ## Toolchain module
8//!
9//! Use the [`toolchain`] module to access and modify ARM toolchains. Most operations
10//! in this module require you to create a [`ToolchainClient`](toolchain::ToolchainClient).
11//! From there, you can do things like getting a list of installed toolchains, getting their
12//! `bin` paths, downloading a new toolchain, etc.
13//!
14//! ## CLI module
15//!
16//! (Cargo feature: `cli` [default])
17//!
18//! The [`cli`] module is for integrating this library into another CLI tool. It provides
19//! specialized wrappers for the operations in the `toolchain` module that work well with
20//! applications using [`clap`]. The functions in this module will print to stdio and read
21//! user input.
22//!
23//! ## CLI Binaries
24//!
25//! (Cargo feature: `bin`)
26//!
27//! This library has two associated CLI tools, `arm-toolchain` and `atrun`. They have their
28//! own dependencies, so to compile them you will need to enable a Cargo feature.
29//!
30//! ```sh
31//! cargo install arm-toolchain -Fbin
32//! ```
33
34use std::sync::LazyLock;
35
36use directories::ProjectDirs;
37
38pub(crate) use fs_err::tokio as fs;
39use tokio_util::sync::CancellationToken;
40use trash::TrashContext;
41
42pub mod cli;
43pub mod toolchain;
44
45pub static DIRS: LazyLock<ProjectDirs> = LazyLock::new(|| {
46    ProjectDirs::from("dev", "vexide", "arm-toolchain").expect("home directory must be available")
47});
48
49pub static TRASH: LazyLock<TrashContext> = LazyLock::new(|| {
50    #[allow(unused_mut)]
51    let mut ctx = TrashContext::new();
52
53    // Opt in to faster deletion method
54    #[cfg(target_os = "macos")]
55    trash::macos::TrashContextExtMacos::set_delete_method(
56        &mut ctx,
57        trash::macos::DeleteMethod::NsFileManager,
58    );
59
60    ctx
61});
62
63trait CheckCancellation {
64    fn check_cancellation<E>(&self, error: E) -> Result<(), E>;
65}
66
67impl CheckCancellation for CancellationToken {
68    fn check_cancellation<E>(&self, error: E) -> Result<(), E> {
69        if self.is_cancelled() {
70            Err(error)
71        } else {
72            Ok(())
73        }
74    }
75}