diff --git a/CHANGELOG.md b/CHANGELOG.md index 04273ec..f568a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.10.3 + +#### 🚀 Updates + +- Updated `RUSTUP_HOME` to support relative paths. + ## 0.10.2 #### 🚀 Updates diff --git a/Cargo.lock b/Cargo.lock index ba42c2a..025cbd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2384,7 +2384,7 @@ dependencies = [ [[package]] name = "rust_plugin" -version = "0.10.2" +version = "0.10.3" dependencies = [ "extism-pdk", "proto_pdk", diff --git a/Cargo.toml b/Cargo.toml index 313ac6d..dc9d7cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_plugin" -version = "0.10.2" +version = "0.10.3" edition = "2021" license = "MIT" publish = false diff --git a/src/helpers.rs b/src/helpers.rs index a522048..cd9a71d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,24 +1,34 @@ +use std::path::PathBuf; + use extism_pdk::*; use proto_pdk::*; -use std::path::PathBuf; #[host_fn] extern "ExtismHost" { fn get_env_var(name: String) -> String; + fn to_virtual_path(input: String) -> String; } -pub fn get_rustup_home(env: &HostEnvironment) -> Result { +pub fn get_rustup_home(env: &HostEnvironment) -> Result { // Cargo sets the RUSTUP_HOME env var when running tests, // which causes a ton of issues, so intercept it here! if let Some(test_env) = get_test_environment()? { - return Ok(test_env.sandbox.join(".home/.rustup")); + return Ok(virtual_path!(buf, test_env.sandbox).join(".home/.rustup")); } - // Variable returns a real path - Ok(host_env!("RUSTUP_HOME") - .map(PathBuf::from) - // So we need our fallback to also be a real path - .unwrap_or_else(|| env.home_dir.real_path().unwrap().join(".rustup"))) + Ok(match host_env!("RUSTUP_HOME") { + Some(path) => { + let path = PathBuf::from(path); + + // Variable returns a real path, so convert to virtual + if path.is_absolute() { + virtual_path!(buf, path) + } else { + virtual_path!("/cwd").join(path) + } + } + None => env.home_dir.join(".rustup"), + }) } pub fn get_channel_from_version(spec: &VersionSpec) -> String { diff --git a/src/proto.rs b/src/proto.rs index a402506..08e5610 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -9,13 +9,12 @@ use std::path::PathBuf; extern "ExtismHost" { fn exec_command(input: Json) -> Json; fn set_env_var(name: String, value: String); - fn to_virtual_path(input: String) -> String; } static NAME: &str = "Rust"; fn get_toolchain_dir(env: &HostEnvironment) -> AnyResult { - Ok(virtual_path!(buf, get_rustup_home(env)?.join("toolchains"))) + Ok(get_rustup_home(env)?.join("toolchains")) } #[plugin_fn]