Using cross is probably a simpler solution, but booting up a 2GiB container for each compilation takes too long, so I decided to use a FreeBSD VM.
This is NOT a step-by-step tutorial but a collection of steps that I remember doing to get this to work.
- The following directories and files are synced to the FreeBSD VM using
rsync
/Cargo.toml
/Cargo.lock
/src/*
build_and_run.sh
is executed on the FreeBSD VM in the project directory- Build the project in release mode for
x86_64-unknown-freebsd
- Send
SIGTERM
to all runningopenvpn-monitor
processes usingkillall
- Wait until all
openvpn-monitor
processes have exited - Copy the compiled binary to
/usr/local/bin
- Run the binary in the background
- Build the project in release mode for
- Download a FreeBSD image
- Add the following to
/etc/ssh/sshd_config
PermitRootLogin yes
AuthorizedKeysFile /root/.ssh/authorized_keys
- Add your SSH key from Windows to
/root/.ssh/authorized_keys
- Install Rust on the FreeBSD VM
- Generate an SSH key using
ssh-keygen -t ed25519
- Install
rsync
usingpkg install rsync
- Install
bash
usingpkg install bash
- Add the SSH key from the FreeBSD VM to the
admin
user- System -> User Manager -> Users ->
admin
-> Authorized SSH Keys
- System -> User Manager -> Users ->
- Install a Debian WSL2 instance
- Create a symlink for convenience
ln -s /mnt/c/path/to/openvpn-monitor/ openvpn-monitor
- Run
sync.sh
to compile on the FreeBSD VM and deploy to pfSense