Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ - Cache compatibility #122

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
x86_64-apple-darwin \
x86_64-pc-windows-gnu
- name: Install cargo zigbuild
run: cargo install cargo-zigbuild
run: cargo install --locked cargo-zigbuild
- name: macOS - build universal2
run: cargo zigbuild --target universal2-apple-darwin --release
- name: Linux - build x86_64 musl
Expand Down
17 changes: 17 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use console::style;
use indicatif::{ProgressBar, ProgressStyle};
use serde::Serialize;
use std::fmt;
use std::fs::File;
use std::io::{stdout, Write};
use std::path::PathBuf;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -414,6 +415,20 @@ impl fmt::Display for BuildError {
}
}

pub fn write_build_ninja(build_state: &BuildState) {
// write build.ninja files in the packages after a non-incremental build
// this is necessary to bust the editor tooling cache. The editor tooling
// is watching this file.
// we don't need to do this in an incremental build because there are no file
// changes (deletes / additions)
for package in build_state.packages.values() {
// write empty file:
let mut f = File::create(std::path::Path::new(&package.get_bs_build_path()).join("build.ninja"))
.expect("Unable to write file");
f.write_all(b"").expect("unable to write to ninja file");
}
}

pub fn build(
filter: &Option<regex::Regex>,
path: &str,
Expand All @@ -440,10 +455,12 @@ pub fn build(
default_timing.unwrap_or(timing_total_elapsed).as_secs_f64()
);
clean::cleanup_after_build(&build_state);
write_build_ninja(&build_state);
Ok(build_state)
}
Err(e) => {
clean::cleanup_after_build(&build_state);
write_build_ninja(&build_state);
Err(BuildError::IncrementalBuild(e))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ fn compile_file(
// because editor tooling doesn't support namespace entries yet
// we just remove the @ for now. This makes sure the editor support
// doesn't break
.join(module_name.to_owned().replace('@', "") + ".cmi"),
.join(module_name.to_owned() + ".cmi"),
);
let _ = std::fs::copy(
build_path_abs.to_string() + "/" + &module_name + ".cmj",
Expand All @@ -590,7 +590,7 @@ fn compile_file(
// because editor tooling doesn't support namespace entries yet
// we just remove the @ for now. This makes sure the editor support
// doesn't break
.join(module_name.to_owned().replace('@', "") + ".cmt"),
.join(module_name.to_owned() + ".cmt"),
);
} else {
let _ = std::fs::copy(
Expand Down
2 changes: 1 addition & 1 deletion src/build/namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn gen_mlmap(
let path = build_path_abs.to_string() + "/" + namespace + ".mlmap";
let mut file = File::create(&path).expect("Unable to create mlmap");

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

let mut modules = Vec::from_iter(depending_modules.to_owned());
Expand Down
3 changes: 3 additions & 0 deletions src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ async fn async_watch(
if let Some(a) = after_build.clone() {
cmd::run(a)
}

build::write_build_ninja(&build_state);

let timing_total_elapsed = timing_total.elapsed();
println!(
"\n{}{}Finished compilation in {:.2}s\n",
Expand Down
Loading