From f384088fd1017d89abd9e931f60c125e7347649a Mon Sep 17 00:00:00 2001
From: Jiahao XU <Jiahao_XU@outlook.com>
Date: Tue, 4 Apr 2023 01:51:13 +1000
Subject: [PATCH] Avoid checking dev-deps for jobs `*-check` and `lint` in
 workflow `ci.yml` (#978)

Avoid checking dev-deps for jobs `*-check` and lint in workflow `ci.yml`

We just want to make sure cargo-binstall can compile for the target, we
don't want to pull in the extra dependencies.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
---
 .github/workflows/ci.yml | 4 ++++
 justfile                 | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a6a8abe9..ee205af2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -85,6 +85,7 @@ jobs:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
     - run: just ci-install-deps
+    - run: just avoid-dev-deps
     - run: just check
 
   apple-m1-check:
@@ -102,6 +103,7 @@ jobs:
         # which works better when we provide it with GITHUB_TOKEN.
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
+    - run: just avoid-dev-deps
     - run: just check
 
   windows-aarch64-check:
@@ -119,6 +121,7 @@ jobs:
         # which works better when we provide it with GITHUB_TOKEN.
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
+    - run: just avoid-dev-deps
     - run: just check
 
   lint:
@@ -142,6 +145,7 @@ jobs:
 
     - run: just toolchain rustfmt,clippy
     - run: just ci-install-deps
+    - run: just avoid-dev-deps
     - run: just lint
 
   # Dummy job to have a stable name for the "all tests pass" requirement
diff --git a/justfile b/justfile
index fe6488b0..ae973e6d 100644
--- a/justfile
+++ b/justfile
@@ -220,6 +220,14 @@ fmt-check: fmt
 
 lint: clippy fmt-check
 
+# Some dev-dependencies require a newer version of Rust, but it doesn't matter for MSRV check
+# This is a workaround for the cargo nightly option `-Z avoid-dev-deps`
+avoid-dev-deps:
+    for crate in ./crates/*; do \
+        sed 's/\[dev-dependencies\]/[workaround-avoid-dev-deps]/g' "$crate/Cargo.toml" >"$crate/Cargo.toml.tmp"; \
+        mv "$crate/Cargo.toml.tmp" "$crate/Cargo.toml" \
+    ; done
+
 package-dir:
     rm -rf packages/prep
     mkdir -p packages/prep