toolkit for mdBook [mirror of my GitHub repo] docs.tonywu.dev/mdbookkit/
permalinks rust-analyzer mdbook
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ci: merge util-rust-analyzer into xtask

Tony Wu bbc58758 6c070bee

+136 -140
+2 -2
.github/workflows/ci.yml
··· 86 86 - name: Prepare binaries 87 87 run: | 88 88 cargo bin --install 89 - cargo run --package util-rust-analyzer -- download 89 + cargo xtask rust-analyzer download 90 90 91 91 - name: Build tests 92 92 run: cargo test --no-run ··· 141 141 .bin/ 142 142 target/ 143 143 144 - - run: cargo run --package util-rust-analyzer -- download 144 + - run: cargo xtask rust-analyzer download 145 145 env: 146 146 RA_VERSION: ${{ matrix.ra-version }} 147 147
+1 -1
.github/workflows/docs.yml
··· 77 77 78 78 - run: pnpm install 79 79 - run: cargo bin --install 80 - - run: cargo run --package util-rust-analyzer -- download 80 + - run: cargo xtask rust-analyzer download 81 81 82 82 - run: cargo bin mdbook build 83 83 working-directory: docs
+9 -17
Cargo.lock
··· 224 224 225 225 [[package]] 226 226 name = "cargo-xtask" 227 - version = "0.1.0" 227 + version = "0.0.0" 228 228 dependencies = [ 229 229 "anyhow", 230 + "cargo-run-bin", 230 231 "clap", 232 + "flate2", 233 + "indicatif", 234 + "reqwest", 235 + "serde_json", 236 + "tap", 237 + "tempfile", 238 + "zip", 231 239 ] 232 240 233 241 [[package]] ··· 2777 2785 version = "0.2.2" 2778 2786 source = "registry+https://github.com/rust-lang/crates.io-index" 2779 2787 checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 2780 - 2781 - [[package]] 2782 - name = "util-rust-analyzer" 2783 - version = "0.0.0" 2784 - dependencies = [ 2785 - "anyhow", 2786 - "cargo-run-bin", 2787 - "clap", 2788 - "flate2", 2789 - "indicatif", 2790 - "reqwest", 2791 - "serde_json", 2792 - "tap", 2793 - "tempfile", 2794 - "zip", 2795 - ] 2796 2788 2797 2789 [[package]] 2798 2790 name = "valuable"
+1 -1
crates/mdbook-rustdoc-links/src/tests.rs
··· 33 33 .init(); 34 34 35 35 let client = Config { 36 - rust_analyzer: Some("cargo run --package util-rust-analyzer -- analyzer".into()), 36 + rust_analyzer: Some("cargo xtask rust-analyzer analyzer".into()), 37 37 ..Default::default() 38 38 } 39 39 .pipe(Environment::new)
+1 -1
crates/mdbook-rustdoc-links/tests/env.rs
··· 153 153 .join("server/rust-analyzer"); 154 154 155 155 Command::new("cargo") 156 - .args(["run", "--package", "util-rust-analyzer", "--"]) 156 + .args(["xtask", "rust-analyzer"]) 157 157 .arg("--ra-path") 158 158 .arg(ra_executable) 159 159 .arg("download")
+2 -2
docs/bin/preprocess.rs
··· 100 100 Replace::RustAnalyzerVersion { span } => { 101 101 static RA_VERSION: LazyLock<String> = LazyLock::new(|| { 102 102 std::process::Command::new(env!("CARGO")) 103 - .args(["run", "--package", "util-rust-analyzer", "--", "version"]) 103 + .args(["xtask", "rust-analyzer", "version"]) 104 104 .stdout(Stdio::piped()) 105 105 .output() 106 - .context("failed to run util-rust-analyzer") 106 + .context("failed to run xtask rust-analyzer") 107 107 .exit(emit_error!()) 108 108 .stdout 109 109 .pipe(String::from_utf8)
+1 -1
docs/book.toml
··· 34 34 cache-dir = "build" 35 35 command = "cargo run --package mdbook-rustdoc-links --all-features" 36 36 manifest-dir = "." 37 - rust-analyzer = "cargo run --package util-rust-analyzer -- analyzer" 37 + rust-analyzer = "cargo xtask rust-analyzer analyzer" 38 38 39 39 [preprocessor.permalinks] 40 40 after = ["rustdoc-links"]
+12 -2
utils/cargo-xtask/Cargo.toml
··· 1 1 [package] 2 2 name = "cargo-xtask" 3 - version = "0.1.0" 3 + version = "0.0.0" 4 4 5 5 authors.workspace = true 6 6 edition.workspace = true ··· 10 10 rust-version.workspace = true 11 11 12 12 [dependencies] 13 - anyhow.workspace = true 13 + anyhow = { workspace = true } 14 + cargo-run-bin = { workspace = true } 14 15 clap = { workspace = true } 16 + flate2 = "1.1.5" 17 + indicatif = { workspace = true } 18 + reqwest = { version = "0.12.28", features = ["blocking"] } 19 + serde_json = { workspace = true } 20 + tap = { workspace = true } 21 + tempfile = { workspace = true } 22 + zip = { version = "7.0.0", features = [ 23 + "deflate", # https://github.com/rust-lang/rust-analyzer/blob/2025-03-17/xtask/src/dist.rs#L134 24 + ], default-features = false }
+33
utils/cargo-xtask/src/github.rs
··· 1 + use std::{env, fs, io::Write}; 2 + 3 + use anyhow::{Context, Result}; 4 + 5 + #[derive(clap::Parser, Debug)] 6 + pub enum Command { 7 + WhichPackage { tag_name: Option<String> }, 8 + } 9 + 10 + impl Command { 11 + pub fn run(self) -> Result<()> { 12 + let output = env::var("GITHUB_OUTPUT").context("missing $GITHUB_OUTPUT")?; 13 + let mut output = fs::OpenOptions::new() 14 + .create(true) 15 + .append(true) 16 + .open(output) 17 + .context("failed to open $GITHUB_OUTPUT")?; 18 + 19 + match self { 20 + Self::WhichPackage { tag_name } => { 21 + for package in ["mdbook-rustdoc-links", "mdbook-permalinks"] { 22 + if (tag_name.as_ref()).is_some_and(|tag| tag.starts_with(package)) 23 + || tag_name.is_none() 24 + { 25 + writeln!(&mut output, "{package}=true")?; 26 + } 27 + } 28 + } 29 + } 30 + 31 + Ok(()) 32 + } 33 + }
+12 -22
utils/cargo-xtask/src/main.rs
··· 1 - use std::{env, fs, io::Write}; 1 + use anyhow::Result; 2 2 3 - use anyhow::{Context, Result}; 3 + mod github; 4 + mod rust_analyzer; 4 5 5 6 fn main() -> Result<()> { 6 - let output = env::var("GITHUB_OUTPUT").context("missing $GITHUB_OUTPUT")?; 7 - let mut output = fs::OpenOptions::new() 8 - .create(true) 9 - .append(true) 10 - .open(output) 11 - .context("failed to open $GITHUB_OUTPUT")?; 12 - 13 7 match clap::Parser::parse() { 14 - Command::WhichPackage { tag_name } => { 15 - for package in ["mdbook-rustdoc-links", "mdbook-permalinks"] { 16 - if (tag_name.as_ref()).is_some_and(|tag| tag.starts_with(package)) 17 - || tag_name.is_none() 18 - { 19 - writeln!(&mut output, "{package}=true")?; 20 - } 21 - } 22 - } 8 + Program::GitHub { command } => command.run(), 9 + Program::RustAnalyzer(command) => command.run(), 23 10 } 24 - 25 - Ok(()) 26 11 } 27 12 28 13 #[derive(clap::Parser, Debug)] 29 - enum Command { 30 - WhichPackage { tag_name: Option<String> }, 14 + enum Program { 15 + #[clap(name = "github")] 16 + GitHub { 17 + #[clap(subcommand)] 18 + command: github::Command, 19 + }, 20 + RustAnalyzer(rust_analyzer::Program), 31 21 }
-23
utils/rust-analyzer/Cargo.toml
··· 1 - [package] 2 - name = "util-rust-analyzer" 3 - version = "0.0.0" 4 - 5 - authors.workspace = true 6 - edition.workspace = true 7 - license.workspace = true 8 - publish.workspace = true 9 - repository.workspace = true 10 - 11 - [dependencies] 12 - anyhow = { workspace = true } 13 - cargo-run-bin = { workspace = true } 14 - clap = { workspace = true } 15 - flate2 = "1.1.5" 16 - indicatif = { workspace = true } 17 - reqwest = { version = "0.12.28", features = ["blocking"] } 18 - serde_json = { workspace = true } 19 - tap = { workspace = true } 20 - tempfile = { workspace = true } 21 - zip = { version = "7.0.0", features = [ 22 - "deflate", # https://github.com/rust-lang/rust-analyzer/blob/2025-03-17/xtask/src/dist.rs#L134 23 - ], default-features = false }
utils/rust-analyzer/build.rs utils/cargo-xtask/build.rs
+62 -68
utils/rust-analyzer/src/main.rs utils/cargo-xtask/src/rust_analyzer.rs
··· 10 10 11 11 use anyhow::Result; 12 12 use cargo_run_bin::metadata::get_project_root; 13 - use clap::Parser; 14 13 use flate2::write::GzDecoder; 15 14 use indicatif::{ProgressBar, ProgressStyle}; 16 15 use tap::{Pipe, Tap}; 17 16 use tempfile::tempfile; 17 + 18 + #[derive(clap::Parser, Debug)] 19 + pub struct Program { 20 + #[arg(long)] 21 + ra_version: Option<String>, 22 + #[arg(long)] 23 + ra_path: Option<PathBuf>, 24 + #[clap(subcommand)] 25 + command: Command, 26 + } 27 + 28 + #[derive(clap::Subcommand, Debug)] 29 + enum Command { 30 + Download, 31 + Analyzer { 32 + #[arg(trailing_var_arg = true, allow_hyphen_values = true, hide = true)] 33 + args: Vec<String>, 34 + }, 35 + Version, 36 + } 37 + 38 + impl Program { 39 + pub fn run(self) -> Result<()> { 40 + let release = std::env::var("RA_VERSION") 41 + .ok() 42 + .unwrap_or("2025-12-01".into()); 43 + 44 + let path = match self.ra_path { 45 + Some(path) => path, 46 + None => get_project_root()? 47 + .join(".bin/rust-analyzer") 48 + .join(&release) 49 + .join("rust-analyzer"), 50 + }; 51 + 52 + let download = Download { release, path }; 53 + 54 + match self.command { 55 + Command::Download => download.download(), 56 + Command::Analyzer { args } => analyzer(&download, args), 57 + Command::Version => { 58 + print!("{}", download.release); 59 + Ok(()) 60 + } 61 + } 62 + } 63 + } 64 + 65 + fn analyzer(download: &Download, args: Vec<String>) -> Result<()> { 66 + if !download.path.exists() { 67 + download.download()?; 68 + } 69 + process::Command::new(&download.path) 70 + .args(args) 71 + .stdin(Stdio::inherit()) 72 + .stdout(Stdio::inherit()) 73 + .stderr(Stdio::inherit()) 74 + .status()? 75 + .code() 76 + .unwrap_or_default() 77 + .pipe(std::process::exit); 78 + } 18 79 19 80 #[derive(Debug)] 20 81 struct Download { ··· 115 176 ) 116 177 .tap(|b| b.enable_steady_tick(Duration::from_millis(100))) 117 178 } 118 - } 119 - 120 - #[derive(clap::Parser, Debug)] 121 - struct Program { 122 - #[arg(long)] 123 - ra_version: Option<String>, 124 - #[arg(long)] 125 - ra_path: Option<PathBuf>, 126 - #[clap(subcommand)] 127 - command: Command, 128 - } 129 - 130 - #[derive(clap::Subcommand, Debug)] 131 - enum Command { 132 - Download, 133 - Analyzer { 134 - #[arg(trailing_var_arg = true, allow_hyphen_values = true, hide = true)] 135 - args: Vec<String>, 136 - }, 137 - Version, 138 - } 139 - 140 - #[derive(clap::Subcommand, Debug)] 141 - enum Version { 142 - Supports { renderer: String }, 143 - } 144 - 145 - fn main() -> Result<()> { 146 - let program = Program::parse(); 147 - 148 - let release = std::env::var("RA_VERSION") 149 - .ok() 150 - .unwrap_or("2025-12-01".into()); 151 - 152 - let path = match program.ra_path { 153 - Some(path) => path, 154 - None => get_project_root()? 155 - .join(".bin/rust-analyzer") 156 - .join(&release) 157 - .join("rust-analyzer"), 158 - }; 159 - 160 - let download = Download { release, path }; 161 - 162 - match program.command { 163 - Command::Download => download.download(), 164 - Command::Analyzer { args } => analyzer(&download, args), 165 - Command::Version => { 166 - print!("{}", download.release); 167 - Ok(()) 168 - } 169 - } 170 - } 171 - 172 - fn analyzer(download: &Download, args: Vec<String>) -> Result<()> { 173 - if !download.path.exists() { 174 - download.download()?; 175 - } 176 - process::Command::new(&download.path) 177 - .args(args) 178 - .stdin(Stdio::inherit()) 179 - .stdout(Stdio::inherit()) 180 - .stderr(Stdio::inherit()) 181 - .status()? 182 - .code() 183 - .unwrap_or_default() 184 - .pipe(std::process::exit); 185 179 } 186 180 187 181 struct Progress<W>(W, ProgressBar);