Fix path env on cygwin when cross compiling from Windows

This commit is contained in:
王宇逸
2025-03-08 00:52:06 +08:00
committed by Johannes Altmanninger
parent 2e89f37446
commit 4eceabeaad
3 changed files with 25 additions and 1 deletions

16
Cargo.lock generated
View File

@@ -117,6 +117,7 @@ dependencies = [
"rust-embed",
"serial_test",
"terminfo",
"unix_path",
"widestring",
]
@@ -545,6 +546,21 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unix_path"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8e291873ae77c4c8d9c9b34d0bee68a35b048fb39c263a5155e0e353783eaf"
dependencies = [
"unix_str",
]
[[package]]
name = "unix_str"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ace0b4755d0a2959962769239d56267f8a024fef2d9b32666b3dcd0946b0906"
[[package]]
name = "version_check"
version = "0.9.5"

View File

@@ -71,6 +71,9 @@ serial_test = { version = "3", default-features = false }
cc = "1.0.94"
rsconf = "0.2.2"
[target.'cfg(windows)'.build-dependencies]
unix_path = "1.0.1"
[lib]
crate-type = ["rlib"]
path = "src/lib.rs"

View File

@@ -3,7 +3,7 @@
use rsconf::{LinkType, Target};
use std::env;
use std::error::Error;
use std::path::{Path, PathBuf};
use std::path::Path;
fn main() {
setup_paths();
@@ -232,6 +232,11 @@ fn has_small_stack(_: &Target) -> Result<bool, Box<dyn Error>> {
}
fn setup_paths() {
#[cfg(unix)]
use std::path::PathBuf;
#[cfg(windows)]
use unix_path::{Path, PathBuf};
fn get_path(name: &str, default: &str, onvar: &Path) -> PathBuf {
let mut var = PathBuf::from(env::var(name).unwrap_or(default.to_string()));
if var.is_relative() {