From 21c05d159c8de1354d9aa2b74a376bc0ef60cdcd Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 21 Nov 2023 15:34:23 -0800 Subject: [PATCH] fix: Fix Cargo bin detection on Windows. (#1199) * Add exe check. * Update proto. * Bump. * Fix tests. * Fix tests. --- .yarn/versions/fa2671e9.yml | 9 +++++++++ Cargo.lock | 10 ++++++---- Cargo.toml | 2 +- crates/cli/src/app.rs | 3 +-- crates/cli/src/commands/upgrade.rs | 2 +- crates/cli/src/lib.rs | 3 +-- crates/cli/src/main.rs | 4 ++-- crates/rust/platform/src/rust_platform.rs | 10 ++++------ crates/rust/platform/tests/rust_platform_test.rs | 14 +++++++++++++- nextgen/common/src/path.rs | 13 +++++++++++++ packages/cli/CHANGELOG.md | 10 ++++++++++ 11 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 .yarn/versions/fa2671e9.yml diff --git a/.yarn/versions/fa2671e9.yml b/.yarn/versions/fa2671e9.yml new file mode 100644 index 00000000000..1f2a5d9c201 --- /dev/null +++ b/.yarn/versions/fa2671e9.yml @@ -0,0 +1,9 @@ +releases: + "@moonrepo/cli": patch + "@moonrepo/core-linux-arm64-gnu": patch + "@moonrepo/core-linux-arm64-musl": patch + "@moonrepo/core-linux-x64-gnu": patch + "@moonrepo/core-linux-x64-musl": patch + "@moonrepo/core-macos-arm64": patch + "@moonrepo/core-macos-x64": patch + "@moonrepo/core-windows-x64-msvc": patch diff --git a/Cargo.lock b/Cargo.lock index 6ead1f33888..4cb24b08424 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4655,9 +4655,9 @@ dependencies = [ [[package]] name = "proto_core" -version = "0.23.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44b64578ff10a1a39d3a3d94e0725c0ecdc5858ec6c42844289530dd15981b22" +checksum = "0f7dbc476e051d23cfac2b1f284ffa8943d45dffe40113dcdf113667b3dd8b79" dependencies = [ "cached", "extism", @@ -4676,6 +4676,7 @@ dependencies = [ "starbase_events", "starbase_styles", "starbase_utils", + "system_env", "thiserror", "tinytemplate", "tracing", @@ -5714,12 +5715,13 @@ dependencies = [ [[package]] name = "system_env" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5430c2b1d8315d22edaebbd40617f9110ccfd95e95684802d0d17907f44966" +checksum = "63476c953552c18056a153eaabc04d2987bc64f07633acc80d6a65a8574f1a3b" dependencies = [ "serde", "serde_json", + "shell-words", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 3a968f1571b..124c78a1df1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ pathdiff = "0.2.1" petgraph = { version = "0.6.4", default-features = false, features = [ "serde-1", ] } -proto_core = "0.23.2" +proto_core = "0.23.3" relative-path = { version = "1.9.0", features = ["serde"] } regex = "1.10.2" reqwest = { version = "0.11.22", default-features = false, features = [ diff --git a/crates/cli/src/app.rs b/crates/cli/src/app.rs index 82d3a4ef60e..9da2221a37b 100644 --- a/crates/cli/src/app.rs +++ b/crates/cli/src/app.rs @@ -23,12 +23,11 @@ use crate::commands::task::TaskArgs; use crate::enums::{CacheMode, LogLevel}; use clap::builder::styling::{Color, Style, Styles}; use clap::{Parser, Subcommand}; +use moon_common::consts::BIN_NAME; use starbase::State; use starbase_styles::color::Color as ColorType; use std::path::PathBuf; -pub const BIN_NAME: &str = if cfg!(windows) { "moon.exe" } else { "moon" }; - #[derive(Clone, Debug, Subcommand)] pub enum DockerCommands { #[command( diff --git a/crates/cli/src/commands/upgrade.rs b/crates/cli/src/commands/upgrade.rs index 3746052ef5d..37a8b463030 100644 --- a/crates/cli/src/commands/upgrade.rs +++ b/crates/cli/src/commands/upgrade.rs @@ -1,10 +1,10 @@ -use crate::app::BIN_NAME; use crate::helpers::create_progress_bar; use bytes::Buf; use itertools::Itertools; use miette::{miette, IntoDiagnostic}; use moon_api::Launchpad; use moon_cache::CacheEngine; +use moon_common::consts::BIN_NAME; use moon_utils::{get_workspace_root, semver::Version}; use starbase::system; use starbase_utils::{dirs, fs}; diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 1e9575bd9e0..9c4f20cf2e6 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -33,6 +33,7 @@ use app::App as CLI; use clap::Parser; use commands::migrate::FromTurborepoArgs; use enums::{CacheMode, LogLevel}; +use moon_common::consts::BIN_NAME; use starbase::{tracing::TracingOptions, App, AppResult}; use starbase_styles::color; use starbase_utils::string_vec; @@ -40,8 +41,6 @@ use std::env; use std::ffi::OsString; use tracing::debug; -pub use app::BIN_NAME; - fn setup_logging(level: &LogLevel) { env::set_var("MOON_APP_LOG", level.to_string()); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 9e5564ccf18..eeba6f9d6f7 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,7 +1,7 @@ use miette::IntoDiagnostic; use mimalloc::MiMalloc; -use moon_cli::{run_cli, BIN_NAME}; -use moon_common::consts::CONFIG_DIRNAME; +use moon_cli::run_cli; +use moon_common::consts::{BIN_NAME, CONFIG_DIRNAME}; use moon_node_lang::{ node::{extract_canonical_node_module_bin, BinFile}, NODE, diff --git a/crates/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index 2e5f3c47e2a..83c1b409917 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -2,7 +2,7 @@ use crate::{ find_cargo_lock, get_cargo_home, target_hash::RustTargetHash, toolchain_hash::RustToolchainHash, }; use moon_action_context::ActionContext; -use moon_common::{is_ci, Id}; +use moon_common::{is_ci, path::exe_name, Id}; use moon_config::{ BinEntry, HasherConfig, PlatformType, ProjectConfig, ProjectsAliasesMap, ProjectsSourcesMap, RustConfig, UnresolvedVersionSpec, @@ -282,9 +282,7 @@ impl Platform for RustPlatform { let globals_dir = self.get_globals_dir(Some(tool)); // Install cargo-binstall if it does not exist - if !globals_dir.join("cargo-binstall").exists() - && !globals_dir.join("cargo-binstall.exe").exists() - { + if !globals_dir.join(exe_name("cargo-binstall")).exists() { debug!( target: LOG_TARGET, "{} does not exist, installing", @@ -525,10 +523,10 @@ impl Platform for RustPlatform { // Binary may be installed to ~/.cargo/bin _ => { let globals_dir = self.get_globals_dir(self.toolchain.get().ok()); - let global_bin_path = globals_dir.join(&task.command); + let global_bin_path = globals_dir.join(exe_name(&task.command)); let cargo_bin = task.command.strip_prefix("cargo-").unwrap_or(&task.command); - let cargo_bin_path = globals_dir.join(format!("cargo-{}", cargo_bin)); + let cargo_bin_path = globals_dir.join(exe_name(format!("cargo-{}", cargo_bin))); // Must run through cargo if cargo_bin_path.exists() { diff --git a/crates/rust/platform/tests/rust_platform_test.rs b/crates/rust/platform/tests/rust_platform_test.rs index 858a32ca78f..46010e75da9 100644 --- a/crates/rust/platform/tests/rust_platform_test.rs +++ b/crates/rust/platform/tests/rust_platform_test.rs @@ -288,6 +288,7 @@ mod target_command { async fn uses_cargo_bin() { let sandbox = create_sandbox("rust/project"); sandbox.create_file("bin/cargo-nextest", ""); + sandbox.create_file("bin/cargo-nextest.exe", ""); let mut task = create_task(); task.command = "nextest".into(); @@ -307,6 +308,7 @@ mod target_command { async fn uses_cargo_bin_with_prefix() { let sandbox = create_sandbox("rust/project"); sandbox.create_file("bin/cargo-nextest", ""); + sandbox.create_file("bin/cargo-nextest.exe", ""); let mut task = create_task(); task.command = "cargo-nextest".into(); @@ -326,6 +328,7 @@ mod target_command { async fn uses_global_bin() { let sandbox = create_sandbox("rust/project"); sandbox.create_file("bin/sea-orm", ""); + sandbox.create_file("bin/sea-orm.exe", ""); let mut task = create_task(); task.command = "sea-orm".into(); @@ -339,7 +342,16 @@ mod target_command { assert_eq!( command.bin, - sandbox.path().join("bin").join("sea-orm").to_str().unwrap() + sandbox + .path() + .join("bin") + .join(if cfg!(windows) { + "sea-orm.exe" + } else { + "sea-orm" + }) + .to_str() + .unwrap() ); assert_eq!(command.args, &["migrate", "-u"]); } diff --git a/nextgen/common/src/path.rs b/nextgen/common/src/path.rs index 7566185cd7b..6644b0c5970 100644 --- a/nextgen/common/src/path.rs +++ b/nextgen/common/src/path.rs @@ -74,3 +74,16 @@ pub fn to_string>(path: T) -> miette::Result { pub fn to_virtual_string>(path: T) -> miette::Result { Ok(standardize_separators(to_string(path)?)) } + +#[inline] +pub fn exe_name>(name: T) -> String { + #[cfg(windows)] + { + format!("{}.exe", name.as_ref()) + } + + #[cfg(not(windows))] + { + name.as_ref().into() + } +} diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index d90d813f296..db52705d838 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -10,6 +10,16 @@ - More accurately monitors signals (ctrl+c) and shutdowns. - Tasks can now be configured with a timeout. +## Unreleased + +#### 🐞 Fixes + +- Fixed an issue where we would fail to find Cargo binaries on Windows. + +#### ⚙️ Internal + +- Updated proto to v0.23.3. + ## 1.17.2 #### 🐞 Fixes