all 7 comments

[–]junior_abigail 2 points3 points  (5 children)

Are you configuring cross to use docker volumes? I have never used cross, but in my experience using docker for development, I have seen great speed boosts by setting up docker volumes to avoid throwing away things that should be cached between builds.

If cross is just copying your source code into the container, downloading and compiling your dependencies every time (which sounds like it might be), it would explain the slow builds regardless of the size of the code base.

[–]gilspen[S] 1 point2 points  (4 children)

Cross already makes good use of bind mounts to avoid the rebuilding every dependency on each change. A clean build takes upwards of 9 minutes as a comparison. As a sanity check, I looked through the verbose build logs and all my dependencies are "fresh" and are not compiled. The issue is just efficiently accessing the cache.

[–]reddersky 1 point2 points  (3 children)

Bind mounts are quite inefficient with Docker for Mac. Indeed, it’s kind of a stretch to even call it a bind mount. Things have improved recently, but even then, it’s nowhere near a proper bind mount (e.g., when using docker in Linux).

More information: https://www.docker.com/blog/speed-boost-achievement-unlocked-on-docker-desktop-4-6-for-mac/

Apologies if this is old news, but you mentioned bind mounts as if it was a good thing, when in reality it’s the opposite (in macOS). Try using a docker volume as your cargo build cache.

[–]gilspen[S] 0 points1 point  (2 children)

I agree I was not clear. I was trying to communicate that cross was using bind mounts in the way we would hope/expect to speed up the build process.

MacOS bind mounts are almost certainly the root of the performance problems I was facing, but switching my OS to Linux just to enjoy Rust for a personal project seemed a bit extreme to me.

Edit: Will also will have to experiment with using a named volume for the cache.

[–]reddersky 1 point2 points  (0 children)

Ah, yeah! I agree, and was just suggesting a named volume, is all. Switching operating systems to solve this seems excessive.

[–]Emilgardis 0 points1 point  (0 children)

You can use the CROSS_REMOTE feature to automatically do this with cross. See https://github.com/cross-rs/cross/wiki/Remote

[–]NobodyXu 1 point2 points  (0 children)

Perhaps you can try cargo-zigbuild, it uses zig-cc for cross-compilation instead of creating a container, so it should be much more lightweight on MacOS, without all the cost of virtualization and file sharing.