I keep running out of space when downloading the tokio crate, or when running cargo build --release, when I get that far.
I start at under 1 GB of available disk space.
E.g.,
user@user:~/bin/runjs$ cargo add tokio --features=default
Updating crates.io index
Adding tokio v1.41.0 to dependencies
Features:
- bytes
- fs
- full
- io-std
- io-util
- libc
- macros
- mio
- net
- parking_lot
- process
- rt
- rt-multi-thread
- signal
- signal-hook-registry
- socket2
- sync
- test-util
- time
- tokio-macros
- tracing
- windows-sys
user@user:~/bin/runjs$ cargo run
# ...
Downloaded tokio v1.41.0
Downloaded deno_core_icudata v0.0.73
Downloaded v8 v0.106.0
error: failed to unpack package `v8 v0.106.0`
Caused by:
failed to unpack entry at `v8-0.106.0/v8/src/wasm/wasm-module-builder.h`
Caused by:
failed to unpack `/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/v8-0.106.0/v8/src/wasm/wasm-module-builder.h`
Caused by:
failed to unpack `v8-0.106.0/v8/src/wasm/wasm-module-builder.h` into `/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/v8-0.106.0/v8/src/wasm/wasm-module-builder.h`
Caused by:
No space left on device (os error 28)
The goal is to complete a download of tokio and a cargo build --release of the above code in the article for around 500 MB, so I can still have around 200 MB left on disk.
I noticed that in the .cargo directory there are the archives and the extracted folders. Is there a way to automatically delete the archives when the crate is extracted so I am not carrying around the crate archives, too?
Alternatively, is it possible to instruct cargo to write the crate archives to an external USB device, and symlink to those dependencies in ~/.cargo , instead of writing the crates to ~/.cargo ?
Are you trying to cross-compile? Maybe the solution is to not attempt to build on a host with only 1GB (presumably limited by system RAM).
To the question you asked, sometimes you can cut down on dependencies by disabling unneeded feature flags. It doesn't help in this case because deno_core has about 180 dependencies that cannot be disabled.
Until someone puts in the work to optimize dependencies, your best option may be building on a larger host and downloading the binary within the live CD environment.
Nothing is preventing you from mounting ~/.cargo to your USB drive before starting cargo. No need to symlink anything. It just seems weird to insist that building in this environment is the right course of action.
Unfortunately, temporary junk created during the build easily grows to many gigabytes, even for small crates (100×-1000× size increase). You probably won't be able to compile anything in just 200MB ;(
Rust/Cargo easily produces gigabytes of debug info for even small crates. Make sure to disable debug info completely. See profiles.
Disable incremental build cache. This is another dir that just grows and grows.
You can delete ~/.cargo/registry/ before/after a build, but Cargo will need the downloaded and decompressed files to be there during the build.
Nothing is preventing you from mounting ~/.cargo to your USB drive before starting cargo.
Kindly explain precisely how you would do that.
It just seems weird to insist that building in this environment is the right course of action.
I've been experimenting on a live Linux USB for years. The way I see it, if it can't be built in a temporary file system with ~1 GB of total space, it's probably too expensive for standalone embedded systems where the source code of any compilers is also included in the "file".
C, C++, probably because of gcc is already on Linux. Python, WASI, can all be compiled for less than 1 GB deposit. With deno compile we can get a 78 MB executable from a 135 MB deno executable. Just for an example. Rust might spit out a 4 MB executabloe, at the cost of 465 MB more, initally. It's a balance, depending on the requirement and environment.
Assuming your USB drive is at /dev/sbd1 and you've already emptied ~/.cargo for mount(8):
# mount /dev/sdb1 ~/.cargo
This doesn't align with my expectations. An "embedded system" doesn't have to run Linux. There are many bare metal platforms where the default is cross compiling. Raspberry Pi Pico, ESP-32, even wasm32.
Having said that, I do not know of any efforts to make the compiler run on small machines.
if only your disk space is constrained, and you still have 2-3GB of RAM, your best bet is mounting the target dir to a zramfs to try to save space via compression.
1GB is just so far below "typical hard drive sizes", you're going to have issues.
and Rust has the philosophy that it's better to waste resources at compile time than at runtime. which makes sense considering you're basically always cross compiling for embedded workflows.
rustup, cargo, and all of the compiler toolchains are installed to ~/.cargo by default. After mounting the USB drive, you can install rustup and your toolchains to the USB drive.
Isn't there more to it than just using mount? We have to set PATH to include the USB device, too, right?
It sure would be helpful is somebody wrote up a piece about how to store cargo and company on an external drive, and use them as if they were on the OS file system.