Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Test in CI if the lib works in embedded #119

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ jobs:
DO_FEATURE_MATRIX: true
run: ./contrib/test.sh

Embedded:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rust-src
target: thumbv7m-none-eabi
- name: Build
env:
RUSTFLAGS: "-C link-arg=-Tlink.x"
run: cd embedded && cargo build --target thumbv7m-none-eabi

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Cargo.lock
fuzz/hfuzz_target
fuzz/hfuzz_workspace

#embedded
embedded/.cargo

*~
23 changes: 23 additions & 0 deletions embedded/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = ["Riccardo Casatta <[email protected]>"]
edition = "2018"
readme = "README.md"
name = "embedded"
version = "0.1.0"

[dependencies]
cortex-m = "0.6.0"
cortex-m-rt = "0.6.10"
cortex-m-semihosting = "0.3.3"
panic-halt = "0.2.0"
bitcoin_hashes = { path="../", default-features = false }

[[bin]]
name = "embedded"
test = false
bench = false

[profile.release]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
5 changes: 5 additions & 0 deletions embedded/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
RAM : ORIGIN = 0x20000000, LENGTH = 64K
}
22 changes: 22 additions & 0 deletions embedded/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![no_std]
#![no_main]

#[macro_use]
extern crate bitcoin_hashes;

use panic_halt as _;
use cortex_m_rt::entry;
use cortex_m_semihosting::{debug, hprintln};
use bitcoin_hashes::sha256;
use bitcoin_hashes::Hash;

hash_newtype!(TestType, sha256::Hash, 32, doc="test");

#[entry]
fn main() -> ! {
hprintln!("Hello world!").unwrap();

debug::exit(debug::EXIT_SUCCESS);

loop {}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
#[cfg(all(test, feature = "unstable"))] extern crate test;

#[cfg(any(test, feature="std"))] pub extern crate core;
#[cfg(any(test, feature="std"))] extern crate core;
#[cfg(feature="serde")] pub extern crate serde;
#[cfg(all(test,feature="serde"))] extern crate serde_test;

Expand Down
28 changes: 14 additions & 14 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ macro_rules! hex_fmt_impl(
hex_fmt_impl!($imp, $ty, );
);
($imp:ident, $ty:ident, $($gen:ident: $gent:ident),*) => (
impl<$($gen: $gent),*> $crate::core::fmt::$imp for $ty<$($gen),*> {
fn fmt(&self, f: &mut $crate::core::fmt::Formatter) -> $crate::core::fmt::Result {
impl<$($gen: $gent),*> ::core::fmt::$imp for $ty<$($gen),*> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use $crate::hex::{format_hex, format_hex_reverse};
if $ty::<$($gen),*>::DISPLAY_BACKWARD {
format_hex_reverse(&self.0, f)
Expand All @@ -49,37 +49,37 @@ macro_rules! index_impl(
index_impl!($ty, );
);
($ty:ident, $($gen:ident: $gent:ident),*) => (
impl<$($gen: $gent),*> $crate::core::ops::Index<usize> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::ops::Index<usize> for $ty<$($gen),*> {
type Output = u8;
fn index(&self, index: usize) -> &u8 {
&self.0[index]
}
}

impl<$($gen: $gent),*> $crate::core::ops::Index<$crate::core::ops::Range<usize>> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::ops::Index<::core::ops::Range<usize>> for $ty<$($gen),*> {
type Output = [u8];
fn index(&self, index: $crate::core::ops::Range<usize>) -> &[u8] {
fn index(&self, index: ::core::ops::Range<usize>) -> &[u8] {
&self.0[index]
}
}

impl<$($gen: $gent),*> $crate::core::ops::Index<$crate::core::ops::RangeFrom<usize>> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::ops::Index<::core::ops::RangeFrom<usize>> for $ty<$($gen),*> {
type Output = [u8];
fn index(&self, index: $crate::core::ops::RangeFrom<usize>) -> &[u8] {
fn index(&self, index: ::core::ops::RangeFrom<usize>) -> &[u8] {
&self.0[index]
}
}

impl<$($gen: $gent),*> $crate::core::ops::Index<$crate::core::ops::RangeTo<usize>> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::ops::Index<::core::ops::RangeTo<usize>> for $ty<$($gen),*> {
type Output = [u8];
fn index(&self, index: $crate::core::ops::RangeTo<usize>) -> &[u8] {
fn index(&self, index: ::core::ops::RangeTo<usize>) -> &[u8] {
&self.0[index]
}
}

impl<$($gen: $gent),*> $crate::core::ops::Index<$crate::core::ops::RangeFull> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::ops::Index<::core::ops::RangeFull> for $ty<$($gen),*> {
type Output = [u8];
fn index(&self, index: $crate::core::ops::RangeFull) -> &[u8] {
fn index(&self, index: ::core::ops::RangeFull) -> &[u8] {
&self.0[index]
}
}
Expand All @@ -93,19 +93,19 @@ macro_rules! borrow_slice_impl(
borrow_slice_impl!($ty, );
);
($ty:ident, $($gen:ident: $gent:ident),*) => (
impl<$($gen: $gent),*> $crate::core::borrow::Borrow<[u8]> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::borrow::Borrow<[u8]> for $ty<$($gen),*> {
fn borrow(&self) -> &[u8] {
&self[..]
}
}

impl<$($gen: $gent),*> $crate::core::convert::AsRef<[u8]> for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::convert::AsRef<[u8]> for $ty<$($gen),*> {
fn as_ref(&self) -> &[u8] {
&self[..]
}
}

impl<$($gen: $gent),*> $crate::core::ops::Deref for $ty<$($gen),*> {
impl<$($gen: $gent),*> ::core::ops::Deref for $ty<$($gen),*> {
type Target = [u8];

fn deref(&self) -> &Self::Target {
Expand Down