How to build Rust in < 8GB?

I need to build Rust on the arm64 FreeBSD system with only 12 GB dedicated to the VM (because the total memory is only 16GB on this system).

The Rust build runs out of memory.
I changed these 3 options in the FreeBSD port:

  • use external LLVM
  • disable LTO
  • use only 1 core for build (MAKE_JOBS_NUMBER=1)

However, the build still runs out of memory.

How can I make it build in <8GB ?

Can you post some log excerpt? In which step does it fail?

Other things to try:

  • reduce/disable debuginfo
  • add swap
  • if you're using a tmpfs anywhere make sure that it's not writing gigabytes of files into that

I still find it astonishing that people casually talk of "system with only 12 GB" as if that wasn't frikken huge.

Coming from a time I could compile my code on machines with 64K bytes or even less this is mind bending.

Anyway I have the same problem I run out of disk on a machine with 10GB space and 2GB swap.

What to do?

Last 100 lines of log with SIGKILL in them.

Just to check is /wrkdirs a tmpfs or a regular directory on disk? If it is a tmpfs this error makes sense. Rustc needs more than 12GB of disk space to do a full build. If not I'm surprised it is rustdoc that fails. I would have expected rustc_middle to need more RAM.

wrkdir is tmpfs. I can try to set USE_TMPFS=OFF for it to go to disk.

Can I turn off rustdoc completely? How?

Then that is the issue. The wrkdir got so big that there is no memory remaining to run rustc. You will need to disable tmpfs usage for the rust port. According to Solved - tmpfs for building ports | The FreeBSD Forums there is a TMPFS_BLACKLIST option you can set together with TMPFS_BLACKLIST_TMPDIR. In fact the example usage for this option shows disabling tmpfs for the rust port.

I don't think you can without patching the build system of rust. And even if you did, doing so would break cargo test as it will use rustdoc to run doctests. And finally disabling rustdoc would almost certainly still result in an OOM once it goes building cargo.

With USE_TMPFS=no in poudriere.conf lang/rust succeeded.

Thank you for your suggestion!