From 4eceabeaad1736abacbdeda8a8a523e8acf5fb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sat, 8 Mar 2025 00:52:06 +0800 Subject: [PATCH] Fix path env on cygwin when cross compiling from Windows --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 3 +++ build.rs | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0517cd39d..33aa99e64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 98c8148b6..16a7e288e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/build.rs b/build.rs index 5ce3beb2d..4a7fe027e 100644 --- a/build.rs +++ b/build.rs @@ -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> { } 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() {