From 4c331dd3192cc918864f5893a64fa82a9d6d6251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Mon, 12 Feb 2024 18:33:06 +0800 Subject: [PATCH] add BSD build instructions --- BSD.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 62 insertions(+) create mode 100644 BSD.md diff --git a/BSD.md b/BSD.md new file mode 100644 index 0000000..ff41cbf --- /dev/null +++ b/BSD.md @@ -0,0 +1,60 @@ +# Building Rust embedded firmware on BSD + +Using the Rust stable compiler from the BSD ports is mostly a matter of removing the arbitrary limitations that have been built into the Rust toolchain. + +Get rid of the "nightly toolchain" check in cargo-xbuild: +``` +diff --git a/src/lib.rs b/src/lib.rs +index 204ad8f..9c61e39 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -157,28 +157,11 @@ pub fn build(args: Args, command_name: &str, crate_config: Option) -> Re + }) + })?; + +- // We can't build sysroot with stable or beta due to unstable features + let sysroot = rustc::sysroot(verbose)?; +- let src = match meta.channel { +- Channel::Dev => rustc::Src::from_env().ok_or(anyhow!( ++ let src = rustc::Src::from_env().ok_or(anyhow!( + "The XARGO_RUST_SRC env variable must be set and point to the \ +- Rust source directory when working with the 'dev' channel", +- ))?, +- Channel::Nightly => { +- if let Some(src) = rustc::Src::from_env() { +- src +- } else { +- sysroot.src()? +- } +- } +- Channel::Stable | Channel::Beta => { +- bail!( +- "The sysroot can't be built for the {:?} channel. \ +- Switch to nightly.", +- meta.channel +- ); +- } +- }; ++ Rust source directory", ++ ))?; + + let cmode = if let Some(triple) = args.target() { + if triple == meta.host { +``` + +Run ``cargo install --path .`` to install the modified cargo-xbuild + +Get a copy of the Rust sources that corresponds to the installed compiler binary, and set up the environment accordingly: +``` +> rustc --version +rustc 1.72.1 (d5c2e9c34 2023-09-13) (built from a source tarball) +> git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/rust-lang/rust --branch 1.72.1 +> export XARGO_RUST_SRC=`pwd`/rust/library +``` + +Disable other arbitrary checks in the Rust compiler: +``` +> export RUSTC_BOOTSTRAP=1 +``` + +And you can now simply run ``cargo xbuild`` to build the firmware. diff --git a/README.md b/README.md index a31dece..e203116 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ The resulting ELF file will be located under `target/thumbv7em-none-eabihf/relea Alternatively, you can install the Rust toolchain without Nix using rustup; see the Rust manifest file pulled in `flake.nix` to determine which Rust version to use. +For building on FreeBSD or OpenBSD, see BSD.md. + ## Debugging Connect SWDIO/SWCLK/RST/GND to a programmer such as ST-Link v2.1. Run OpenOCD: