From 10178ade356f33f7603a217fe39680ae6c1c08ad Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Fri, 7 Apr 2023 12:57:50 -0500 Subject: [PATCH] fix: Use / paths when building WASM Changed the build-wasm command to always use forward slashes in paths, since using Windows style paths breaks if the build is run with Docker. Fixes #532 --- Cargo.lock | 7 +++++++ cli/Cargo.toml | 1 + cli/src/wasm.rs | 15 ++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52013e49..7c3fa7eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -440,6 +440,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + [[package]] name = "percent-encoding" version = "2.2.0" @@ -774,6 +780,7 @@ dependencies = [ "indexmap", "lazy_static", "log", + "path-slash", "pretty_assertions", "rand", "regex", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 48473095..ee6d52af 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -30,6 +30,7 @@ glob = "0.3.0" html-escape = "0.2.6" indexmap = "1" lazy_static = "1.2.0" +path-slash = "0.2.1" regex = "1" regex-syntax = "0.6.4" rustc-hash = "1" diff --git a/cli/src/wasm.rs b/cli/src/wasm.rs index 467fef71..35f09b55 100644 --- a/cli/src/wasm.rs +++ b/cli/src/wasm.rs @@ -1,5 +1,6 @@ use super::generate::parse_grammar::GrammarJSON; use anyhow::{anyhow, Context, Result}; +use path_slash::PathExt as _; use std::ffi::{OsStr, OsString}; use std::fs; use std::path::Path; @@ -41,7 +42,7 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu volume_string = OsString::from(parent); volume_string.push(":/src:Z"); command.arg("--workdir"); - command.arg(&Path::new("/src").join(filename)); + command.arg(Path::new("/src").join(filename).to_slash_lossy().as_ref()); } else { volume_string = OsString::from(language_dir); volume_string.push(":/src:Z"); @@ -103,14 +104,18 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu let scanner_cpp_path = src.join("scanner.cpp"); if language_dir.join(&scanner_cc_path).exists() { - command.arg("-xc++").arg(&scanner_cc_path); + command + .arg("-xc++") + .arg(scanner_cc_path.to_slash_lossy().as_ref()); } else if language_dir.join(&scanner_cpp_path).exists() { - command.arg("-xc++").arg(&scanner_cpp_path); + command + .arg("-xc++") + .arg(scanner_cpp_path.to_slash_lossy().as_ref()); } else if language_dir.join(&scanner_c_path).exists() { - command.arg(&scanner_c_path); + command.arg(scanner_c_path.to_slash_lossy().as_ref()); } - command.arg(&parser_c_path); + command.arg(parser_c_path.to_slash_lossy().as_ref()); let output = command .output()