Blog/2024-02-28/Rust Panamax

From Rest of What I Know

Today, my wife and I flew to Hawaii for her sister's wedding tomorrow on Feb 29. That's a 5.5 h flight and United doesn't have Internet access on the plane once you leave the mainland US so that means that if you do any programming at all, it all has to be offline. So naturally I prepared for the occasion.

LLM Assistant[edit]

My M1 Max Mac has 64 GiB of RAM which is good enough to run a reasonably sized Mixtral 8x7b, the one quantized down to 4 bits per float. That's a pretty good tool and I've had it on my laptop for a while so I was confident it would work. I use Copilot less, so I didn't bother getting an offline version of that.

Rust Crates[edit]

A screenshot of the Panamax-RS web interface. It has instructions on how to set up Panamax.
The rather nice-looking page you see looking at the Panamax web server

Writing Rust, a lot of the work has been done in crates that are shared for all sorts of esoteric purposes. But to get crates you need the Internet. Unless you've decided to mirror all of crates.io on your laptop. Well, fortunately there's a tremendous tool to let you do that: Panamax.

It's a pretty straightforward process once you've decided you want this.

panamax sync crates-mirror synced everything to a directory called crates-mirror that I put in my ~/lib directory.

From that same directory, I could then run panamax server -p 80 to start a HTTP server that acts as a crates.io mirror. If you visit that page, you'll get the web interface with instructions on how to set things up. Personally, I didn't want to switch all my cargo commands to always use Panamax, this being a temporary affair, so I completed setup differently.

I added the following to ~/.zshrc since I wanted to be able to rustup offline as well, on-demand:

function activate_panamax_rustup() {
  export RUSTUP_DIST_SERVER=http://localhost
  export RUSTUP_UPDATE_ROOT=http://localhost/rustup
}

So now, when I want to rustup on Panamax, I run that function that's available and then it works as normal.

But the main thing you want to be able to do is use crates as if you were still connected to crates.io. For that, I added a comma command that proxies cargo:

#!/usr/bin/env bash

cargo \
  --config 'source.crates-io.replace-with="panamax-sparse"'\
  --config 'source.panamax.registry="http://localhost/git/crates.io-index"'\
  --config 'source.panamax-sparse.registry="sparse+http://localhost/index/"'\
  "$@"

Nice and simple, I save that as ,pargo it just runs our good friend cargo using the local index that panamax is serving. And after that ,pargo build and friends will work beautifully, fetching from one's local cache.

And then you can write code on a plane without needing to worry about fetching crates from the Internet!