I stumbled upon this from your wonderful blog post trying to link in Swift to my own project. It worked great, but my builds without a changed file were taking multiple seconds, which is weird. Digging into it, I found an issue in my build.rs.
This looks like it globs all .swift files but does not. It is looking for the literal file *.swift, which should never exist. Since the file doesn't exist, it caused the build.rs to rerun every single build.
The fix is to list each Swift file directly.
You could do this with a manual list, but I walk the directory and find the swift files instead. Here's my snippet:
for entry in std::fs::read_dir("src/swift/").unwrap() {
// I don't like using ".flatten()" to skip over Err results
#![allow(clippy::manual_flatten)]
if let Ok(e) = entry {
if e.file_type().unwrap().is_file() {
let p = e.path().canonicalize().unwrap();
println!("cargo:rerun-if-changed={}", p);
}
}
}
I include all files it finds, but you can filter them to restrict it just to .swift files.
The impact of this is pretty minor - an extra second or two to rebuild the crate if anything maybe changed. For clients of the crate, I wouldn't expect any impact. But when I used this for my own stuff, it really slows down iteration cycles (which I try to keep as tight as possible).
Gah, that's a pretty rookie mistake! Thanks for pointing this out! I got rid of Swift parts of this project, so it's pure Rust now, but I should probably go and update that blog post. Thanks again!
I stumbled upon this from your wonderful blog post trying to link in Swift to my own project. It worked great, but my builds without a changed file were taking multiple seconds, which is weird. Digging into it, I found an issue in my
build.rs
.In build.rs we have this line:
This looks like it globs all
.swift
files but does not. It is looking for the literal file*.swift
, which should never exist. Since the file doesn't exist, it caused thebuild.rs
to rerun every single build.The fix is to list each Swift file directly. You could do this with a manual list, but I walk the directory and find the swift files instead. Here's my snippet:
I include all files it finds, but you can filter them to restrict it just to
.swift
files.The impact of this is pretty minor - an extra second or two to rebuild the crate if anything maybe changed. For clients of the crate, I wouldn't expect any impact. But when I used this for my own stuff, it really slows down iteration cycles (which I try to keep as tight as possible).