Skip to content

Commit

Permalink
fix: Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Oct 22, 2023
1 parent 52086db commit 8663d28
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn set_env(toolchain_dir: &Path) -> Result<(), Error> {
#[cfg(windows)]
if cfg!(windows) {
windows::write_env_files(toolchain_dir)?;
windows::update_env(toolchain_dir)?;
windows::update_env()?;
}
#[cfg(unix)]
if cfg!(unix) {
Expand Down
2 changes: 2 additions & 0 deletions src/env/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,12 @@ impl UnixShell for Fish {
}
}

#[cfg(unix)]
pub(crate) fn find_cmd<'a>(cmds: &[&'a str]) -> Option<&'a str> {
cmds.iter().cloned().find(|&s| has_cmd(s))
}

#[cfg(unix)]
fn has_cmd(cmd: &str) -> bool {
let cmd = format!("{}{}", cmd, env::consts::EXE_SUFFIX);
let path = env::var("PATH").unwrap_or_default();
Expand Down
29 changes: 16 additions & 13 deletions src/env/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use winreg::{
const LEGACY_EXPORT_FILE: &str = "export-esp.ps1";

// Clean the environment for Windows.
pub(super) fn clean_env(toolchain_dir: &Path) -> Result<(), Error> {
pub(super) fn clean_env(_install_dir: &Path) -> Result<(), Error> {
delete_env_variable("LIBCLANG_PATH")?;
delete_env_variable("CLANG_PATH")?;
if let Some(path) = env::var_os("PATH") {
Expand Down Expand Up @@ -56,28 +56,31 @@ fn remove_legacy_export_file() -> Result<(), Error> {
}

// Update the environment for Windows.
pub(super) fn update_env(toolchain_dir: &Path) -> Result<(), Error> {
pub(super) fn update_env() -> Result<(), Error> {
let mut path = env::var("PATH").unwrap_or_default();

if let Some(xtensa_gcc) = env::var_os("XTENSA_GCC") {
if !path.contains(xtensa_gcc.into()) {
path = format!("{};{}", xtensa_gcc.into(), path);
if let Ok(xtensa_gcc) = env::var("XTENSA_GCC") {
let xtensa_gcc: &str = &xtensa_gcc;
if !path.contains(xtensa_gcc) {
path = format!("{};{}", xtensa_gcc, path);
}
}

if let Some(riscv_gcc) = env::var_os("RISCV_GCC") {
if !path.contains(riscv_gcc.into()) {
path = format!("{};{}", riscv_gcc.into(), path);
if let Ok(riscv_gcc) = env::var("RISCV_GCC") {
let riscv_gcc: &str = &riscv_gcc;
if !path.contains(riscv_gcc) {
path = format!("{};{}", riscv_gcc, path);
}
}

if let Some(libclang_path) = env::var_os("LIBCLANG_PATH") {
set_env_variable("LIBCLANG_PATH", &libclang_path.to_string_lossy())?;
if let Ok(libclang_path) = env::var("LIBCLANG_PATH") {
set_env_variable("LIBCLANG_PATH", &libclang_path)?;
}

if let Some(clang_path) = env::var_os("CLANG_PATH") {
if !path.contains(clang_path.into()) {
path = format!("{};{}", clang_path.into(), path);
if let Ok(clang_path) = env::var("CLANG_PATH") {
let clang_path: &str = &clang_path;
if !path.contains(clang_path) {
path = format!("{};{}", clang_path, path);
}
}
set_env_variable("PATH", &path)?;
Expand Down
28 changes: 11 additions & 17 deletions src/toolchain/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ pub struct Gcc {
impl Gcc {
/// Gets the binary path.
fn get_bin_path(&self) -> String {
format!("{}/{}/bin", &self.path.to_str().unwrap(), &self.arch)
#[cfg(windows)]
let bin_path =
format!("{}/{}/bin", &self.path.to_str().unwrap(), &self.arch).replace('/', "\\");
#[cfg(unix)]
let bin_path = format!("{}/{}/bin", &self.path.to_str().unwrap(), &self.arch);
bin_path
}

/// Create a new instance with default values and proper toolchain name.
Expand Down Expand Up @@ -81,23 +86,12 @@ impl Installable for Gcc {
.await?;
}

#[cfg(windows)]
if cfg!(windows) {
let windows_path = self.get_bin_path().replace('/', "\\");
if self.arch == RISCV_GCC {
env::set_var("RISCV_GCC", self.get_bin_path());
} else {
env::set_var("XTENSA_GCC", self.get_bin_path());
}
}
#[cfg(unix)]
if cfg!(unix) {
if self.arch == RISCV_GCC {
env::set_var("RISCV_GCC", self.get_bin_path());
} else {
env::set_var("XTENSA_GCC", self.get_bin_path());
}
if self.arch == RISCV_GCC {
env::set_var("RISCV_GCC", self.get_bin_path());
} else {
env::set_var("XTENSA_GCC", self.get_bin_path());
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/toolchain/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ mod tests {
logging::initialize_logger,
toolchain::rust::{get_cargo_home, get_rustup_home, XtensaRust},
};
use std::env;

#[test]
fn test_xtensa_rust_parse_version() {
Expand Down

0 comments on commit 8663d28

Please sign in to comment.