Skip to content

Commit a8a162e

Browse files
committed
Merge remote-tracking branch 'tcharding/07-28-alloc-feature' into HEAD
2 parents cc50e7d + e15eb28 commit a8a162e

File tree

11 files changed

+147
-20
lines changed

11 files changed

+147
-20
lines changed

.github/workflows/rust.yml

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
12
on: [pull_request]
23

34
name: Continuous Integration
45

56
jobs:
6-
test:
7+
Test:
78
name: Test Suite
89
runs-on: ubuntu-latest
910
strategy:
@@ -13,16 +14,17 @@ jobs:
1314
- stable
1415
- nightly
1516
steps:
17+
- name: Checkout Crate
1618
- uses: actions/checkout@v2
19+
- name: Checkout Toolchain
1720
- uses: actions-rs/toolchain@v1
1821
with:
1922
profile: minimal
2023
toolchain: ${{ matrix.rust }}
2124
override: true
22-
- uses: actions-rs/cargo@v1
23-
with:
24-
command: test
25-
args: --verbose --features strict
25+
- name: Run Test Script
26+
env: ${{ matrix.rust }}
27+
run: ./contrib/test.sh
2628

2729
fmt:
2830
name: Rustfmt
@@ -64,7 +66,8 @@ jobs:
6466
command: clippy
6567
args: -- -D warnings
6668

67-
Embedded:
69+
EmbeddedWithAlloc:
70+
name: no_std with alloc
6871
runs-on: ubuntu-latest
6972
steps:
7073
- name: Checkout
@@ -83,4 +86,20 @@ jobs:
8386
env:
8487
RUSTFLAGS: "-C link-arg=-Tlink.x"
8588
CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER: "qemu-system-arm -cpu cortex-m3 -machine mps2-an385 -nographic -semihosting-config enable=on,target=native -kernel"
86-
run: cd embedded && cargo run --target thumbv7m-none-eabi
89+
run: cd embedded/with-allocator && cargo run --target thumbv7m-none-eabi
90+
91+
EmbeddedNoAlloc:
92+
name: no_std no alloc
93+
runs-on: ubuntu-latest
94+
strategy:
95+
steps:
96+
- uses: actions/checkout@v2
97+
- uses: actions-rs/toolchain@v1
98+
with:
99+
profile: minimal
100+
toolchain: stable
101+
override: true
102+
- uses: actions-rs/cargo@v1
103+
with:
104+
command: rustc
105+
args: -- -C link-arg=-nostartfiles

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
*.o
33
/Cargo.lock
44

5-
/embedded/Cargo.lock
6-
/embedded/.cargo
5+
/embedded/no-allocator/Cargo.lock
6+
/embedded/no-allocator/.cargo
7+
/embedded/with-allocator/Cargo.lock
8+
/embedded/with-allocator/.cargo

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ edition = "2018"
1212

1313
[features]
1414
default = ["std"]
15-
std = []
15+
std = ["alloc"]
16+
alloc = []
17+
1618
# Only for CI to make all warnings errors, do not activate otherwise (may break forward compatibility)
1719
strict = []
1820

contrib/test.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
#
3+
# CI test script for rust-bech32.
4+
#
5+
# The "strict" feature is used to configure cargo to deny all warnings, always use it in test runs.
6+
7+
set -ex
8+
9+
# Sanity, check tools exist.
10+
cargo --version
11+
rustc --version
12+
13+
# Sanity, first check with default features.
14+
15+
cargo build
16+
cargo test
17+
18+
# Sanity, build with no features.
19+
20+
cargo build --no-default-features --features="strict"
21+
22+
# Check "alloc" feature alone.
23+
24+
cargo build --no-default-features --features="strict std"
25+
cargo test --no-default-features --features="strict std"
26+
27+
# Check "std" feature (implies "alloc").
28+
29+
cargo build --no-default-features --features="strict alloc"
30+
cargo test --no-default-features --features="strict alloc"
31+
32+
exit 0

embedded/no-allocator/Cargo.toml

+15
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

+10
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

+26
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+
}

embedded/Cargo.toml renamed to embedded/with-allocator/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["Riccardo Casatta <[email protected]>"]
33
edition = "2018"
44
readme = "README.md"
5-
name = "embedded"
5+
name = "with-allocator"
66
version = "0.1.0"
77

88
[dependencies]
@@ -11,10 +11,10 @@ cortex-m-rt = "0.6.10"
1111
cortex-m-semihosting = "0.3.3"
1212
panic-halt = "0.2.0"
1313
alloc-cortex-m = "0.4.1"
14-
bech32 = { path="../", default-features = false }
14+
bech32 = { path="../../", default-features = false }
1515

1616
[[bin]]
17-
name = "embedded"
17+
name = "with-allocator"
1818
test = false
1919
bench = false
2020

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)