Skip to content

Commit b4c1641

Browse files
committedOct 6, 2024
Fix slow build.rs / rust analyzer #913
1 parent ce31095 commit b4c1641

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed
 

‎.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
// This is used to prevent `build.rs` from running every time you make a change to a file.
3+
"rust-analyzer.check.extraEnv": {
4+
"IS_RUST_ANALYZER": "true"
5+
},
26
// The linter in the CI is quite strict, so running `cargo fmt` on save is probably a good idea!
37
"editor.formatOnSave": true,
48
"files.autoSave": "onFocusChange",

‎server/build.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,13 @@ fn main() -> std::io::Result<()> {
2121
// Uncomment this line if you want faster builds during development
2222
// return Ok(());
2323
const BROWSER_ROOT: &str = "../browser/";
24-
let dirs: Dirs = {
25-
Dirs {
26-
js_dist_source: PathBuf::from("../browser/data-browser/dist"),
27-
js_dist_tmp: PathBuf::from("./assets_tmp"),
28-
src_browser: PathBuf::from("../browser/data-browser/src"),
29-
browser_root: PathBuf::from(BROWSER_ROOT),
30-
}
31-
};
32-
println!("cargo:rerun-if-changed={}", BROWSER_ROOT);
33-
// Check if we're likely running in a check-like context
34-
let opt_level = std::env::var("OPT_LEVEL").unwrap_or_else(|_| "0".to_string());
35-
let profile = std::env::var("PROFILE").unwrap_or_else(|_| "release".to_string());
36-
37-
let is_check_like = profile == "debug" && opt_level == "0";
24+
// Env is set in .vscode/settings.json when rust-analyzer runs
25+
let is_rust_analyzer = !std::env::var("IS_RUST_ANALYZER")
26+
.unwrap_or_default()
27+
.is_empty();
3828

39-
if is_check_like {
40-
println!("cargo:rerun-if-changed=build.rs");
41-
// Skip the heavy logic
42-
println!("Skipping build.rs logic for cargo check/clippy.");
29+
if is_rust_analyzer {
30+
p!("Skipping build.rs logic to keep rust-analyzer fast. If you see this message in some other context: the JS build not run!");
4331
} else {
4432
const BROWSER_ROOT: &str = "../browser/";
4533
println!("cargo:rerun-if-changed={}", BROWSER_ROOT);

0 commit comments

Comments
 (0)
Please sign in to comment.