diff --git a/userspace/rust-toolchain.toml b/userspace/rust-toolchain.toml new file mode 100644 index 00000000..90ff040f --- /dev/null +++ b/userspace/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "ygg-stage1" diff --git a/xtask/src/build/toolchain.rs b/xtask/src/build/toolchain.rs index 3df079f7..1f4ad7d9 100644 --- a/xtask/src/build/toolchain.rs +++ b/xtask/src/build/toolchain.rs @@ -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>(toolchain_root: P) -> Result<(), Error> { } } +fn install_shims>(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");