Ivory Siege Tower

mobile construct built of thoughts and parentheses

Cargo Home switching between different Cargo instances

[2022-10-25]

bash emacs guix rust st_dev

That's a tricky situation: I've ended up with two independent instances of Rust Cargo. One comes from rustup with all the top-notch features, including wasm32 target architecture for builds. The other is provisioned by Guix and is a bit behind and not having the extra targets required.

Why do I need the second one? Oh, that's because I do use Guix primarily to install Emacs and its packages, plus my own extensions on the top. All in "package manager" mode of Guix - for now. And some of those extensions rely on shared modules for Emacs. Arguably, the best and most clear way to create them shared modules id to write them in Rust.

And here a problem occurs: Emacs gets an error from module.so that it cannot find required glibc version, since external glibc (system-default) is different from the one installed by Guix (and at the moment, newer) than the one to which Emacs is linked inside Guix. I guess, when Guix is operating in OS mode there is no such problem, but here I see no other opportunity than bringing its own Rust toolchain alongside the "default" one.

There is an environment variable $CARGO_HOME (empty by default) that sets the location of the Cargo cache. But instead of setting it I use - and have verified - another approach: symlinking an actual cache folder to $HOME/.cargo. This way the choice of cache folder AND the cargo instance persists among sessions, until I manually switch it.

  function set_cargo_guix () {
          ln -sfn $HOME/.cargo_guix $HOME/.cargo
  }

  function set_cargo_rustup () {
          ln -sfn $HOME/.cargo_rustup $HOME/.cargo
  }

  path_prepend $HOME/.cargo/bin
  echo "cargo points to $(ls -l $HOME/.cargo | awk '{ print $11 }')"

The path_prepend function is one of the clean ways to alter $PATH that I stole from here.

Understandingly, it is an ad-hoc solution. Like all workarounds it lives inside .bashrc marked for further improvement. Ideally I should use something like Guix profiles with $CARGO_HOME correctly set. All that and more will be revisited upon successful adoption of GuixOS, if it ever happens.

Until then this is fine.

Social Timeline: