Skip to content

Commit 0abde2f

Browse files
committed
Add no-allocator crate
In order to test that `bech32` can be built in a `no_std` environment without an allocator add a crate `no-allocator` to the `embedded` directory. Add a CI job to build the crate.
1 parent e7ce700 commit 0abde2f

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-1
lines changed

.github/workflows/rust.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ jobs:
7373
command: clippy
7474
args: -- -D warnings
7575

76-
Embedded:
76+
EmbeddedAlloc:
77+
name: no_std with allocator
7778
runs-on: ubuntu-latest
7879
steps:
7980
- name: Checkout
@@ -93,3 +94,19 @@ jobs:
9394
RUSTFLAGS: "-C link-arg=-Tlink.x"
9495
CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER: "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
9596
run: cd embedded/allocator && cargo run --target thumbv7m-none-eabi
97+
98+
EmbeddedNoAlloc:
99+
name: no_std without allocator
100+
runs-on: ubuntu-latest
101+
strategy:
102+
steps:
103+
- uses: actions/checkout@v2
104+
- uses: actions-rs/toolchain@v1
105+
with:
106+
profile: minimal
107+
toolchain: stable
108+
override: true
109+
- uses: actions-rs/cargo@v1
110+
with:
111+
command: rustc
112+
args: -- -C link-arg=-nostartfiles

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
*.o
33
/Cargo.lock
44

5+
/embedded/no-allocator/Cargo.lock
6+
/embedded/no-allocator/.cargo
57
/embedded/with-allocator/Cargo.lock
68
/embedded/with-allocator/.cargo

embedded/no-allocator/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
authors = ["Tobin C. Harding <[email protected]>"]
3+
edition = "2018"
4+
readme = "README.md"
5+
name = "no-allocator"
6+
version = "0.1.0"
7+
8+
[profile.dev]
9+
panic = "abort"
10+
11+
[profile.release]
12+
panic = "abort"
13+
14+
[dependencies]
15+
bech32 = { path = "../../", default_features = false }

embedded/no-allocator/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# no_std test crate without an allocator
2+
3+
This crate is based on the blog post found at:
4+
5+
https://blog.dbrgn.ch/2019/12/24/testing-for-no-std-compatibility/
6+
7+
Its purpose is to test that the `rust-bech32` library can be built in a `no_std` environment without
8+
a global allocator.
9+
10+
Build with: `cargo rustc -- -C link-arg=-nostartfiles`.

embedded/no-allocator/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Test `no_std` build of `bech32`.
2+
//!
3+
//! Build with: `cargo rustc -- -C link-arg=-nostartfiles`.
4+
//!
5+
6+
#![no_std]
7+
#![no_main]
8+
9+
use core::panic::PanicInfo;
10+
11+
// Note: `#[global_allocator]` is NOT set.
12+
13+
#[allow(unused_imports)]
14+
use bech32;
15+
16+
/// This function is called on panic, defining this ensures build will fail if `std` is enabled
17+
/// because `panic` will be defined twice.
18+
#[panic_handler]
19+
fn panic(_info: &PanicInfo) -> ! {
20+
loop {}
21+
}
22+
23+
#[no_mangle]
24+
pub extern "C" fn _start() -> ! {
25+
loop {}
26+
}

0 commit comments

Comments
 (0)