Cross-build FreeBSD Program in Linux
Rust on FreeBSD
The First Steps on FreeBSD
hostname
1 | root@freebsd-13:~ # vi /etc/rc.conf |
hvn0
1 | root@freebsd-13:~ # vi /etc/rc.conf |
disk
1 | root@freebsd-13:~ # df -h |
1 | root@freebsd-13:~ # mount |
rc.conf
1 | root@freebsd-13:~ # vi /etc/rc.conf |
sshd
1 | root@freebsd-13:~ # touch $HOME/.hushlogin |
pkg
1 | root@freebsd-13:~ # vi ~/.profile |
1 | root@freebsd-13:~ # pkg update |
cc
1 | root@freebsd-13:~ # cat << EOF | cc -std=c11 -march=haswell -O2 -s -o hello -x c - |
c++
1 | root@freebsd-13:~ # cat << EOF | c++ -std=c++17 -march=haswell -O2 -s -o hello.c++ -x c++ - |
Copy FreeBSD Library Files to Linux
We can copy all files under /lib and /usr/lib:
1 | root@freebsd-13:~ # du -ms /lib /usr/lib /usr/include |
or a few of them:
1 | root@linux:/opt $ du -ms x86_64-unknown-freebsd/ |
Archive Library Files on FreeBSD
1 | root@freebsd-13:~ # tar --no-acls --no-xattrs --no-fflags -cvzf x86_64-unknown-freebsd_13.0-RELEASE-p4-rust.tar.gz \ |
Extract FreeBSD Library Files on Linux
1 | root@linux:~ $ mkdir -p /opt/x86_64-unknown-freebsd |
Install clang and lld on Linux
1 | sudo apt-get install -y clang lld |
Install Rust on Linux
1 | root@linux:~ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
Cargo’s Configuration on Linux
Cargo allows local configuration for a particular package as well as global configuration. It looks for configuration files in the current directory and all parent directories.
- .cargo/config.toml
- (all parent directories)/.cargo/config.toml
- $CARGO_HOME/config.toml which defaults to:
- Windows: %USERPROFILE%.cargo\config.toml
- Unix: $HOME/.cargo/config.toml, ${CARGO_HOME:-${HOME}/.cargo}/config.toml
Now we can make rust target x86_64-unknown-FreeBSD use directory /opt/x86_64-unknown-FreeBSD as sysroot:
1 | [http] |
Cross-build FreeBSD Program in Linux
1 | root@linux:~ uname -msr |