let id = SourceId::for_path(&dst)?;
let mut src = PathSource::new(&dst, &id, ws.config());
let new_pkg = src.root_package()?;
+ let pkg_fingerprint = src.fingerprint(&new_pkg)?;
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;
ops::compile_ws(
Arc::new(DefaultExecutor),
)?;
+ // Check that build.rs didn't modify any files in the src directory.
+ let ws_fingerprint = src.fingerprint(ws.current()?)?;
+ if pkg_fingerprint != ws_fingerprint {
+ bail!(
+ "Source directory was modified by build.rs during cargo publish. \
+ Build scripts should not modify anything outside of OUT_DIR."
+ )
+ }
+
Ok(())
}