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

Commit

Permalink
Update home detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 1, 2024
1 parent 0313263 commit 8ea25bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
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

0 comments on commit 8ea25bb

Please sign in to comment.