xtask: generate rust-analyzer shim

This commit is contained in:
Mark Poliakov 2024-08-10 20:41:32 +03:00
parent b131d2b52a
commit 99f4482533
2 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,2 @@
[toolchain]
channel = "ygg-stage1"

View File

@ -1,6 +1,9 @@
// use std::{collections::HashMap, path::Path};
use std::{collections::HashMap, path::Path, process::Command};
use std::{
collections::HashMap, fs::OpenOptions, os::unix::fs::OpenOptionsExt, path::Path,
process::Command,
};
use crate::{env::BuildEnv, error::Error, util};
@ -102,6 +105,38 @@ fn do_build<P: AsRef<Path>>(toolchain_root: P) -> Result<(), Error> {
}
}
fn install_shims<P: AsRef<Path>>(env: &BuildEnv, toolchain_root: P) -> Result<(), Error> {
use std::io::Write;
let toolchain_root = toolchain_root.as_ref();
let build_dir = toolchain_root.join("build").join(&env.host_triple);
let stage1_rustlib = build_dir
.join("stage1/lib/rustlib/")
.join(&env.host_triple)
.join("lib");
let stage1_tools_bin = build_dir.join("stage1-tools-bin");
let stage1_bin = build_dir.join("stage1/bin");
let rust_analyzer = stage1_bin.join("rust-analyzer");
let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.mode(0o755)
.open(rust_analyzer)?;
writeln!(file, "#!/bin/sh")?;
writeln!(
file,
"LD_LIBRARY_PATH={} {}/rust-analyzer",
stage1_rustlib.display(),
stage1_tools_bin.display()
)?;
Ok(())
}
pub fn fetch(env: &BuildEnv, branch: &str) -> Result<(), Error> {
let path = env.workspace_root.join("toolchain");
@ -137,6 +172,8 @@ pub fn build(env: &BuildEnv) -> Result<(), Error> {
log::info!("Building toolchain");
do_build(&toolchain_path)?;
log::info!("Installing rust tool shims");
install_shims(env, &toolchain_path)?;
if !is_toolchain_linked() {
log::info!("Linking the newly built toolchain to +ygg-stage1");