Blog/2024-02-28/Rust Panamax: Difference between revisions

From Rest of What I Know
Created page with "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 == My M1 Max Mac has 64 GiB of RAM which is good enough to run [https://huggingface.co/TheBloke/dolphin-2.5-mixtral-8x7b-GGUF a reasonably sized Mix..."
 
No edit summary
Line 41: Line 41:


Nice and simple, I save that as <syntaxhighlight inline>,pargo</syntaxhighlight> it just runs our good friend cargo using the local index that panamax is serving. And after that <syntaxhighlight inline>,pargo build</syntaxhighlight> and friends will work beautifully, fetching from one's local cache.
Nice and simple, I save that as <syntaxhighlight inline>,pargo</syntaxhighlight> it just runs our good friend cargo using the local index that panamax is serving. And after that <syntaxhighlight inline>,pargo build</syntaxhighlight> 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!

Revision as of 09:00, 29 February 2024

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

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

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!