Skip to content

Commit

Permalink
fix: Fix Cargo bin detection on Windows. (#1199)
Browse files Browse the repository at this point in the history
* Add exe check.

* Update proto.

* Bump.

* Fix tests.

* Fix tests.
  • Loading branch information
milesj authored Nov 21, 2023
1 parent 84db7a3 commit 21c05d1
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 19 deletions.
9 changes: 9 additions & 0 deletions .yarn/versions/fa2671e9.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ 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;
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());

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 4 additions & 6 deletions crates/rust/platform/src/rust_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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() {
Expand Down
14 changes: 13 additions & 1 deletion crates/rust/platform/tests/rust_platform_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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"]);
}
Expand Down
13 changes: 13 additions & 0 deletions nextgen/common/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ pub fn to_string<T: AsRef<Path>>(path: T) -> miette::Result<String> {
pub fn to_virtual_string<T: AsRef<Path>>(path: T) -> miette::Result<String> {
Ok(standardize_separators(to_string(path)?))
}

#[inline]
pub fn exe_name<T: AsRef<str>>(name: T) -> String {
#[cfg(windows)]
{
format!("{}.exe", name.as_ref())
}

#[cfg(not(windows))]
{
name.as_ref().into()
}
}
10 changes: 10 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21c05d1

Please sign in to comment.