Skip to content
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
18 changes: 16 additions & 2 deletions src/rustup/env_var.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
use std::ffi::OsString;
use std::env;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::Command;

pub fn set_path(name: &str, value: &Path, cmd: &mut Command) {
pub fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
let old_value = env::var_os(name);
let mut parts: Vec<PathBuf>;
if let Some(ref v) = old_value {
parts = env::split_paths(v).collect();
parts.extend(value);
} else {
parts = value;
}
if let Ok(new_value) = env::join_paths(parts) {
cmd.env(name, new_value);
}
}

pub fn prepend_path(name: &str, value: &Path, cmd: &mut Command) {
let old_value = env::var_os(name);
let mut parts = vec![value.to_owned()];
if let Some(ref v) = old_value {
Expand Down
12 changes: 10 additions & 2 deletions src/rustup/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,16 @@ impl<'a> Toolchain<'a> {
pub fn set_ldpath(&self, cmd: &mut Command) {
let new_path = self.path.join("lib");

env_var::set_path("LD_LIBRARY_PATH", &new_path, cmd);
env_var::set_path("DYLD_LIBRARY_PATH", &new_path, cmd);
env_var::prepend_path("LD_LIBRARY_PATH", &new_path, cmd);
env_var::prepend_path("DYLD_LIBRARY_PATH", &new_path, cmd);

// Append first cargo_home, then toolchain/bin to the PATH
let mut path_to_append = Vec::with_capacity(2);
if let Ok(cargo_home) = utils::cargo_home() {
path_to_append.push(cargo_home.join("bin"));
}
path_to_append.push(self.path.join("bin"));
env_var::append_path("PATH", path_to_append, cmd);
}

pub fn doc_path(&self, relative: &str) -> Result<PathBuf> {
Expand Down