Now I have a shell script `rcargo` which remote compiles rust crates: I work on my laptop but have beefy machines on my home and work LANs. You'd have to reimplement cargo to do it much finer-grained, apparently: sccache used to and gave up?

The real trick is ssh's ControlPath config var, which allows shared connection for much-improved speed: ChatGPT taught me this one!

The other option is Nix, but I'm not *that* bored!

Reply to this note

Please Login to reply.

Discussion

How much better than https://github.com/liamaharon/crunch if at all?

Seems similar! Mine is for my specific setup: I have different machines on home vs work, so I wanted it to Just Work. And it's one file:

#! /bin/sh -e

REMOTES="workserver:22 homeserver:22 bouncehost:2222"

# Figure out likely remotes by looking for ssh ControlPath vars, as

# per this cantrip in ssh_config:

# # Reuse ssh tunnels if possible.

# Host *

# ControlMaster auto

# ControlPath ~/.cache/ssh-%r@%h:%p

# ControlPersist 10m

find_remote()

{

for r in $REMOTES; do

if [ -S ~/.cache/ssh-`whoami`@$r ]; then

echo $r

return

fi

done

# Nothing cached, try ping.

for r in $REMOTES; do

host=$(echo $r | cut -d: -f1)

if ping -c 1 $host > /dev/null 2>&1; then

echo $r

return

fi

done

echo "No reachable remote" >&2

exit 1

}

# Make sure we're in a git dir!

[ -d .git ] || (echo "Not a git dir!"; exit 1)

PWD=$(pwd -P)

REMOTE=$(find_remote)

echo "rcargo: remote $REMOTE"

HOST=$(echo $REMOTE | cut -d: -f1)

PORT=$(echo $REMOTE | cut -d: -f2)

# Make sure directory exists

ssh "$HOST" -p $PORT "mkdir -p '$PWD'"

# Sync source (exclude junk)

rsync -az --delete \

-e "ssh -p $PORT" \

--exclude .git \

--exclude target \

"$PWD/" "$HOST:$PWD/"

ssh $HOST -p $PORT ". ~/.profile && cd '$PWD' && cargo $*"

rsync -az --delete \

-e "ssh -p $PORT" \

"$HOST:$PWD/target/" "$PWD/target/"