Skip to content

Commit

Permalink
feat: Add Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Dec 1, 2023
1 parent 2b10208 commit f3c2862
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 67 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]
name: ci

jobs:
build_and_test:
test_coverage:
name: cargo-run-bin
runs-on: ubuntu-latest
steps:
Expand All @@ -30,3 +30,24 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info

test:
name: cargo-run-bin
strategy:
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
with:
cache-directories: ".bin"
- name: Install deps
run: |
cargo install --path .
cargo bin --build
- name: Test
run: cargo nextest run
83 changes: 49 additions & 34 deletions Cargo.lock

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

25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ name = "cargo-bin"
path = "src/main.rs"

[dependencies]
anyhow = "1.0.40"
clap = "4.3.19"
owo-colors = "3.5.0"
serde = { version = "1.0.149", features = ["derive"] }
toml = "0.5.9"
toml_edit = "0.19.14"
version_check = "0.9.3"
which = "4.4.0"
anyhow = "=1.0.40"
cfg-if = "=1.0.0"
clap = "=4.3.19"
owo-colors = "=3.5.0"
serde = { version = "=1.0.149", features = ["derive"] }
toml = "=0.5.9"
toml_edit = "=0.19.14"
version_check = "=0.9.3"
which = "=4.4.0"

[dev-dependencies]
assert_cmd = "2.0.12"
cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] }
insta = { version = "1.31.0", features = ["yaml"] }
assert_cmd = "=2.0.12"
cargo-husky = { version = "=1.5.0", default-features = false, features = ["user-hooks"] }
insta = { version = "=1.31.0", features = ["yaml"] }

[package.metadata.bin]
cargo-binstall = { version = "1.4.4" }
cargo-binstall = { version = "1.4.6" }
cargo-cmd = { version = "0.3.1" }
cargo-deny = { version = "0.13.5" }
cargo-dist = { version = "0.1.0-prerelease.10" }
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.71.1"
channel = "1.74.0"
components = ["rustfmt", "clippy", "llvm-tools-preview"]
13 changes: 6 additions & 7 deletions src/binary.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::env;
use std::fs;
use std::io;
use std::os::fd::AsFd;
use std::path;
use std::process;

Expand All @@ -22,11 +21,10 @@ pub fn cargo_install(
binary_package: metadata::BinaryPackage,
cache_path: path::PathBuf,
) -> Result<()> {
let stderr = io::stderr().as_fd().try_clone_to_owned()?;
let mut cmd_prefix = process::Command::new("cargo");

cmd_prefix
.stdout::<std::process::Stdio>(stderr.into())
.stdout(io::stderr())
.stderr(process::Stdio::inherit())
.arg("install")
.arg("--root")
Expand Down Expand Up @@ -74,12 +72,10 @@ pub fn cargo_install(
}

pub fn binstall(binary_package: metadata::BinaryPackage, cache_path: path::PathBuf) -> Result<()> {
let stderr = io::stderr().as_fd().try_clone_to_owned()?;

let mut cmd_prefix = process::Command::new("cargo");

cmd_prefix
.stdout::<std::process::Stdio>(stderr.into())
.stdout(io::stderr())
.stderr(process::Stdio::inherit())
.arg("binstall")
.arg("--no-confirm")
Expand Down Expand Up @@ -131,8 +127,11 @@ pub fn install(binary_package: metadata::BinaryPackage) -> Result<String> {
.join(binary_package.package.clone())
.join(binary_package.version.clone());
let cache_bin_path = cache_path.join("bin").join(bin_name);
let mut cache_bin_path_win = cache_bin_path.clone();
cache_bin_path_win.set_extension("exe");

if !path::Path::new(&cache_bin_path).exists() {
if !path::Path::new(&cache_bin_path).exists() && !path::Path::new(&cache_bin_path_win).exists()
{
fs::create_dir_all(&cache_path)?;
if binary_package.bin_target.is_none()
&& binary_package.features.is_none()
Expand Down
4 changes: 3 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ pub fn run() -> Result<()> {
app.print_long_help()?;
} else {
let mut args: Vec<_> = env::args().collect();
let start_index = args.iter().position(|e| return e.ends_with("/cargo-bin"));
let start_index = args
.iter()
.position(|e| return e.ends_with("/cargo-bin") || e.ends_with("cargo-bin.exe"));
if start_index.is_none() || start_index.unwrap() == (args.len() + 1) {
app.print_long_help()?;
return Ok(());
Expand Down
Loading

0 comments on commit f3c2862

Please sign in to comment.