Cargo + rustup + Toolbox

I was half-heartedly fooling around with rust+webassembly a few nights ago, which quickly takes you outside the packaged-in-Fedora universe - in particular, you need a build of rustc that can target webassembly.

The advertised way to do this is rustup, which downloads and installs rust compilers in ~/.cargo/bin alongside things that you build and install with ‘cargo install’.

But the home-directory install rubbed me the wrong way - in addition to wanting to keep this isolated from my normal working toolboxes instead of mixed with them, some crates (called -sys) do have dependencies on native system libraries which could differ between different toolboxes.

What I really wanted to do was to have a rust-development toolbox with all the rustup installed stuff and the stuff I installed with cargo isolated there - and more generally, I wanted a solution where things that I install with cargo are toolbox-local not home-directory global.

Some desirable properties of a solution:

  1. Can easily start using ‘cargo install’ in an arbitrary existing toolbox container.
  2. Location of $CARGO_HOME is on a direct bind mount, not fuse-overlayfs

One possible solution (that has property 1 but not property 2.:

sudo mkdir /cargo
sudo chown $(id -u):$(id -g) /cargo
ln -s /cargo ~/.cargo

I’m sure some people here have already come up with solutions for this and validated them with use. How are you handling this?


1 Like

Would love to hear if you come up with an answer. At the moment, I’m using cargo + rust installed through rpm-ostree.

See: GitHub - owtaylor/rustup-toolbox: Toolbox image with rustup based on Fedora for an attempt at a prebuilt Fedora+rustup Toolbox image.

The way it works is that it sets CARGO_HOME=/cargo and RUSTUP_HOME=/rustup in the container environment variables. These directories are meant to be wheel-writable, but due to a bug in crun, a small workaround is needed before starting to use the toolbox.

If anybody tries this out, let me know how it works for them. Thanks!