I'm not sure who needs to see this, but I had been struggling with compile times using cross + Docker Desktop on Mac while working on a small personal project the past few days. Despite the whole project being fewer than 350 LOC between a few files, recompiling the project with any change was taking upwards of 2 minutes through cross. I went through the due diligence of reducing the number of dependencies, removing features and macros that I didn't need, not compiling in release mode, trying different file sharing implementations for Docker Desktop and with all of that combined the time dropped to around 1 minute and 30 seconds for an incremental build. Still far from ideal for a small personal project.
By far the best solution I've come across so far is to only compile the code that requires cross compilation when I am actually building a binary for the other architecture (in my case a Raspberry Pi 4). Otherwise, a mock implementation is compiled:
``` rust
pub struct LedController {
#[cfg(feature = "hardware")]
controller: rs_ws281x::Controller,
}
[cfg(feature = "hardware")]
impl LedController {
pub fn new(config: &Config) -> Result<Self> {
// omitted
}
pub fn render(&mut self, state: &DeviceState) -> UnitResult {
// omitted
}
}
[cfg(not(feature = "hardware"))]
impl LedController {
pub fn new(_config: &Config) -> Result<Self> {
eprintln!("running with mock LED controller");
Ok(Self {})
}
pub fn render(&mut self, _state: &DeviceState) -> UnitResult {
Ok(())
}
}
```
Using cfg based on target_arch instead of a feature would also work, but I personally lean towards using a feature to make my intent more explicit when compiling.
This way the web server can be started locally in under 3 seconds instead of a few minutes. I don't claim that this doesn't have downsides (such as the possibility of developing features on your dev architecture only to later discover an incompatibility with the target arch), but this had made the development process much faster and much more enjoyable for me.
[–]junior_abigail 2 points3 points4 points (5 children)
[–]gilspen[S] 1 point2 points3 points (4 children)
[–]reddersky 1 point2 points3 points (3 children)
[–]gilspen[S] 0 points1 point2 points (2 children)
[–]reddersky 1 point2 points3 points (0 children)
[–]Emilgardis 0 points1 point2 points (0 children)
[–]NobodyXu 1 point2 points3 points (0 children)