Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

fix: Support relative paths in RUSTUP_HOME. #28

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.10.3

#### 🚀 Updates

- Updated `RUSTUP_HOME` to support relative paths.

## 0.10.2

#### 🚀 Updates
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust_plugin"
version = "0.10.2"
version = "0.10.3"
edition = "2021"
license = "MIT"
publish = false
Expand Down
26 changes: 18 additions & 8 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf, Error> {
pub fn get_rustup_home(env: &HostEnvironment) -> Result<VirtualPath, Error> {
// 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 {
Expand Down
3 changes: 1 addition & 2 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use std::path::PathBuf;
extern "ExtismHost" {
fn exec_command(input: Json<ExecCommandInput>) -> Json<ExecCommandOutput>;
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<VirtualPath> {
Ok(virtual_path!(buf, get_rustup_home(env)?.join("toolchains")))
Ok(get_rustup_home(env)?.join("toolchains"))
}

#[plugin_fn]
Expand Down