Skip to content

Commit c73b226

Browse files
committed
oof
1 parent 5cf5bdf commit c73b226

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

Cargo.lock

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ thiserror = "1.0"
99
tempfile = "3.10"
1010
tracing = "0.1"
1111
tracing-subscriber = "0.3.19"
12+
indexmap = "2.9.0"
1213

1314
[dev-dependencies]

src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::io::Write as _;
44
use std::path::PathBuf;
55
use std::process::{Command, Stdio};
66
use std::sync::{Mutex, OnceLock};
7+
use indexmap::IndexMap;
78
use thiserror::Error;
89

910
const VSWHERE_URL: &str =
@@ -102,7 +103,7 @@ pub enum MsvcEnvError {
102103
#[derive(Debug, Clone)]
103104
pub struct MsvcEnvironment {
104105
/// All environment variables from vcvars
105-
pub vars: HashMap<String, String>,
106+
pub vars: IndexMap<String, String>,
106107
}
107108

108109
pub struct MsvcEnv;
@@ -253,7 +254,7 @@ impl MsvcEnv {
253254
}
254255

255256
/// Gets the environment variables after running vcvars
256-
fn vcvars_environment(&self, arch: MsvcArch) -> Result<HashMap<String, String>, MsvcEnvError> {
257+
fn vcvars_environment(&self, arch: MsvcArch) -> Result<IndexMap<String, String>, MsvcEnvError> {
257258
let vsdevcmd_path = self.vsdevcmd_path()?;
258259
let mut child = Command::new("cmd")
259260
.stdin(Stdio::piped())
@@ -292,7 +293,7 @@ impl MsvcEnv {
292293
Some((key, value)) => Some((key.to_string(), value.to_string())),
293294
None => None,
294295
})
295-
.collect::<HashMap<String, String>>();
296+
.collect::<IndexMap<String, String>>();
296297

297298
Ok(output)
298299
}

src/main.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
use msvc_env::MsvcEnv;
2-
use std::env;
2+
use std::{
3+
env,
4+
path::{Path, Prefix},
5+
};
6+
7+
fn unixify_path(path: &Path) -> String {
8+
let p = path.components()
9+
.filter_map(|c| Some(match c {
10+
std::path::Component::Prefix(prefix_component) => match prefix_component.kind() {
11+
Prefix::Disk(os_str) => format!("/{}", os_str as char).to_lowercase(),
12+
_ => format!("{}", prefix_component.as_os_str().to_str().unwrap()),
13+
},
14+
std::path::Component::RootDir => return None,
15+
std::path::Component::CurDir => ".".to_string(),
16+
std::path::Component::ParentDir => "..".to_string(),
17+
std::path::Component::Normal(os_str) => os_str.to_str().unwrap().replace(" ", "\\ "),
18+
}))
19+
.collect::<Vec<_>>();
20+
// eprintln!("P: {:?}", p);
21+
p.join("/")
22+
}
23+
24+
fn unixify_path_env(path: &str) -> String {
25+
path.split(";")
26+
.map(|p| Path::new(p))
27+
.map(unixify_path)
28+
.collect::<Vec<_>>()
29+
.join(":")
30+
}
331

432
fn main() {
533
tracing_subscriber::fmt::init();
@@ -51,7 +79,13 @@ fn main() {
5179
format!("{:?}", value).replace(r"\\", r"\")
5280
);
5381
} else if !(key.contains("(") || key.contains(")")) {
54-
println!("export {:?}={:?}", key, value);
82+
if key.to_uppercase() == "PATH" {
83+
println!("export MSVC_PATH={:?}", unixify_path_env(&value));
84+
println!("export OLD_PATH=\"$PATH\"");
85+
println!("export PATH=\"$MSVC_PATH:$OLD_PATH\"");
86+
} else {
87+
println!("export {}={:?}", key, value);
88+
}
5589
}
5690
}
5791
}

0 commit comments

Comments
 (0)