Published : 2026-02-15

Compile rust programs on FreeBSD with Bastille

Introduction

Compiling Rust on FreeBSD can be resource-intensive. Using Bastille jails allows you to isolate the compilation environment without impacting the host system.

This article documents how to create a FreeBSD jail with Bastille, install Rust, and compile a Rust project.

Create a Bastille jail

Create a thin jail with Bastille:

root@rustbuilder:~ # bastille create rustjail 14.3-RELEASE 172.31.0.10/24

Attempting to create jail: rustjail

Valid IP: 172.31.0.10

Creating a thinjail...

[rustjail]:
rustjail: created

[rustjail]:
Applying template: default/thin...

[rustjail]:
Applying template: default/base...

[rustjail]:

[rustjail]:

[rustjail]:

[rustjail]:
daily_status_world_kernel:  -> NO

[rustjail]:
syslogd_flags: -s -> -ss

[rustjail]:
sendmail_enable: NONE -> NO

[rustjail]:
sendmail_submit_enable: YES -> NO

[rustjail]:
sendmail_outbound_enable: YES -> NO

[rustjail]:
sendmail_msp_queue_enable: YES -> NO

[rustjail]:
cron_flags:  -> -J 60

[rustjail]:
/etc/resolv.conf -> /usr/local/bastille/jails/rustjail/root/etc/resolv.conf

Template applied: default/base

Template applied: default/thin

[rustjail]:
rustjail: removed

[rustjail]:
rustjail: created

Verify the jail is running:

root@rustbuilder:~ # bastille list
 JID  Name      Boot  Prio  State  Type   IP Address     Published Ports  Release       Tags
 3    rustjail  on    99    Up     thin   172.31.0.10  -                14.3-RELEASE  -

Access the jail

Connect to the jail console:

root@rustbuilder:~ # bastille console rustjail
[rustjail]:
root@rustjail:~ #

Install Rust

First, install rustup-init:

root@rustjail:~ # pkg install rustup-init
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+https://pkg.FreeBSD.org/FreeBSD:14:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
[rustjail] Installing pkg-2.5.1...
[rustjail] Extracting pkg-2.5.1: 100%
Updating FreeBSD repository catalogue...
[rustjail] Fetching meta.conf: 100%    179 B   0.2 k/s    00:01    
[rustjail] Fetching data: 100%   10 MiB   2.7 M/s    00:04    
Processing entries: 100%
FreeBSD repository update completed. 36700 packages processed.
Updating FreeBSD-kmods repository catalogue...
[rustjail] Fetching meta.conf: 100%    179 B   0.2 k/s    00:01    
[rustjail] Fetching data: 100%   36 KiB  37.3 k/s    00:01    
Processing entries: 100%
FreeBSD-kmods repository update completed. 245 packages processed.
All repositories are up to date.
Updating database digests format: 100%
The following 10 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	brotli: 1.2.0,1 [FreeBSD]
	curl: 8.17.0 [FreeBSD]
	indexinfo: 0.3.1_1 [FreeBSD]
	libidn2: 2.3.8 [FreeBSD]
	libnghttp2: 1.68.0 [FreeBSD]
	libpsl: 0.21.5_2 [FreeBSD]
	libssh2: 1.11.1,3 [FreeBSD]
	libunistring: 1.4.1 [FreeBSD]
	rustup-init: 1.28.1_8 [FreeBSD]
	zstd: 1.5.7_1 [FreeBSD]

Number of packages to be installed: 10

The process will require 24 MiB more space.
7 MiB to be downloaded.

Proceed with this action? [y/N]: y
[rustjail] [ 1/10] Fetching indexinfo-0.3.1_1: 100%    6 KiB   6.2 k/s    00:01    
[rustjail] [ 2/10] Fetching libnghttp2-1.68.0: 100%  137 KiB 140.7 k/s    00:01    
[rustjail] [ 3/10] Fetching libidn2-2.3.8: 100%  160 KiB 164.0 k/s    00:01    
[rustjail] [ 4/10] Fetching zstd-1.5.7_1: 100%  509 KiB 521.0 k/s    00:01    
[rustjail] [ 5/10] Fetching libunistring-1.4.1: 100%  738 KiB 755.0 k/s    00:01    
[rustjail] [ 6/10] Fetching libssh2-1.11.1,3: 100%  244 KiB 250.0 k/s    00:01    
[rustjail] [ 7/10] Fetching libpsl-0.21.5_2: 100%   66 KiB 67.5 k/s    00:01    
[rustjail] [ 8/10] Fetching brotli-1.2.0,1: 100%  388 KiB 397.0 k/s    00:01    
[rustjail] [ 9/10] Fetching curl-8.17.0: 100%    2 MiB   1.8 M/s    00:01    
[rustjail] [10/10] Fetching rustup-init-1.28.1_8: 100%    3 MiB   3.0 M/s    00:01    
Checking integrity... done (0 conflicting)
[rustjail] [ 1/10] Installing brotli-1.2.0,1...
[rustjail] [ 1/10] Extracting brotli-1.2.0,1: 100%
[rustjail] [ 2/10] Installing indexinfo-0.3.1_1...
[rustjail] [ 2/10] Extracting indexinfo-0.3.1_1: 100%
[rustjail] [ 3/10] Installing libnghttp2-1.68.0...
[rustjail] [ 3/10] Extracting libnghttp2-1.68.0: 100%
[rustjail] [ 4/10] Installing libssh2-1.11.1,3...
[rustjail] [ 4/10] Extracting libssh2-1.11.1,3: 100%
[rustjail] [ 5/10] Installing libunistring-1.4.1...
[rustjail] [ 5/10] Extracting libunistring-1.4.1: 100%
[rustjail] [ 6/10] Installing libidn2-2.3.8...
[rustjail] [ 6/10] Extracting libidn2-2.3.8: 100%
[rustjail] [ 7/10] Installing libpsl-0.21.5_2...
[rustjail] [ 7/10] Extracting libpsl-0.21.5_2: 100%
[rustjail] [ 8/10] Installing zstd-1.5.7_1...
[rustjail] [ 8/10] Extracting zstd-1.5.7_1: 100%
[rustjail] [ 9/10] Installing curl-8.17.0...
[rustjail] [ 9/10] Extracting curl-8.17.0: 100%
[rustjail] [10/10] Installing rustup-init-1.28.1_8...
[rustjail] [10/10] Extracting rustup-init-1.28.1_8: 100%
=====
Message from rustup-init-1.28.1_8:

--
Usage:

  1. Use the following command to install rustup only to $RUSTUP_HOME (default: $HOME/.rustup).
  $ rustup-init --profile minimal --default-toolchain none -y

  2. Use the following command to install toolchains to $CARGO_HOME (default: $HOME/.cargo) in a new terminal session.
  $ rustup default stable

Initialize rustup with minimal profile:

root@rustjail:~ # rustup-init --profile minimal --default-toolchain none -y
info: profile set to 'minimal'
info: default host triple is x86_64-unknown-freebsd
info: skipping toolchain installation

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
source "$HOME/.cargo/env.nu"    # For nushell

Source the cargo environment:

root@rustjail:~ # . "$HOME/.cargo/env"

Install the stable Rust toolchain:

root@rustjail:~ # rustup default stable
info: syncing channel updates for 'stable-x86_64-unknown-freebsd'
info: latest update on 2026-02-12, rust version 1.93.1 (01f6ddf75 2026-02-11)
info: downloading component 'cargo'
 11.0 MiB /  11.0 MiB (100 %)   9.6 MiB/s in  1s         
info: downloading component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %)  13.0 MiB/s in  2s         
info: downloading component 'rustc'
 83.7 MiB /  83.7 MiB (100 %)  15.2 MiB/s in  8s         
info: installing component 'cargo'
 11.0 MiB /  11.0 MiB (100 %)   3.3 MiB/s in  3s         
  3 IO-ops /   3 IO-ops (100 %)   0 IOPS in  5s ETA: Unknown
info: installing component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %)   1.6 MiB/s in  27s         
  5 IO-ops /   5 IO-ops (100 %)   0 IOPS in  13s ETA: Unknown
info: installing component 'rustc'
 83.7 MiB /  83.7 MiB (100 %) 352.0 KiB/s in  1m 28s         
  4 IO-ops /   4 IO-ops (100 %)   0 IOPS in  15s ETA: Unknown
info: default toolchain set to 'stable-x86_64-unknown-freebsd'

  stable-x86_64-unknown-freebsd installed - rustc 1.93.1 (01f6ddf75 2026-02-11)

Install Git and clone a project

Install Git to clone repositories:

root@rustjail:~ # pkg install git
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
Updating FreeBSD-kmods repository catalogue...
FreeBSD-kmods repository is up to date.
All repositories are up to date.
The following 19 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	expat: 2.7.3 [FreeBSD]
	gettext-runtime: 0.26 [FreeBSD]
	git: 2.52.0 [FreeBSD]
	libffi: 3.5.1 [FreeBSD]
	mpdecimal: 4.0.1 [FreeBSD]
	p5-Authen-SASL: 2.1900 [FreeBSD]
	p5-Crypt-URandom: 0.54 [FreeBSD]
	p5-Digest-HMAC: 1.05 [FreeBSD]
	p5-Error: 0.17030 [FreeBSD]
	p5-IO-Socket-SSL: 2.095 [FreeBSD]
	p5-MIME-Base32: 1.303 [FreeBSD]
	p5-MIME-Base64: 3.16 [FreeBSD]
	p5-Mozilla-CA: 20250602 [FreeBSD]
	p5-Net-SSLeay: 1.94 [FreeBSD]
	p5-URI: 5.34 [FreeBSD]
	pcre2: 10.47_1 [FreeBSD]
	perl5: 5.42.0_1 [FreeBSD]
	python311: 3.11.14_2 [FreeBSD]
	readline: 8.3.3 [FreeBSD]

Number of packages to be installed: 19

The process will require 336 MiB more space.
55 MiB to be downloaded.

Proceed with this action? [y/N]: y
[rustjail] [ 1/19] Fetching p5-MIME-Base64-3.16: 100%   22 KiB  22.6 k/s    00:01    
[rustjail] [ 2/19] Fetching p5-Net-SSLeay-1.94: 100%  280 KiB 286.6 k/s    00:01    
[rustjail] [ 3/19] Fetching p5-IO-Socket-SSL-2.095: 100%  195 KiB 199.7 k/s    00:01    
[rustjail] [ 4/19] Fetching mpdecimal-4.0.1: 100%  157 KiB 160.6 k/s    00:01    
[rustjail] [ 5/19] Fetching p5-MIME-Base32-1.303: 100%    8 KiB   8.3 k/s    00:01    
[rustjail] [ 6/19] Fetching p5-URI-5.34: 100%  103 KiB 105.5 k/s    00:01    
[rustjail] [ 7/19] Fetching perl5-5.42.0_1: 100%   16 MiB  16.7 M/s    00:01    
[rustjail] [ 8/19] Fetching p5-Crypt-URandom-0.54: 100%   17 KiB  17.9 k/s    00:01    
[rustjail] [ 9/19] Fetching p5-Mozilla-CA-20250602: 100%  123 KiB 126.3 k/s    00:01    
[rustjail] [10/19] Fetching pcre2-10.47_1: 100%    1 MiB   1.5 M/s    00:01    
[rustjail] [11/19] Fetching libffi-3.5.1: 100%   46 KiB  47.3 k/s    00:01    
[rustjail] [12/19] Fetching readline-8.3.3: 100%  467 KiB 478.7 k/s    00:01    
[rustjail] [13/19] Fetching p5-Digest-HMAC-1.05: 100%   15 KiB  14.9 k/s    00:01    
[rustjail] [14/19] Fetching p5-Error-0.17030: 100%   27 KiB  27.3 k/s    00:01    
[rustjail] [15/19] Fetching gettext-runtime-0.26: 100%  303 KiB 310.2 k/s    00:01    
[rustjail] [16/19] Fetching expat-2.7.3: 100%  126 KiB 129.0 k/s    00:01    
[rustjail] [17/19] Fetching git-2.52.0: 100%    9 MiB   9.0 M/s    00:01    
[rustjail] [18/19] Fetching python311-3.11.14_2: 100%   27 MiB  14.1 M/s    00:02    
[rustjail] [19/19] Fetching p5-Authen-SASL-2.1900: 100%   44 KiB  45.2 k/s    00:01    
Checking integrity... done (0 conflicting)
[rustjail] [ 1/19] Installing expat-2.7.3...
[rustjail] [ 1/19] Extracting expat-2.7.3: 100%
[rustjail] [ 2/19] Installing gettext-runtime-0.26...
[rustjail] [ 2/19] Extracting gettext-runtime-0.26: 100%
[rustjail] [ 3/19] Installing libffi-3.5.1...
[rustjail] [ 3/19] Extracting libffi-3.5.1: 100%
[rustjail] [ 4/19] Installing mpdecimal-4.0.1...
[rustjail] [ 4/19] Extracting mpdecimal-4.0.1: 100%
[rustjail] [ 5/19] Installing pcre2-10.47_1...
[rustjail] [ 5/19] Extracting pcre2-10.47_1: 100%
[rustjail] [ 6/19] Installing perl5-5.42.0_1...
[rustjail] [ 6/19] Extracting perl5-5.42.0_1: 100%
[rustjail] [ 7/19] Installing p5-Crypt-URandom-0.54...
[rustjail] [ 7/19] Extracting p5-Crypt-URandom-0.54: 100%
[rustjail] [ 8/19] Installing p5-Digest-HMAC-1.05...
[rustjail] [ 8/19] Extracting p5-Digest-HMAC-1.05: 100%
[rustjail] [ 9/19] Installing p5-Authen-SASL-2.1900...
[rustjail] [ 9/19] Extracting p5-Authen-SASL-2.1900: 100%
[rustjail] [10/19] Installing p5-Error-0.17030...
[rustjail] [10/19] Extracting p5-Error-0.17030: 100%
[rustjail] [11/19] Installing p5-MIME-Base32-1.303...
[rustjail] [11/19] Extracting p5-MIME-Base32-1.303: 100%
[rustjail] [12/19] Installing p5-MIME-Base64-3.16...
[rustjail] [12/19] Extracting p5-MIME-Base64-3.16: 100%
[rustjail] [13/19] Installing p5-Mozilla-CA-20250602...
[rustjail] [13/19] Extracting p5-Mozilla-CA-20250602: 100%
[rustjail] [14/19] Installing p5-Net-SSLeay-1.94...
[rustjail] [14/19] Extracting p5-Net-SSLeay-1.94: 100%
[rustjail] [15/19] Installing p5-URI-5.34...
[rustjail] [15/19] Extracting p5-URI-5.34: 100%
[rustjail] [16/19] Installing p5-IO-Socket-SSL-2.095...
[rustjail] [16/19] Extracting p5-IO-Socket-SSL-2.095: 100%
[rustjail] [17/19] Installing readline-8.3.3...
[rustjail] [17/19] Extracting readline-8.3.3: 100%
[rustjail] [18/19] Installing python311-3.11.14_2...
[rustjail] [18/19] Extracting python311-3.11.14_2: 100%
[rustjail] [19/19] Installing git-2.52.0...
===> Creating groups
Creating group 'git_daemon' with gid '964'
===> Creating users
Creating user 'git_daemon' with uid '964'
[rustjail] [19/19] Extracting git-2.52.0: 100%

Clone a Rust project:

root@rustjail:~ # git clone https://github.com/nerzhul/rust-example.git
Cloning into 'home-router'...
remote: Enumerating objects: 110, done.
remote: Counting objects: 100% (110/110), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 110 (delta 40), reused 101 (delta 31), pack-reused 0 (from 0)
Receiving objects: 100% (110/110), 67.95 KiB | 2.52 MiB/s, done.
Resolving deltas: 100% (40/40), done.

Compile the project

Navigate to the project directory and build it:

root@rustjail:~/rust-example # cargo build
    Updating crates.io index
  Downloaded serde v1.0.209
  Downloaded serde_derive v1.0.209
  Downloaded tokio v1.39.3
  Downloaded mio v1.0.2
  Downloaded socket2 v0.5.7
  Downloaded parking_lot v0.12.3
  Downloaded parking_lot_core v0.9.10
  Downloaded lock_api v0.4.12
  Downloaded smallvec v1.13.2
  Downloaded libc v0.2.158
  Downloaded bytes v1.7.1
  Downloaded signal-hook-registry v1.4.2
  Downloaded pin-project-lite v0.2.14
  Downloaded autocfg v1.3.0
  Downloaded cfg-if v1.0.0
  Downloaded log v0.4.22
  Downloaded quote v1.0.36
  Downloaded syn v2.0.75
  Downloaded proc-macro2 v1.0.86
  Downloaded unicode-ident v1.0.12
   Compiling libc v0.2.158
   Compiling proc-macro2 v1.0.86
   Compiling unicode-ident v1.0.12
   Compiling autocfg v1.3.0
   Compiling cfg-if v1.0.0
   Compiling quote v1.0.36
   Compiling syn v2.0.75
   Compiling lock_api v0.4.12
   Compiling parking_lot_core v0.9.10
   Compiling smallvec v1.13.2
   Compiling bytes v1.7.1
   Compiling signal-hook-registry v1.4.2
   Compiling socket2 v0.5.7
   Compiling mio v1.0.2
   Compiling pin-project-lite v0.2.14
   Compiling tokio v1.39.3
   Compiling serde v1.0.209
   Compiling serde_derive v1.0.209
   Compiling log v0.4.22
   Compiling rust-example v0.1.0 (/usr/home/alex/dev/rust-example)
    Finished dev [unoptimized + debuginfo] target(s) in 18.42s

root@rustjail:~/rust-example # file target/debug/rust-example
target/debug/rust-example: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, for FreeBSD 14.3, with debug_info, not stripped

The compilation will download dependencies and compile them. On a typical system, this may take several minutes depending on the project size and jail resources.

Conclusion

Voila, you now know how to compile a Rust program under FreeBSD easily!