Skip to content

Commit bf6de81

Browse files
authored
✨ - Cache compatibility (#122)
1 parent f74c893 commit bf6de81

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
x86_64-apple-darwin \
4242
x86_64-pc-windows-gnu
4343
- name: Install cargo zigbuild
44-
run: cargo install cargo-zigbuild
44+
run: cargo install --locked cargo-zigbuild
4545
- name: macOS - build universal2
4646
run: cargo zigbuild --target universal2-apple-darwin --release
4747
- name: Linux - build x86_64 musl

src/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use console::style;
1818
use indicatif::{ProgressBar, ProgressStyle};
1919
use serde::Serialize;
2020
use std::fmt;
21+
use std::fs::File;
2122
use std::io::{stdout, Write};
2223
use std::path::PathBuf;
2324
use std::time::{Duration, Instant};
@@ -414,6 +415,20 @@ impl fmt::Display for BuildError {
414415
}
415416
}
416417

418+
pub fn write_build_ninja(build_state: &BuildState) {
419+
// write build.ninja files in the packages after a non-incremental build
420+
// this is necessary to bust the editor tooling cache. The editor tooling
421+
// is watching this file.
422+
// we don't need to do this in an incremental build because there are no file
423+
// changes (deletes / additions)
424+
for package in build_state.packages.values() {
425+
// write empty file:
426+
let mut f = File::create(std::path::Path::new(&package.get_bs_build_path()).join("build.ninja"))
427+
.expect("Unable to write file");
428+
f.write_all(b"").expect("unable to write to ninja file");
429+
}
430+
}
431+
417432
pub fn build(
418433
filter: &Option<regex::Regex>,
419434
path: &str,
@@ -440,10 +455,12 @@ pub fn build(
440455
default_timing.unwrap_or(timing_total_elapsed).as_secs_f64()
441456
);
442457
clean::cleanup_after_build(&build_state);
458+
write_build_ninja(&build_state);
443459
Ok(build_state)
444460
}
445461
Err(e) => {
446462
clean::cleanup_after_build(&build_state);
463+
write_build_ninja(&build_state);
447464
Err(BuildError::IncrementalBuild(e))
448465
}
449466
}

src/build/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ fn compile_file(
575575
// because editor tooling doesn't support namespace entries yet
576576
// we just remove the @ for now. This makes sure the editor support
577577
// doesn't break
578-
.join(module_name.to_owned().replace('@', "") + ".cmi"),
578+
.join(module_name.to_owned() + ".cmi"),
579579
);
580580
let _ = std::fs::copy(
581581
build_path_abs.to_string() + "/" + &module_name + ".cmj",
@@ -590,7 +590,7 @@ fn compile_file(
590590
// because editor tooling doesn't support namespace entries yet
591591
// we just remove the @ for now. This makes sure the editor support
592592
// doesn't break
593-
.join(module_name.to_owned().replace('@', "") + ".cmt"),
593+
.join(module_name.to_owned() + ".cmt"),
594594
);
595595
} else {
596596
let _ = std::fs::copy(

src/build/namespaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn gen_mlmap(
3232
let path = build_path_abs.to_string() + "/" + namespace + ".mlmap";
3333
let mut file = File::create(&path).expect("Unable to create mlmap");
3434

35-
file.write_all(b"randjbuildsystem\n" as &[u8])
35+
file.write_all(b"randjbuildsystem\n")
3636
.expect("Unable to write mlmap");
3737

3838
let mut modules = Vec::from_iter(depending_modules.to_owned());

src/watcher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ async fn async_watch(
212212
if let Some(a) = after_build.clone() {
213213
cmd::run(a)
214214
}
215+
216+
build::write_build_ninja(&build_state);
217+
215218
let timing_total_elapsed = timing_total.elapsed();
216219
println!(
217220
"\n{}{}Finished compilation in {:.2}s\n",

0 commit comments

Comments
 (0)