1
0
forked from M-Labs/kirdy

add BSD build instructions

This commit is contained in:
Sébastien Bourdeauducq 2024-02-12 18:33:06 +08:00
parent 6b05b2d851
commit 4c331dd319
2 changed files with 62 additions and 0 deletions

60
BSD.md Normal file
View File

@ -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<Config>) -> 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.

View File

@ -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: