Compare commits

..

68 Commits

Author SHA1 Message Date
github-actions[bot]
267a8a94c9
Merge pull request #254 from Swatinem/dependabot/npm_and_yarn/prd-patch-d0e2e2b032
Bump the prd-patch group with 2 updates
2025-08-14 11:19:25 +00:00
dependabot[bot]
46cb408fba
Bump the prd-patch group with 2 updates
Bumps the prd-patch group with 2 updates: [@actions/cache](https://github.com/actions/toolkit/tree/HEAD/packages/cache) and [smol-toml](https://github.com/squirrelchat/smol-toml).


Updates `@actions/cache` from 4.0.3 to 4.0.5
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/cache)

Updates `smol-toml` from 1.4.1 to 1.4.2
- [Release notes](https://github.com/squirrelchat/smol-toml/releases)
- [Commits](https://github.com/squirrelchat/smol-toml/compare/v1.4.1...v1.4.2)

---
updated-dependencies:
- dependency-name: "@actions/cache"
  dependency-version: 4.0.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: prd-patch
- dependency-name: smol-toml
  dependency-version: 1.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: prd-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-14 11:14:50 +00:00
Rene Leonhardt
203c9eb82a
chore: fix dependabot groups (#253) 2025-08-14 13:12:32 +02:00
Rene Leonhardt
a8b36e3f74
chore(deps): update dependencies (#251) 2025-07-26 20:53:41 +02:00
Arsenii Lyashenko
7e1e2d0a10
Set empty CARGO_ENCODED_RUSTFLAGS in workspace metadata retrieval (#249) 2025-06-27 19:56:05 +02:00
Arpad Borsos
98c8021b55
2.8.0 2025-06-25 18:29:46 +02:00
Arpad Borsos
14d3bc39c4
update Changelog 2025-06-25 18:29:46 +02:00
Sammy Harris
52ea1434f8
support warpbuild cache provider (#247) 2025-06-24 19:04:05 +02:00
Jeroen Bransen
eaa85be6b1
Add cache-workspace-crates feature (#246) 2025-06-22 10:43:50 +02:00
Arpad Borsos
901019c0f8
Update the test lockfiles 2025-06-20 09:12:23 +02:00
Arpad Borsos
9d47c6ad4b
2.7.8 2025-03-19 08:16:06 +01:00
Linda_pp
27b8ea9368
Include CPU arch in the cache key (#228) 2025-02-08 15:36:01 +01:00
Arpad Borsos
f0deed1e0e
2.7.7 2024-12-29 08:48:10 +01:00
Arpad Borsos
008623fb83
also cache cargo install metadata 2024-12-29 08:47:45 +01:00
Arpad Borsos
720f7e45cc
2.7.6 2024-12-28 08:37:30 +01:00
Arpad Borsos
4b1f006ad2
update dependencies, in particular @actions/cache 2024-12-28 08:36:36 +01:00
Benjy Weinberger
e8e63cdbf2
Allow opting out of caching $CARGO_HOME/bin. (#216)
Prevents wiping the bin directory, which is harmful for
self-hosted runners.
2024-12-10 08:47:51 +01:00
Rano | Ranadeep
9a2e0d3212
add runner OS in cache key (#220) 2024-12-09 22:32:01 +01:00
Daniel LeCheminant
c00f3025ca
Adds an option to do lookup-only of the cache (#217) 2024-11-08 20:36:34 +01:00
guylamar2006
68b3cb7503
Updated artifact upload action to v4 (#212) 2024-10-17 09:52:18 +02:00
Arpad Borsos
82a92a6e8f
2.7.5 2024-10-12 12:15:11 +02:00
Arpad Borsos
598fe25fa1
update dependencies, rebuild 2024-10-12 12:14:29 +02:00
Jiahao XU
8f842c2d45
Support Cargo.lock format cargo-lock v4 (#211)
Fixed #209

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2024-10-08 20:55:46 +02:00
Gunnar Lilleaasen
96a8d65dba
Only run macOsWorkaround() on macOS (#206) 2024-09-17 17:45:02 +02:00
Hamir Mahal
9bdad043e8
fix: usage of deprecated version of node (#197) 2024-05-03 16:02:43 +02:00
Arpad Borsos
f7a52f6914
"add jsonpath test" 2024-03-24 10:00:25 +01:00
Arpad Borsos
2bceda3912
"update dependencies" 2024-03-24 09:56:50 +01:00
Carsten Wenderdel
640a22190e
Upgrade checkout action from version 3 to 4 (#190)
This fixes issue #189.

This is necessary because GitHub actions are going to drop support for Node.js 16.
Version 4 uses Node.js 20.
See https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
2024-02-27 08:23:34 +01:00
Arpad Borsos
1582741630
update dependencies 2024-02-04 09:29:45 +01:00
Arpad Borsos
23bce251a8
2.7.3 2024-01-14 09:31:14 +01:00
Arpad Borsos
378c8285a4
Work around upstream GitHub issue and update dependencies 2024-01-14 09:26:03 +01:00
Arpad Borsos
a226033982
2.7.2 2024-01-10 19:34:14 +01:00
Max Heller
d30f1144e8
Only key by Cargo.toml and Cargo.lock files of workspace members (#180) 2023-12-03 11:57:51 +01:00
Linda_pp
b1db5f9d5f
Update action runtime to node20 (#175) 2023-10-25 20:36:38 +02:00
Arpad Borsos
3cf7f8cc28
2.7.1 2023-10-21 10:37:46 +02:00
Arpad Borsos
e03705e031
changelog 2023-10-21 10:37:41 +02:00
Arpad Borsos
b86d1c6caa
bump all the other dependencies too 2023-10-21 10:36:18 +02:00
Wyatt Herkamp
f27990c89a
Update Dependencies (#172)
Update smol-toml 1.1.3
2023-10-20 15:35:55 +02:00
Arpad Borsos
a95ba19544
2.7.0 2023-09-12 19:34:11 +02:00
Arpad Borsos
82c8487d00
changelog 2023-09-12 19:34:01 +02:00
Filippo Neysofu Costa
67c46e7159
Support for trybuild and similar macro testing tools (#168)
Signed-off-by: Filippo Costa <filippo@neysofu.me>
2023-09-12 19:32:03 +02:00
Lucas Kent
44b6087283
Fix save-if documentation in readme (#166) 2023-08-24 15:18:39 +02:00
Arpad Borsos
e207df5d26
2.6.2 2023-08-20 10:28:01 +02:00
Arpad Borsos
decb69d790
Update dependencies and add changelog 2023-08-20 10:27:32 +02:00
Jiahao XU
ab6b2769d1
dep: Use smol-toml instead of toml (#164)
Fixed #162 #163

The former is listed on
https://github.com/toml-lang/toml/wiki#implementations and is toml 1.0
compliant.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-08-19 12:23:03 +02:00
Arpad Borsos
578b235f6e
2.6.1 2023-08-12 16:51:06 +02:00
Arpad Borsos
5113490c3f
prepare 2.6.1 2023-08-12 16:50:53 +02:00
Jiahao XU
c0e052c18c
Fix hashing of parsed Cargo.toml (#160)
The values for the dependencies could be strings intead of objects, so
add a `try` block to take care of that.

Also set `dep.path` to `""` if the dependency contains a key `path` to
make sure that the cache isn't invalidated due to change in workspace.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-08-12 12:34:30 +02:00
Jiahao XU
4e0f4b19dd
Fix typo in hashing parsed Cargo.lock (#159)
This simple mistake caused the entire `Cargo.lock` to be ignored (JS
treats having no return as `false`).

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-08-10 19:50:14 +02:00
Jiahao XU
b919e1427f
feat: Add logging to Cargo.lock/Cargo.toml hashing (#156)
There are a few problems in cargo-binstall where sometimes change to
`Cargo.lock` does not invalidate the cache.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-08-04 12:39:02 +02:00
Arpad Borsos
b8a6852b4f
2.6.0 2023-08-02 13:06:28 +02:00
Arpad Borsos
80c47cc945
Clean up credentials.toml 2023-08-02 12:54:48 +02:00
Arpad Borsos
5ec9842c14
bump test dependencies 2023-08-02 12:47:24 +02:00
Arpad Borsos
3312b3ab47
Slightly improve docs 2023-08-02 12:46:45 +02:00
Arpad Borsos
f6987ea139
Improve errors and cleanup
- Silence errors and do not create error annotations, fixes #144
- Implement cleanup for new sparse registry
- Do not clean `-sys` dependencies from `registry/src`, hopefully fixes  #150
2023-08-02 12:15:14 +02:00
Arpad Borsos
e97a782690
move buildjet test into its own workflow 2023-08-02 10:38:22 +02:00
Jordan Oroshiba
b00faf5858
Add BuildJet Option (#154) 2023-08-01 09:01:11 +02:00
Arpad Borsos
9de8f90afb
Add jemalloc to test -sys style dependencies 2023-07-31 16:34:21 +02:00
Arpad Borsos
fd201ad913
test globbing of rust-toolchain differently 2023-07-31 16:26:42 +02:00
Arpad Borsos
cf3f88254c
"properly rename git-registry workflow" 2023-07-31 16:02:24 +02:00
Arpad Borsos
4fedae9bcf
"update dependencies and rebuild" 2023-07-31 16:01:23 +02:00
Arpad Borsos
1e604afb09
Update workflow definitions
- Use rust `--no-self-update` flag instead of separate command.
- Add an explicit test for the `git` registry, as the sparse registry is now the default.
2023-07-31 15:31:10 +02:00
Arpad Borsos
dd05243424
2.5.1 2023-07-03 19:38:11 +02:00
Arpad Borsos
65dbc54a5d
update changelog 2023-07-03 19:38:01 +02:00
Jiahao XU
be7377e68e
fix src/config.ts: Remove sort_object (#152)
Fixed #151

I've tried running manually load and parse `Cargo.lock` and it runs fine
until `sort_object` is called.

Since `Cargo.lock` is auto-generated and usually sorted, I think there
is no need for sorting.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-06-27 08:55:56 +02:00
Arpad Borsos
2656b87321
2.5.0 2023-06-18 15:32:29 +02:00
Jiahao XU
715970feed
feat: Add hash of .cargo/config.toml to key (#149)
Also:
 - Add and use `sort_and_uniq` to make sure `globFile` resulting
   and `keyFiles` does not contain duplicates.
 - Only returns regular file in function `globFile`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-06-18 10:12:25 +02:00
Jiahao XU
3d4000164d
feat: Rm workspace crates version before caching (#147)
Fixed #146

 - Set all `package.version` in `Cargo.toml` to `0.0.0`
 - Set `{build-, dev-, }dependencies` of workspace crates to `0.0.0`
 - Remove workspace crates from `Cargo.lock` before caching
 - Sort all toml objects before hashing them as json

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-06-18 09:29:44 +02:00
38 changed files with 237750 additions and 71334 deletions

50
.github/dependabot.yaml vendored Normal file
View File

@ -0,0 +1,50 @@
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/optimizing-pr-creation-version-updates#setting-up-a-cooldown-period-for-dependency-updates
version: 2
updates:
- package-ecosystem: cargo
directories:
- tests
- tests/wasm-workspace
schedule:
interval: weekly
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#groups--
# 1 PR per week and group
groups:
cargo-major:
update-types: ["major"]
cargo-minor:
update-types: ["minor"]
cargo-patch:
update-types: ["patch"]
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions:
# Combine all images of the last week
patterns: ["*"]
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
groups:
prd-major:
dependency-type: "production"
update-types: ["major"]
prd-minor:
dependency-type: "production"
update-types: ["minor"]
prd-patch:
dependency-type: "production"
update-types: ["patch"]
dev-major:
dependency-type: "development"
update-types: ["major"]
dev-minor:
dependency-type: "development"
update-types: ["minor"]
dev-patch:
dependency-type: "development"
update-types: ["patch"]

33
.github/workflows/buildjet.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: buildjet
on: [push, pull_request]
jobs:
buildjet:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: Test buildjet provider on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- run: rustup toolchain install stable --profile minimal --no-self-update
- uses: ./
with:
workspaces: tests
cache-provider: buildjet
- run: |
cargo check
cargo test
cargo build --release
working-directory: tests

View File

@ -5,22 +5,23 @@ on:
branches:
- master
paths-ignore:
- '**.md'
- "**.md"
pull_request:
paths-ignore:
- '**.md'
- "**.md"
workflow_dispatch:
jobs:
check-dist:
if: github.repository == 'Swatinem/rust-cache'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Setup Node.js 16.x
uses: actions/setup-node@v3
- name: Setup Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
cache: npm
- name: Install dependencies
@ -38,7 +39,7 @@ jobs:
fi
id: diff
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist

View File

@ -4,6 +4,7 @@ on: [push, pull_request]
jobs:
coverage:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -16,13 +17,9 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal --component llvm-tools-preview
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update
- uses: taiki-e/install-action@cargo-llvm-cov

25
.github/workflows/dependabot.yml vendored Normal file
View File

@ -0,0 +1,25 @@
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#enabling-automerge-on-a-pull-request
name: Dependabot Automation
on: pull_request
permissions:
contents: write
pull-requests: write
jobs:
automerge:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'Swatinem/rust-cache'
steps:
- name: Fetch metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge Patch PRs
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

32
.github/workflows/git-registry.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: git-registry
on: [push, pull_request]
jobs:
git-registry:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: Test cargo "git" registry on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
steps:
- uses: actions/checkout@v5
- run: rustup toolchain install stable --profile minimal --no-self-update
- uses: ./
with:
workspaces: tests
- run: |
cargo check
cargo test
working-directory: tests

View File

@ -1,23 +0,0 @@
name: globbed-directories
on: [push, pull_request]
jobs:
simple:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
name: Test `cargo check/test` on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- name: Create folder that will be globbed
run: |
mkdir -p folder/rust-toolchain
- uses: ./

View File

@ -4,6 +4,7 @@ on: [push, pull_request]
jobs:
install:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -16,13 +17,9 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- run: rustup toolchain install stable --profile minimal --no-self-update
- uses: ./

View File

@ -4,25 +4,22 @@ on: [push, pull_request]
jobs:
simple:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: Test `cargo check/test` on ${{ matrix.os }}
name: Test `cargo check/test/build` on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- run: rustup toolchain install stable --profile minimal --no-self-update
- uses: ./
with:
@ -31,4 +28,5 @@ jobs:
- run: |
cargo check
cargo test
cargo build --release
working-directory: tests

View File

@ -1,36 +0,0 @@
name: sparse-registry
on: [push, pull_request]
jobs:
sparse-registry:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: Test `cargo check/test` with sparse registry on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
CARGO_UNSTABLE_SPARSE_REGISTRY: true
steps:
- uses: actions/checkout@v3
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install nightly --profile minimal
rustup default nightly
- uses: ./
with:
workspaces: tests
- run: |
cargo check
cargo test
working-directory: tests

View File

@ -4,6 +4,7 @@ on: [push, pull_request]
jobs:
target-dir:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -16,13 +17,9 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- run: rustup toolchain install stable --profile minimal --no-self-update
# the `workspaces` option has the format `$workspace -> $target-dir`
# and the `$target-dir` is relative to the `$workspace`.

View File

@ -4,6 +4,7 @@ on: [push, pull_request]
jobs:
workspaces:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -16,13 +17,9 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown
- run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
- uses: ./
with:
@ -30,8 +27,10 @@ jobs:
tests
tests/wasm-workspace
- run: cargo check
- name: cargo check (tests)
working-directory: tests
run: cargo check
- run: cargo check
- name: cargo check (tests/wasm-workspace)
working-directory: tests/wasm-workspace
run: cargo check

View File

@ -1,5 +1,69 @@
# Changelog
## 2.8.0
- Add support for `warpbuild` cache provider
- Add new `cache-workspace-crates` feature
## 2.7.8
- Include CPU arch in the cache key
## 2.7.7
- Also cache `cargo install` metadata
## 2.7.6
- Allow opting out of caching $CARGO_HOME/bin
- Add runner OS in cache key
- Adds an option to do lookup-only of the cache
## 2.7.5
- Support Cargo.lock format cargo-lock v4
- Only run macOsWorkaround() on macOS
## 2.7.3
- Work around upstream problem that causes cache saving to hang for minutes.
## 2.7.2
- Only key by `Cargo.toml` and `Cargo.lock` files of workspace members.
## 2.7.1
- Update toml parser to fix parsing errors.
## 2.7.0
- Properly cache `trybuild` tests.
## 2.6.2
- Fix `toml` parsing.
## 2.6.1
- Fix hash contributions of `Cargo.lock`/`Cargo.toml` files.
## 2.6.0
- Add "buildjet" as a second `cache-provider` backend.
- Clean up sparse registry index.
- Do not clean up src of `-sys` crates.
- Remove `.cargo/credentials.toml` before saving.
## 2.5.1
- Fix hash contribution of `Cargo.lock`.
## 2.5.0
- feat: Rm workspace crates version before caching.
- feat: Add hash of `.cargo/config.toml` to key.
## 2.4.0
- Fix cache key stability.

View File

@ -6,7 +6,7 @@ sensible defaults.
## Example usage
```yaml
- uses: actions/checkout@v3
- uses: actions/checkout@v5
# selecting a toolchain either by action or manual `rustup` calls should happen
# before the plugin, as the cache uses the current rustc version as its cache key
@ -60,11 +60,35 @@ sensible defaults.
# default: "false"
cache-all-crates: ""
# Determiners whether the cache should be saved.
# Similar to cache-all-crates.
# If `true` the workspace crates will be cached.
# Useful if the workspace contains libraries that are only updated sporadically.
# default: "false"
cache-workspace-crates: ""
# Determines whether the cache should be saved.
# If `false`, the cache is only restored.
# Useful for jobs where the matrix is additive e.g. additional Cargo features.
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
# or when only runs from `master` should be saved to the cache.
# default: "true"
save-if: ""
# To only cache runs from `master`:
save-if: ${{ github.ref == 'refs/heads/master' }}
# Determines whether the cache should be restored.
# If `true` the cache key will be checked and the `cache-hit` output will be set
# but the cache itself won't be restored
# default: "false"
lookup-only: ""
# Specifies what to use as the backend providing cache
# Can be set to "github", "buildjet", or "warpbuild"
# default: "github"
cache-provider: ""
# Determines whether to cache the ~/.cargo/bin directory.
# default: "true"
cache-bin: ""
```
Further examples are available in the [.github/workflows](./.github/workflows/) directory.
@ -85,7 +109,8 @@ repositories with only a `Cargo.toml` file have limited benefits, as cargo will
_always_ use the most up-to-date dependency versions, which may not be cached.
Usage with Stable Rust is most effective, as a cache is tied to the Rust version.
Using it with Nightly Rust is less effective as it will throw away the cache every day.
Using it with Nightly Rust is less effective as it will throw away the cache every day,
unless a specific nightly build is being pinned.
## Cache Details
@ -101,6 +126,7 @@ This cache is automatically keyed by:
- the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and
- a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).
- a hash of all `rust-toolchain` / `rust-toolchain.toml` files in the root of the repository (if present).
- a hash of all `.cargo/config.toml` files in the root of the repository (if present).
An additional input `key` can be provided if the builtin keys are not sufficient.
@ -159,4 +185,7 @@ to see those details as well as further details related to caching operations.
## Known issues
- The cache cleaning process currently removes all the files from `~/.cargo/bin`
that were present before the action ran (for example `rustc`).
that were present before the action ran (for example `rustc`), by default.
This can be an issue on long-running self-hosted runners, where such state
is expected to be preserved across runs. You can work around this by setting
`cache-bin: "false"`.

View File

@ -1,4 +1,3 @@
- better .cargo/bin handling:
- get a list of all the files on "pre"/"restore"
- move the files out of the way on "post"/"save" and move them back afterwards
- properly clean sparse registry

View File

@ -32,15 +32,31 @@ inputs:
description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached."
required: false
default: "false"
cache-workspace-crates:
description: "Similar to cache-all-crates. If `true` the workspace crates will be cached."
required: false
default: "false"
save-if:
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
required: false
default: "true"
cache-provider:
description: "Determines which provider to use for caching. Options are github, buildjet, or warpbuild. Defaults to github."
required: false
default: "github"
cache-bin:
description: "Determines whether to cache ${CARGO_HOME}/bin."
required: false
default: "true"
lookup-only:
description: "Check if a cache entry exists without downloading the cache"
required: false
default: "false"
outputs:
cache-hit:
description: "A boolean value that indicates an exact match was found."
runs:
using: "node16"
using: "node20"
main: "dist/restore/index.js"
post: "dist/save/index.js"
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"

151214
dist/restore/index.js vendored

File diff suppressed because one or more lines are too long

151224
dist/save/index.js vendored

File diff suppressed because one or more lines are too long

1955
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"private": true,
"name": "rust-cache",
"version": "2.4.0",
"version": "2.8.0",
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
"keywords": [
"actions",
@ -22,16 +22,20 @@
},
"homepage": "https://github.com/Swatinem/rust-cache#readme",
"dependencies": {
"@actions/cache": "^3.2.1",
"@actions/core": "^1.10.0",
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
"@actions/cache": "^4.0.5",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.4.0",
"@actions/io": "^1.1.3"
"@actions/glob": "^0.5.0",
"@actions/io": "^1.1.3",
"smol-toml": "^1.4.2"
},
"devDependencies": {
"@vercel/ncc": "^0.36.1",
"@types/node": "^22.16.0",
"@vercel/ncc": "^0.38.3",
"linefix": "^0.1.1",
"typescript": "5.0.4"
"typescript": "5.8.3"
},
"scripts": {
"prepare": "ncc build --target es2020 -o dist/restore src/restore.ts && ncc build --target es2020 -o dist/save src/save.ts && linefix dist"

View File

@ -4,6 +4,7 @@ import fs from "fs";
import path from "path";
import { CARGO_HOME } from "./config";
import { exists } from "./utils";
import { Packages } from "./workspace";
export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
@ -34,6 +35,26 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec
async function cleanProfileTarget(profileDir: string, packages: Packages, checkTimestamp = false) {
core.debug(`cleaning profile directory "${profileDir}"`);
// Quite a few testing utility crates store compilation artifacts as nested
// workspaces under `target/tests`. Notably, `target/tests/target` and
// `target/tests/trybuild`.
if (path.basename(profileDir) === "tests") {
try {
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
} catch {}
try {
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
} catch {}
// Delete everything else.
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
return;
}
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
await rmExcept(profileDir, keepProfile);
@ -91,11 +112,15 @@ export async function cleanBin(oldBins: Array<string>) {
}
export async function cleanRegistry(packages: Packages, crates = true) {
// `.cargo/registry/src`
// we can remove this completely, as cargo will recreate this from `cache`
await rmRF(path.join(CARGO_HOME, "registry", "src"));
// remove `.cargo/credentials.toml`
try {
const credentials = path.join(CARGO_HOME, ".cargo", "credentials.toml");
core.debug(`deleting "${credentials}"`);
await fs.promises.unlink(credentials);
} catch {}
// `.cargo/registry/index`
let pkgSet = new Set(packages.map((p) => p.name));
const indexDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "index"));
for await (const dirent of indexDir) {
if (dirent.isDirectory()) {
@ -106,19 +131,38 @@ export async function cleanRegistry(packages: Packages, crates = true) {
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
if (await exists(path.join(dirPath, ".git"))) {
await rmRF(path.join(dirPath, ".cache"));
} else {
await cleanRegistryIndexCache(dirPath, pkgSet);
}
// TODO: else, clean `.cache` based on the `packages`
}
}
if (!crates) {
core.debug(`skipping crate cleanup`);
core.debug("skipping registry cache and src cleanup");
return;
}
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
// `.cargo/registry/src`
// Cargo usually re-creates these from the `.crate` cache below,
// but for some reason that does not work for `-sys` crates that check timestamps
// to decide if rebuilds are necessary.
pkgSet = new Set(packages.filter((p) => p.name.endsWith("-sys")).map((p) => `${p.name}-${p.version}`));
const srcDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "src"));
for await (const dirent of srcDir) {
if (dirent.isDirectory()) {
// eg `.cargo/registry/src/github.com-1ecc6299db9ec823`
// or `.cargo/registry/src/index.crates.io-e139d0d48fed7772`
const dir = await fs.promises.opendir(path.join(srcDir.path, dirent.name));
for await (const dirent of dir) {
if (dirent.isDirectory() && !pkgSet.has(dirent.name)) {
await rmRF(path.join(dir.path, dirent.name));
}
}
}
}
// `.cargo/registry/cache`
pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));
for await (const dirent of cacheDir) {
if (dirent.isDirectory()) {
@ -135,6 +179,28 @@ export async function cleanRegistry(packages: Packages, crates = true) {
}
}
/// Recursively walks and cleans the index `.cache`
async function cleanRegistryIndexCache(dirName: string, keepPkg: Set<string>) {
let dirIsEmpty = true;
const cacheDir = await fs.promises.opendir(dirName);
for await (const dirent of cacheDir) {
if (dirent.isDirectory()) {
if (await cleanRegistryIndexCache(path.join(dirName, dirent.name), keepPkg)) {
await rm(dirName, dirent);
} else {
dirIsEmpty &&= false;
}
} else {
if (keepPkg.has(dirent.name)) {
dirIsEmpty &&= false;
} else {
await rm(dirName, dirent);
}
}
}
return dirIsEmpty;
}
export async function cleanGit(packages: Packages) {
const coPath = path.join(CARGO_HOME, "git", "checkouts");
const dbPath = path.join(CARGO_HOME, "git", "db");
@ -243,12 +309,3 @@ async function rmRF(dirName: string) {
core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName);
}
async function exists(path: string) {
try {
await fs.promises.access(path);
return true;
} catch {
return false;
}
}

View File

@ -2,12 +2,14 @@ import * as core from "@actions/core";
import * as glob from "@actions/glob";
import crypto from "crypto";
import fs from "fs";
import fs_promises from "fs/promises";
import os from "os";
import path from "path";
import * as toml from "smol-toml";
import { getCmdOutput } from "./utils";
import { Workspace } from "./workspace";
import { getCargoBins } from "./cleanup";
import { CacheProvider, exists, getCmdOutput } from "./utils";
import { Workspace } from "./workspace";
const HOME = os.homedir();
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
@ -23,6 +25,9 @@ export class CacheConfig {
/** The secondary (restore) key that only contains the prefix and environment */
public restoreKey = "";
/** Whether to cache CARGO_HOME/.bin */
public cacheBin: boolean = true;
/** The workspace configurations */
public workspaces: Array<Workspace> = [];
@ -69,6 +74,11 @@ export class CacheConfig {
}
}
// Add runner OS and CPU architecture to the key to avoid cross-contamination of cache
const runnerOS = os.type();
const runnerArch = os.arch();
key += `-${runnerOS}-${runnerArch}`;
self.keyPrefix = key;
// Construct environment portion of the key:
@ -114,6 +124,8 @@ export class CacheConfig {
// This considers all the files found via globbing for various manifests
// and lockfiles.
self.cacheBin = core.getInput("cache-bin").toLowerCase() == "true";
// Constructs the workspace config and paths to restore:
// The workspaces are given using a `$workspace -> $target` syntax.
@ -127,32 +139,122 @@ export class CacheConfig {
}
self.workspaces = workspaces;
let keyFiles = await globFiles("rust-toolchain\nrust-toolchain.toml");
let keyFiles = await globFiles(".cargo/config.toml\nrust-toolchain\nrust-toolchain.toml");
const parsedKeyFiles = []; // keyFiles that are parsed, pre-processed and hashed
hasher = crypto.createHash("sha1");
for (const workspace of workspaces) {
const root = workspace.root;
keyFiles.push(
...(await globFiles(
`${root}/**/Cargo.toml\n${root}/**/Cargo.lock\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
)),
);
}
keyFiles = keyFiles.filter(file => !fs.statSync(file).isDirectory());
keyFiles.sort((a, b) => a.localeCompare(b));
hasher = crypto.createHash("sha1");
const workspaceMembers = await workspace.getWorkspaceMembers();
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
for (const cargo_manifest of cargo_manifests) {
try {
const content = await fs_promises.readFile(cargo_manifest, { encoding: "utf8" });
// Use any since TomlPrimitive is not exposed
const parsed = toml.parse(content) as { [key: string]: any };
if ("package" in parsed) {
const pack = parsed.package;
if ("version" in pack) {
pack["version"] = "0.0.0";
}
}
for (const prefix of ["", "build-", "dev-"]) {
const section_name = `${prefix}dependencies`;
if (!(section_name in parsed)) {
continue;
}
const deps = parsed[section_name];
for (const key of Object.keys(deps)) {
const dep = deps[key];
try {
if ("path" in dep) {
dep.version = "0.0.0";
dep.path = "";
}
} catch (_e) {
// Not an object, probably a string (version),
// continue.
continue;
}
}
}
hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest);
} catch (e) {
// Fallback to caching them as regular file
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_manifest);
}
}
const cargo_lock = path.join(workspace.root, "Cargo.lock");
if (await exists(cargo_lock)) {
try {
const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" });
const parsed = toml.parse(content);
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
// Fallback to caching them as regular file since this action
// can only handle Cargo.lock format version 3
core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
keyFiles.push(cargo_lock);
continue;
}
// Package without `[[package]].source` and `[[package]].checksum`
// are the one with `path = "..."` to crates within the workspace.
const packages = (parsed.package as any[]).filter((p: any) => "source" in p || "checksum" in p);
hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock);
} catch (e) {
// Fallback to caching them as regular file
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_lock);
}
}
}
keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) {
for await (const chunk of fs.createReadStream(file)) {
hasher.update(chunk);
}
}
let lockHash = digest(hasher);
self.keyFiles = keyFiles;
keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles);
key += `-${lockHash}`;
self.cacheKey = key;
self.cachePaths = [CARGO_HOME];
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
if (self.cacheBin) {
self.cachePaths = [
path.join(CARGO_HOME, "bin"),
path.join(CARGO_HOME, ".crates.toml"),
path.join(CARGO_HOME, ".crates2.json"),
...self.cachePaths,
];
}
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
if (cacheTargets === "true") {
self.cachePaths.push(...workspaces.map((ws) => ws.target));
@ -185,8 +287,7 @@ export class CacheConfig {
const self = new CacheConfig();
Object.assign(self, JSON.parse(source));
self.workspaces = self.workspaces
.map((w: any) => new Workspace(w.root, w.target));
self.workspaces = self.workspaces.map((w: any) => new Workspace(w.root, w.target));
return self;
}
@ -194,8 +295,10 @@ export class CacheConfig {
/**
* Prints the configuration to the action log.
*/
printInfo() {
printInfo(cacheProvider: CacheProvider) {
core.startGroup("Cache Configuration");
core.info(`Cache Provider:`);
core.info(` ${cacheProvider.name}`);
core.info(`Workspaces:`);
for (const workspace of this.workspaces) {
core.info(` ${workspace.root}`);
@ -270,5 +373,25 @@ async function globFiles(pattern: string): Promise<string[]> {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
return await globber.glob();
// fs.statSync resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved
// file is actually a regular file.
return (await globber.glob()).filter((file) => fs.statSync(file).isFile());
}
function sort_and_uniq(a: string[]) {
return a
.sort((a, b) => a.localeCompare(b))
.reduce((accumulator: string[], currentValue: string) => {
const len = accumulator.length;
// If accumulator is empty or its last element != currentValue
// Since array is already sorted, elements with the same value
// are grouped together to be continugous in space.
//
// If currentValue != last element, then it must be unique.
if (len == 0 || accumulator[len - 1].localeCompare(currentValue) != 0) {
accumulator.push(currentValue);
}
return accumulator;
}, []);
}

View File

@ -1,8 +1,8 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { cleanTargetDir } from "./cleanup";
import { CacheConfig } from "./config";
import { getCacheProvider, reportError } from "./utils";
process.on("uncaughtException", (e) => {
core.error(e.message);
@ -12,7 +12,9 @@ process.on("uncaughtException", (e) => {
});
async function run() {
if (!cache.isFeatureAvailable()) {
const cacheProvider = getCacheProvider();
if (!cacheProvider.cache.isFeatureAvailable()) {
setCacheHitOutput(false);
return;
}
@ -22,22 +24,26 @@ async function run() {
if (cacheOnFailure !== "true") {
cacheOnFailure = "false";
}
var lookupOnly = core.getInput("lookup-only").toLowerCase() === "true";
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
core.exportVariable("CARGO_INCREMENTAL", 0);
const config = await CacheConfig.new();
config.printInfo();
config.printInfo(cacheProvider);
core.info("");
core.info(`... Restoring cache ...`);
core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
const key = config.cacheKey;
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed.
const restoreKey = await cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]);
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
lookupOnly,
});
if (restoreKey) {
const match = restoreKey === key;
core.info(`Restored from cache key "${restoreKey}" full match: ${match}.`);
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
if (!match) {
// pre-clean the target directory on cache mismatch
for (const workspace of config.workspaces) {
@ -60,8 +66,9 @@ async function run() {
} catch (e) {
setCacheHitOutput(false);
core.error(`${(e as any).stack}`);
reportError(e);
}
process.exit();
}
function setCacheHitOutput(cacheHit: boolean): void {

View File

@ -1,9 +1,9 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup";
import { CacheConfig, isCacheUpToDate } from "./config";
import { getCacheProvider, reportError } from "./utils";
process.on("uncaughtException", (e) => {
core.error(e.message);
@ -13,9 +13,11 @@ process.on("uncaughtException", (e) => {
});
async function run() {
const cacheProvider = getCacheProvider();
const save = core.getInput("save-if").toLowerCase() || "true";
if (!(cache.isFeatureAvailable() && save === "true")) {
if (!(cacheProvider.cache.isFeatureAvailable() && save === "true")) {
return;
}
@ -26,54 +28,64 @@ async function run() {
}
const config = CacheConfig.fromState();
config.printInfo();
config.printInfo(cacheProvider);
core.info("");
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
if (process.env["RUNNER_OS"] == "macOS") {
await macOsWorkaround();
}
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false";
const allPackages = [];
for (const workspace of config.workspaces) {
const packages = await workspace.getPackages();
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
if (workspaceCrates === "true") {
const wsMembers = await workspace.getWorkspaceMembers();
packages.push(...wsMembers);
}
allPackages.push(...packages);
try {
core.info(`... Cleaning ${workspace.target} ...`);
await cleanTargetDir(workspace.target, packages);
} catch (e) {
core.error(`${(e as any).stack}`);
core.debug(`${(e as any).stack}`);
}
}
try {
const crates = core.getInput("cache-all-crates").toLowerCase() || "false"
core.info(`... Cleaning cargo registry cache-all-crates: ${crates} ...`);
const crates = core.getInput("cache-all-crates").toLowerCase() || "false";
core.info(`... Cleaning cargo registry (cache-all-crates: ${crates}) ...`);
await cleanRegistry(allPackages, crates !== "true");
} catch (e) {
core.error(`${(e as any).stack}`);
core.debug(`${(e as any).stack}`);
}
if (config.cacheBin) {
try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin(config.cargoBins);
} catch (e) {
core.error(`${(e as any).stack}`);
core.debug(`${(e as any).stack}`);
}
}
try {
core.info(`... Cleaning cargo git cache ...`);
await cleanGit(allPackages);
} catch (e) {
core.error(`${(e as any).stack}`);
core.debug(`${(e as any).stack}`);
}
core.info(`... Saving cache ...`);
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed.
await cache.saveCache(config.cachePaths.slice(), config.cacheKey);
await cacheProvider.cache.saveCache(config.cachePaths.slice(), config.cacheKey);
} catch (e) {
core.error(`${(e as any).stack}`);
reportError(e);
}
process.exit();
}
run();

View File

@ -1,5 +1,19 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as buildjetCache from "@actions/buildjet-cache";
import * as warpbuildCache from "@actions/warpbuild-cache";
import * as ghCache from "@actions/cache";
import fs from "fs";
export function reportError(e: any) {
const { commandFailed } = e;
if (commandFailed) {
core.error(`Command failed: ${commandFailed.command}`);
core.error(commandFailed.stderr);
} else {
core.error(`${e.stack}`);
}
}
export async function getCmdOutput(
cmd: string,
@ -22,9 +36,54 @@ export async function getCmdOutput(
...options,
});
} catch (e) {
core.error(`Command failed: ${cmd} ${args.join(" ")}`);
core.error(stderr);
(e as any).commandFailed = {
command: `${cmd} ${args.join(" ")}`,
stderr,
};
throw e;
}
return stdout;
}
export interface GhCache {
isFeatureAvailable: typeof ghCache.isFeatureAvailable;
restoreCache: typeof ghCache.restoreCache;
saveCache: (paths: string[], key: string) => Promise<string | number>;
}
export interface CacheProvider {
name: string;
cache: GhCache;
}
export function getCacheProvider(): CacheProvider {
const cacheProvider = core.getInput("cache-provider");
let cache: GhCache;
switch (cacheProvider) {
case "github":
cache = ghCache;
break;
case "buildjet":
cache = buildjetCache;
break;
case "warpbuild":
cache = warpbuildCache;
break;
default:
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
}
return {
name: cacheProvider,
cache: cache,
};
}
export async function exists(path: string) {
try {
await fs.promises.access(path);
return true;
} catch {
return false;
}
}

View File

@ -8,26 +8,34 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
export class Workspace {
constructor(public root: string, public target: string) {}
public async getPackages(): Promise<Packages> {
async getPackages(filter: (p: Meta["packages"][0]) => boolean, ...extraArgs: string[]): Promise<Packages> {
let packages: Packages = [];
try {
core.debug(`collecting metadata for "${this.root}"`);
const meta: Meta = JSON.parse(
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], {
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
cwd: this.root,
env: { "CARGO_ENCODED_RUSTFLAGS": "" },
}),
);
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
for (const pkg of meta.packages) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
for (const pkg of meta.packages.filter(filter)) {
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) });
}
} catch {}
} catch (err) {
console.error(err);
}
return packages;
}
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
}
public async getWorkspaceMembers(): Promise<Packages> {
return await this.getPackages((_) => true, "--no-deps");
}
}
export interface PackageDefinition {

1419
tests/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,5 +6,12 @@ authors = ["Arpad Borsos <arpad.borsos@googlemail.com>"]
edition = "2021"
[dependencies]
reqwest = "0.11.11"
watto = { git = "https://github.com/getsentry/watto", rev = "d71c8218506bddba102a124a460d64da25e303dc", features = ["strings"] }
reqwest = "0.12.1"
jsonpath_lib_polars_vendor = "0.0.1"
watto = { git = "https://github.com/getsentry/watto", rev = "39ccb9add289c1f23c89f40506f4a80b2f4011b9", features = ["strings"] }
[dev-dependencies]
trybuild = "1"
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.6.0"

View File

@ -0,0 +1,2 @@
the `rust-toolchain` directory will be globbed,
and should not lead to any errors down the road

View File

@ -1,3 +1,10 @@
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
fn main() {
println!("Hello, world!");
}

6
tests/tests/trybuild.rs Normal file
View File

@ -0,0 +1,6 @@
#[test]
fn test_trybuild() {
let t = trybuild::TestCases::new();
t.pass("tests/trybuild/empty_main.rs");
t.compile_fail("tests/trybuild/fail_to_compile.rs");
}

View File

@ -0,0 +1 @@
fn main() {}

View File

@ -0,0 +1,3 @@
fn main() {
"foobar".foobar();
}

View File

@ -0,0 +1,5 @@
error[E0599]: no method named `foobar` found for reference `&'static str` in the current scope
--> tests/trybuild/fail_to_compile.rs:2:14
|
2 | "foobar".foobar();
| ^^^^^^ method not found in `&'static str`

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"crates/one",
"crates/two",

View File

@ -5,7 +5,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
reqwest = "0.11.0"
reqwest = "0.12"
async-std = "1"
tracing = "0.1"
tracing-futures = "0.2"

View File

@ -5,4 +5,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
clap = "3"
clap = "4"