Skip to content

Commit 4891406

Browse files
authored
feat: add rspack_tools to compare .cache from different os (#12499)
* feat: rspack storage add scopes method * feat: pub persistent cache mod * feat: add rspack_kit compare command * feat: add ci * fix: ci * fix: typo * fix: comment
1 parent 9c26ab0 commit 4891406

File tree

30 files changed

+1004
-45
lines changed

30 files changed

+1004
-45
lines changed

.github/actions/artifact/upload/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
description: "Force upload to github"
1414
default: false
1515
require: false
16+
include-hidden-files:
17+
description: "Allow upload hidden files"
18+
default: false
19+
require: false
1620

1721
runs:
1822
using: composite
@@ -23,6 +27,7 @@ runs:
2327
with:
2428
name: ${{ inputs.name }}
2529
path: ${{ inputs.path }}
30+
include-hidden-files: ${{ inputs.include-hidden-files }}
2631
if-no-files-found: error
2732
overwrite: true
2833

@@ -31,5 +36,6 @@ runs:
3136
with:
3237
name: ${{ inputs.name }}
3338
path: ${{ inputs.path }}
39+
include-hidden-files: ${{ inputs.include-hidden-files }}
3440
if-no-files-found: error
3541
overwrite: true

.github/workflows/ci.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,36 @@ jobs:
116116
if: ${{ github.event_name == 'pull_request' }}
117117
run: bash .github/actions/codspeed/check-comment.sh
118118

119+
check-cache:
120+
name: Check Cache Portable
121+
needs: [test-linux, test-windows]
122+
runs-on: ${{ fromJSON(vars.LINUX_SELF_HOSTED_RUNNER_LABELS || '"ubuntu-22.04"') }}
123+
steps:
124+
- name: Checkout
125+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
126+
- name: Install Rust Toolchain
127+
uses: ./.github/actions/rustup
128+
with:
129+
key: test_cache
130+
save-if: true
131+
- name: Download linux cache
132+
uses: ./.github/actions/artifact/download
133+
with:
134+
name: testCase-persistentCache-linux
135+
path: ./cache-linux
136+
force-use-github: true
137+
- name: Download windows cache
138+
uses: ./.github/actions/artifact/download
139+
with:
140+
name: testCase-persistentCache-windows
141+
path: ./cache-windows
142+
force-use-github: true
143+
- name: Run compare kit
144+
run: |
145+
echo "success"
146+
# TODO open it after rspack portable cache implementation
147+
# cargo run -p rspack_tools -- compare ./cache-linux ./cache-windows
148+
119149
test_required_check:
120150
# this job will be used for GitHub actions to determine required job success or not;
121151
# When code changed, it will check if any of the test jobs failed.
@@ -129,7 +159,8 @@ jobs:
129159
test-mac,
130160
test-wasm,
131161
check-changed,
132-
size-limit
162+
size-limit,
163+
check-cache
133164
]
134165
if: ${{ always() && !cancelled() }}
135166
runs-on: ubuntu-latest
@@ -139,13 +170,13 @@ jobs:
139170
- name: Test check
140171
if: ${{ needs.check-changed.outputs.code_changed == 'true'
141172
&& github.event_name == 'pull_request'
142-
&& join(needs.*.result, ',')!='success,success,success,success,success,success,success' }}
173+
&& join(needs.*.result, ',')!='success,success,success,success,success,success,success,success' }}
143174
run: echo "Tess Failed" && exit 1
144175

145176
- name: Test check
146177
if: ${{ needs.check-changed.outputs.code_changed == 'true'
147178
&& github.event_name != 'pull_request'
148-
&& join(needs.*.result, ',')!='success,success,success,success,success,success,skipped' }}
179+
&& join(needs.*.result, ',')!='success,success,success,success,success,success,skipped,success' }}
149180
run: echo "Tess Failed" && exit 1
150181

151182
- name: No check to Run test

.github/workflows/reusable-build-test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ jobs:
113113
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }}
114114
run: pnpm run test:ci
115115

116+
- name: Upload linux test cache
117+
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' && matrix.node == '22' }}
118+
uses: ./.github/actions/artifact/upload
119+
with:
120+
name: testCase-persistentCache-linux
121+
path: tests/rspack-test/js/temp/**/.cache
122+
force-use-github: true
123+
include-hidden-files: true
124+
116125
### *-apple-darwin
117126
- name: Test apple-darwin
118127
timeout-minutes: 20 # Tests should finish within 15 mins, please fix your tests instead of changing this to a higher timeout.
@@ -133,6 +142,15 @@ jobs:
133142
if: ${{ inputs.target == 'x86_64-pc-windows-msvc' }}
134143
run: pnpm run test:ci
135144

145+
- name: Upload windows test cache
146+
if: ${{ inputs.target == 'x86_64-pc-windows-msvc' && matrix.node == '22' }}
147+
uses: ./.github/actions/artifact/upload
148+
with:
149+
name: testCase-persistentCache-windows
150+
path: tests/rspack-test/js/temp/**/.cache
151+
force-use-github: true
152+
include-hidden-files: true
153+
136154
### WASM
137155
- name: Test WASM
138156
timeout-minutes: 15 # Tests should finish within 15 mins, please fix your tests instead of changing this to a higher timeout.

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rspack_core/src/cache/persistent/build_dependencies/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{
1313
storage::Storage,
1414
};
1515

16-
const SCOPE: &str = "build_dependencies";
16+
pub const SCOPE: &str = "build_dependencies";
1717

1818
pub type BuildDepsOptions = Vec<PathBuf>;
1919

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,2 @@
1-
use std::{any::Any, sync::Arc};
2-
3-
use rspack_cacheable::{DeserializeError, SerializeError, cacheable, with::AsConverter};
4-
use rspack_fs::ReadableFileSystem;
5-
6-
use crate::CompilerOptions;
7-
81
#[derive(Debug)]
9-
pub struct CacheableContext {
10-
pub options: Arc<CompilerOptions>,
11-
pub input_filesystem: Arc<dyn ReadableFileSystem>,
12-
}
13-
14-
#[cacheable]
15-
pub struct FromContext;
16-
17-
impl AsConverter<Arc<CompilerOptions>> for FromContext {
18-
fn serialize(_data: &Arc<CompilerOptions>, _ctx: &dyn Any) -> Result<Self, SerializeError> {
19-
Ok(FromContext)
20-
}
21-
fn deserialize(self, ctx: &dyn Any) -> Result<Arc<CompilerOptions>, DeserializeError> {
22-
let Some(ctx) = ctx.downcast_ref::<CacheableContext>() else {
23-
return Err(DeserializeError::NoContext);
24-
};
25-
Ok(ctx.options.clone())
26-
}
27-
}
2+
pub struct CacheableContext;

crates/rspack_core/src/cache/persistent/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
mod build_dependencies;
1+
pub mod build_dependencies;
22
mod cacheable_context;
3-
mod occasion;
3+
pub mod occasion;
44
pub mod snapshot;
55
pub mod storage;
66

@@ -9,7 +9,7 @@ use std::{
99
sync::Arc,
1010
};
1111

12-
pub use cacheable_context::{CacheableContext, FromContext};
12+
pub use cacheable_context::CacheableContext;
1313
use rspack_fs::{IntermediateFileSystem, ReadableFileSystem};
1414
use rspack_paths::ArcPathSet;
1515
use rspack_workspace::rspack_pkg_version;
@@ -67,10 +67,7 @@ impl PersistentCache {
6767
hex::encode(hasher.finish().to_ne_bytes())
6868
};
6969
let storage = create_storage(option.storage.clone(), version, intermediate_filesystem);
70-
let context = Arc::new(CacheableContext {
71-
options: compiler_options,
72-
input_filesystem: input_filesystem.clone(),
73-
});
70+
let context = Arc::new(CacheableContext);
7471
let make_occasion = MakeOccasion::new(storage.clone(), context);
7572
let meta_occasion = MetaOccasion::new(storage.clone());
7673
Self {

crates/rspack_core/src/cache/persistent/occasion/make/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod module_graph;
33

44
use std::sync::Arc;
55

6+
pub use module_graph::SCOPE;
67
use rspack_collections::IdentifierSet;
78
use rspack_error::Result;
89
use rustc_hash::FxHashSet;

crates/rspack_core/src/cache/persistent/occasion/make/module_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
compilation::build_module_graph::{LazyDependencies, ModuleToLazyMake},
1919
};
2020

21-
const SCOPE: &str = "occasion_make_module_graph";
21+
pub const SCOPE: &str = "occasion_make_module_graph";
2222

2323
/// The value struct of current storage scope
2424
#[cacheable]

crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rspack_tasks::{get_current_dependency_id, set_current_dependency_id};
66

77
use super::super::Storage;
88

9-
const SCOPE: &str = "meta";
9+
pub const SCOPE: &str = "meta";
1010

1111
/// The meta data.
1212
#[cacheable]

0 commit comments

Comments
 (0)