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

Commit

Permalink
fix: Respect CARGO_HOME during rustup install. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Jul 1, 2024
1 parent 2592594 commit edd9a02
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
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.4

#### 🐞 Fixes

- Updated our "automatic rustup installation" to respect the `CARGO_HOME` environment variable.

## 0.10.3

#### 🚀 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.3"
version = "0.10.4"
edition = "2021"
license = "MIT"
publish = false
Expand Down
40 changes: 27 additions & 13 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,40 @@ extern "ExtismHost" {
fn to_virtual_path(input: String) -> String;
}

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(virtual_path!(buf, test_env.sandbox).join(".home/.rustup"));
}
fn get_home_env(key: &str) -> Result<Option<VirtualPath>, Error> {
match host_env!(key) {
Some(value) => {
if value.is_empty() {
return Ok(None);
}

Ok(match host_env!("RUSTUP_HOME") {
Some(path) => {
let path = PathBuf::from(path);
let path = PathBuf::from(value);

// Variable returns a real path, so convert to virtual
if path.is_absolute() {
let path = if path.is_absolute() {
virtual_path!(buf, path)
} else {
virtual_path!("/cwd").join(path)
}
};

Ok(Some(path))
}
None => env.home_dir.join(".rustup"),
})
None => Ok(None),
}
}

pub fn get_cargo_home(env: &HostEnvironment) -> Result<VirtualPath, Error> {
Ok(get_home_env("CARGO_HOME")?.unwrap_or_else(|| env.home_dir.join(".cargo")))
}

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(virtual_path!(buf, test_env.sandbox).join(".home/.rustup"));
}

Ok(get_home_env("RUSTUP_HOME")?.unwrap_or_else(|| env.home_dir.join(".rustup")))
}

pub fn get_channel_from_version(spec: &VersionSpec) -> String {
Expand Down
9 changes: 6 additions & 3 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pub fn load_versions(Json(_): Json<LoadVersionsInput>) -> FnResult<Json<LoadVers
let tags = load_git_tags("https://github.com/rust-lang/rust")?;

let tags = tags
.iter()
.into_iter()
.filter_map(|tag| {
// Filter out old versions
if tag.starts_with("release-") || tag.starts_with("0.") {
None
} else {
Some(tag.to_owned())
Some(tag)
}
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -144,7 +144,10 @@ pub fn native_install(

// Update PATH explicitly, since we can't "reload the shell"
// on the host side. This is good enough since it's deterministic.
host_env!("PATH", "/userhome/.cargo/bin");
host_env!(
"PATH",
format!("{}:$HOME/.cargo/bin", get_cargo_home(&env)?.join("bin"))
);
}

let version = &input.context.version;
Expand Down

0 comments on commit edd9a02

Please sign in to comment.