Description
Versions
Sublime Text 3 (Build 3125)
Rust Enhanced 1.2.5
macOS 10.12.1
rustc 1.17.0-nightly (a559452b0 2017-03-17)
Problematic behavior
When using a build script and editing code with Sublime + sublime-rust, every time you save a file and then run cargo run
, every dependency of your project is rebuilt.
If you turn off sublime-rust or edit in a different editor or such, this does not happen.
If after building with cargo you save your target folder somewhere else, wait until sublime-rust finishes it checks, and then restore it you can also avoid the problem. My guess is that sublime-rust isn't using the same version of rustc as me or is compiling with different settings, clobbering the saved output in the target folder. I'm not sure what the build script has to do with it.
I'm also seeing this a lot: Blocking waiting for file lock on build directory
, I assume due to sublime-rust recompiling in the background, and taking a long time cause it's recompiling all the deps as well.
Steps to reproduce
- Create a project with the following files. This is a pretty normal pattern for code generation, I basically copied it from the cargo docs.
src/main.rs
extern crate ctrlc; // Doesn't matter what the dependency is since we aren't gonna use it, we just want /something/ so we can see it get rebuilt unnecessarily
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
build.rs
extern crate itertools; // unused, just so we can see if it's rebuilt
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("generated.rs");
let mut f = File::create(&dest_path).unwrap();
write!(&mut f, "fn main() {{ println!(\"Hello, World!\"); }}").unwrap();
}
Cargo.toml
[package]
name = "TestProj"
version = "0.1.0"
authors = ["Mason Remaley <redacted>"]
[dependencies]
ctrlc = "3.0.1"
[build-dependencies]
itertools = "0.5.9"
- Build the project from the console (not via sublime-rust) via
cargo build
- Add a comment to
main.rs
using Sublime with sublime-rust installed and the feature that shows errors inline in Sublime turned on - Build the project again the same way, and see that ctrl-c (or whichever dependency you've added) gets rebuilt.
- Now save the target folder somewhere else on your machine
- Add another comment to
main.rs
- Wait for sublime-rust to finish building
- Delete the resulting target folder, and then move the original one back
- Do
cargo run
and observer hat it does /not/ rebuild all of the dependencies this time.
Let me know if you have any trouble reproducing/want any further help debugging.