Skip to content

Commit

Permalink
fix(hydro_deploy): avoid inflexible \\?\ canonical paths on windows…
Browse files Browse the repository at this point in the history
… to mitigate `/` separator errors (#1014)
  • Loading branch information
MingweiSamuel committed Jan 4, 2024
1 parent 3f5b411 commit d23c229
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions hydro_deploy/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ documentation = "https://docs.rs/hydro_deploy/"
description = "Hydro Deploy"

[dependencies]
tokio = { version = "1.16", features = [ "full" ] }
tokio-util = { version = "0.7.7", features=[ "compat" ] }
once_cell = "1.17"
anyhow = { version = "1.0.69", features = [ "backtrace" ] }
async-trait = "0.1.64"
async-channel = "1.8.0"
async-once-cell = "0.5.3"
async-process = "1.6.0"
async-recursion = "1"
async-recursion = "1.0"
async-ssh2-lite = { version = "0.4.2", features = [ "tokio" ] }
async-trait = "0.1.64"
bytes = "1.1.0"
cargo_metadata = "0.15.4"
dunce = "1.0.4"
dyn-clone = "1"
futures = "0.3.26"
futures-core = "0.3.26"
async-channel = "1.8.0"
hydroflow_cli_integration = { path = "../hydroflow_cli_integration", version = "^0.3.0" }
indicatif = "0.17.6"
nanoid = "0.4.0"
nix = "0.26.2"
once_cell = "1.17"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
tempfile = "3.3.0"
async-ssh2-lite = { version = "0.4.2", features = [ "tokio" ] }
shell-escape = "0.1.5"
dyn-clone = "1"
bytes = "1.1.0"
nanoid = "0.4.0"
nix = "0.26.2"
hydroflow_cli_integration = { path = "../hydroflow_cli_integration", version = "^0.3.0" }
indicatif = "0.17.6"
cargo_metadata = "0.15.4"
async-once-cell = "0.5.3"
tempfile = "3.3.0"
tokio = { version = "1.16", features = [ "full" ] }
tokio-util = { version = "0.7.7", features=[ "compat" ] }
12 changes: 10 additions & 2 deletions hydro_deploy/core/src/hydroflow_crate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::error::Error;
use std::fmt::Display;
use std::io::BufRead;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};

Expand Down Expand Up @@ -30,13 +30,21 @@ static BUILDS: Lazy<Mutex<HashMap<CacheKey, Arc<OnceCell<BuiltCrate>>>>> =
Lazy::new(Default::default);

pub async fn build_crate(
src: PathBuf,
src: impl AsRef<Path>,
bin: Option<String>,
example: Option<String>,
profile: Option<String>,
target_type: HostTargetType,
features: Option<Vec<String>>,
) -> Result<BuiltCrate, BuildError> {
// `fs::canonicalize` prepends windows paths with the `r"\\?\"`
// https://stackoverflow.com/questions/21194530/what-does-mean-when-prepended-to-a-file-path
// However, this breaks the `include!(concat!(env!("OUT_DIR"), "/my/forward/slash/path.rs"))`
// Rust codegen pattern on windows. To help mitigate this happening in third party crates, we
// instead use `dunce::canonicalize` which is the same as `fs::canonicalize` but avoids the
// `\\?\` prefix when possible.
let src = dunce::canonicalize(src).expect("Failed to canonicalize path for build.");

let key = CacheKey {
src: src.clone(),
bin: bin.clone(),
Expand Down
2 changes: 1 addition & 1 deletion hydro_deploy/core/src/hydroflow_crate/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl HydroflowCrateService {
}

fn build(&self) -> impl Future<Output = Result<BuiltCrate, BuildError>> {
let src_cloned = self.src.canonicalize().unwrap();
let src_cloned = self.src.clone();
let bin_cloned = self.bin.clone();
let example_cloned = self.example.clone();
let features_cloned = self.features.clone();
Expand Down

0 comments on commit d23c229

Please sign in to comment.