Are you on macOS? Would you like a faster incremental debug build? Nightly has the answer for you! The Cargo team is looking for feedback on new feature which you can opt-in with:
# inside of ~/.cargo/config.toml
[profile.dev]
split-debuginfo = 'unpacked'
[profile.test]
split-debuginfo = 'unpacked'
This can make your incremental debug builds up to seconds faster depending on the use case. This option is not turned on by default but we would like to turn it on by default in the future! The Cargo team, however, would like to take some time to evaluate this change. If you experience any breakage using this feature, please report it here or to the Cargo team.
Background
A historical pain point for macOS Rust users is that incremental debug builds can often be far worse than compared to other platforms. The reason for this is that when debuginfo is enabled (as it is by default for cargo build
) then rustc
will automatically execute the dsymutil
command line tool on the final executable. The purpose of dsymutil
is to "link" debuginfo together. This works over your entire executable and creates a separate *.dSYM
folder next to the binary itself, and this .dSYM
folder contains all the DWARF debug info you'll need for the binary.
The dsymutil
tool, however, is not incremental. This means that it can take quite a long time to run, especially over larger projects that have more and more debug information. If you're not using debuginfo or all you're using it for is filenames and line numbers in backtraces, this is often a hefty cost to pay! I've personally measured locally that of a ~10s incremental build time locally on macOS for Cargo itself ~7s are spent purely in dsymutil
. That means 70% of my incremental build time was doing something that I rarely use!
Another downside of running dsymutil
is that debuginfo takes up quite a lot of space on disk. By "linking" debug information you end up with two copies, one in *.rlib
and *.o
files and one in the *.dSYM
folders. Debug information can sometimes approach the size of gigabytes so this can be a lot of space wasted.
Recently the -C split-debuginfo
option was stabilized for macOS targets. This has been exposed in Cargo as well now through the split-debuginfo
profile option. The defaults for all compilations have not changed at this time.
The Cargo team would like to change the default split-debuginfo
setting for macOS to unpacked
by default (it's currently packed
). This might be a breaking change for some workflows, however, so that's where you come in!
- Does changing to
unpacked
break your build? - Does it speed up your build? If so, by how much?
- Does this make your
target
directory smaller? If so by how much? - Do you have external tooling relying on
*.dSYM
files existing? - Do you use any tooling locally that requires
*.dSYM
to exist? (e.g. does your local debugger/tooling support theunpacked
format of the object files)
In the future when -Csplit-debuginfo
is stabilized for other Unix platforms (those using ELF binaries, e.g. Linux) the Cargo team would also like to switch the default to unpacked
. This will likely require another round of testing, however, and is blocked on the stabilization of -Csplit-debuginfo
for other Unix platforms in the first place (this is pseudo-tracked here and is known as "split dwarf" in the compiler itself).
How can I help?
First make sure you're building for macOS. Next make sure that you're on the nightly channel. Next configure Cargo to use split-debuginfo=unpacked
. This configuration can be via TOML:
# inside of ~/.cargo/config.toml
[profile.dev]
split-debuginfo = 'unpacked'
[profile.test]
split-debuginfo = 'unpacked'
or you can export environment variables too for your shell or build:
$ export CARGO_PROFILE_DEV_SPLIT_DEBUGINFO=unpacked
$ export CARGO_PROFILE_TEST_SPLIT_DEBUGINFO=unpacked
Next run cargo build
. Then cargo test
. Then incremental. Then anything else if you're feeling wild!
In other words we're looking to confirm that this is a build time win, shrinks the size of the target directory, and whether or not it breaks your tooling. If it breaks anything, we're interested in the details there too!