diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 855c4ad..dda94b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/src/build.rs b/src/build.rs index b8b6342..aece691 100644 --- a/src/build.rs +++ b/src/build.rs @@ -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}; @@ -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, path: &str, @@ -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)) } } diff --git a/src/build/compile.rs b/src/build/compile.rs index ea3ac59..ea52e6a 100644 --- a/src/build/compile.rs +++ b/src/build/compile.rs @@ -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", @@ -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( diff --git a/src/build/namespaces.rs b/src/build/namespaces.rs index 394b582..39b943d 100644 --- a/src/build/namespaces.rs +++ b/src/build/namespaces.rs @@ -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()); diff --git a/src/watcher.rs b/src/watcher.rs index 166d44c..74251e5 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -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",