From 544fcd0c92da264c14df3f0aef4025b2ba5170b7 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Wed, 15 May 2019 07:17:02 -0400 Subject: [PATCH 01/12] support no-std for parity-bytes --- parity-bytes/Cargo.toml | 6 ++++++ parity-bytes/src/lib.rs | 25 ++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/parity-bytes/Cargo.toml b/parity-bytes/Cargo.toml index ea782b24d..758e238dc 100644 --- a/parity-bytes/Cargo.toml +++ b/parity-bytes/Cargo.toml @@ -7,3 +7,9 @@ description = "byte utilities for Parity" license = "GPL-3.0" [dependencies] + + +[features] +default = ["std","nostd"] +std = [] +nostd = [] diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 03b474559..6247acc0d 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -19,9 +19,28 @@ //! Includes a pretty-printer for bytes, in the form of `ToPretty` and `PrettySlice` //! as -use std::fmt; -use std::cmp::min; -use std::ops::{Deref, DerefMut}; +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(alloc))] + +#[cfg(not(feature = "std"))] +extern crate alloc; + +// Re-export libcore using an alias so that the macros can work without +// requiring `extern crate core` downstream. +#[doc(hidden)] +pub extern crate core as core_; + +use core_::{ + cmp::min, + fmt, + ops::{Deref, DerefMut}, +}; + +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + +#[cfg(feature = "std")] +use std::vec::Vec; /// Slice pretty print helper pub struct PrettySlice<'a> (&'a [u8]); From 7ca23a6a85b9c2d32494e249e4c05c74d2486f1c Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Wed, 15 May 2019 07:31:53 -0400 Subject: [PATCH 02/12] remove nostd feature --- parity-bytes/Cargo.toml | 3 +-- parity-bytes/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/parity-bytes/Cargo.toml b/parity-bytes/Cargo.toml index 758e238dc..92af4a511 100644 --- a/parity-bytes/Cargo.toml +++ b/parity-bytes/Cargo.toml @@ -10,6 +10,5 @@ license = "GPL-3.0" [features] -default = ["std","nostd"] +default = ["std"] std = [] -nostd = [] diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 6247acc0d..20951a6e7 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -20,7 +20,6 @@ //! as #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(not(feature = "std"), feature(alloc))] #[cfg(not(feature = "std"))] extern crate alloc; From 8421dc3fc31650b0900d44d423e70d5816eb57f9 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Wed, 15 May 2019 07:52:07 -0400 Subject: [PATCH 03/12] feature(alloc) is stable until 1.36 --- parity-bytes/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 20951a6e7..9a1ea8d0f 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -20,11 +20,12 @@ //! as #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(alloc))] #[cfg(not(feature = "std"))] extern crate alloc; -// Re-export libcore using an alias so that the macros can work without +// Re-export libcore using an alias so that possible macros can work without // requiring `extern crate core` downstream. #[doc(hidden)] pub extern crate core as core_; From f1ad6ade40679c8fe233080a3213a5ba719f6435 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Wed, 15 May 2019 08:23:09 -0400 Subject: [PATCH 04/12] fix cargo +nightly test --no-default-features --- parity-bytes/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 9a1ea8d0f..e1e94b094 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -23,9 +23,10 @@ #![cfg_attr(not(feature = "std"), feature(alloc))] #[cfg(not(feature = "std"))] +#[macro_use] extern crate alloc; -// Re-export libcore using an alias so that possible macros can work without +// Re-export libcore using an alias so that possible backward macros could work without // requiring `extern crate core` downstream. #[doc(hidden)] pub extern crate core as core_; @@ -42,6 +43,9 @@ use alloc::vec::Vec; #[cfg(feature = "std")] use std::vec::Vec; +#[cfg(not(feature = "std"))] +use alloc::string::String; + /// Slice pretty print helper pub struct PrettySlice<'a> (&'a [u8]); From 44022f084aa7a5103eb1a98b3cc23a4337fd9332 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Wed, 15 May 2019 08:29:35 -0400 Subject: [PATCH 05/12] add Readme.md --- parity-bytes/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 parity-bytes/README.md diff --git a/parity-bytes/README.md b/parity-bytes/README.md new file mode 100644 index 000000000..ada12564a --- /dev/null +++ b/parity-bytes/README.md @@ -0,0 +1,11 @@ +## `no_std` crates + +This crate has a feature, `std`, that is enabled by default. To use this crate +in a `no_std` context, add the following to your `Cargo.toml` (still requires allocator though): + +```toml +[dependencies] +parity-bytes = { version = "0.1.0", default-features = false } +``` + +Until allocator api is stabilized, this type of use is limited to nightly Rust. From 979aefa1ab4bce6990177ace9bef42c4807f7790 Mon Sep 17 00:00:00 2001 From: bradyjoestar Date: Wed, 15 May 2019 09:31:22 -0400 Subject: [PATCH 06/12] Update parity-bytes/README.md Co-Authored-By: Andronik Ordian --- parity-bytes/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity-bytes/README.md b/parity-bytes/README.md index ada12564a..27936d3c7 100644 --- a/parity-bytes/README.md +++ b/parity-bytes/README.md @@ -1,4 +1,4 @@ -## `no_std` crates +## `no_std` support This crate has a feature, `std`, that is enabled by default. To use this crate in a `no_std` context, add the following to your `Cargo.toml` (still requires allocator though): From 5b6a0a0143d5c7def4abf1ebf10a21a57cc88372 Mon Sep 17 00:00:00 2001 From: bradyjoestar Date: Wed, 15 May 2019 09:31:53 -0400 Subject: [PATCH 07/12] Update parity-bytes/README.md Co-Authored-By: Andronik Ordian --- parity-bytes/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity-bytes/README.md b/parity-bytes/README.md index 27936d3c7..b1d3a3af0 100644 --- a/parity-bytes/README.md +++ b/parity-bytes/README.md @@ -5,7 +5,7 @@ in a `no_std` context, add the following to your `Cargo.toml` (still requires al ```toml [dependencies] -parity-bytes = { version = "0.1.0", default-features = false } +parity-bytes = { version = "0.1.1", default-features = false } ``` Until allocator api is stabilized, this type of use is limited to nightly Rust. From bc08d4373e8514e49c1a47d3cd79762798438913 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Wed, 15 May 2019 22:01:52 -0400 Subject: [PATCH 08/12] add test in travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 16d70c362..c41f4b36d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ script: - cargo check --all --tests - cargo build --all - cargo test --all --exclude uint --exclude fixed-hash + - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cd parity-bytes/ && cargo build --no-default-features && cd ..; + fi - cd fixed-hash/ && cargo test --all-features && cd .. - cd uint/ && cargo test --features=std,quickcheck --release && cd .. - cd plain_hasher/ && cargo test --no-default-features && cd .. From 6fddc6e8aa04d3bfc6d36cff45b2518105f48cf6 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Thu, 16 May 2019 03:39:47 -0400 Subject: [PATCH 09/12] fix re-export --- parity-bytes/README.md | 2 +- parity-bytes/src/lib.rs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/parity-bytes/README.md b/parity-bytes/README.md index b1d3a3af0..c3503a19e 100644 --- a/parity-bytes/README.md +++ b/parity-bytes/README.md @@ -5,7 +5,7 @@ in a `no_std` context, add the following to your `Cargo.toml` (still requires al ```toml [dependencies] -parity-bytes = { version = "0.1.1", default-features = false } +parity-bytes = { version = "0.1", default-features = false } ``` Until allocator api is stabilized, this type of use is limited to nightly Rust. diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index e1e94b094..8985ca872 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -26,12 +26,10 @@ #[macro_use] extern crate alloc; -// Re-export libcore using an alias so that possible backward macros could work without -// requiring `extern crate core` downstream. #[doc(hidden)] -pub extern crate core as core_; +extern crate core; -use core_::{ +use core::{ cmp::min, fmt, ops::{Deref, DerefMut}, From 7c73083d22bfe18ffe33538e8a01b31e397781a6 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Thu, 16 May 2019 04:10:04 -0400 Subject: [PATCH 10/12] fix bug --- parity-bytes/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 8985ca872..d23cf865b 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -26,9 +26,6 @@ #[macro_use] extern crate alloc; -#[doc(hidden)] -extern crate core; - use core::{ cmp::min, fmt, From afabd6114a693d0f26bbd60877aba9b909761e68 Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Thu, 16 May 2019 04:15:21 -0400 Subject: [PATCH 11/12] revert --- parity-bytes/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index d23cf865b..e1e94b094 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -26,7 +26,12 @@ #[macro_use] extern crate alloc; -use core::{ +// Re-export libcore using an alias so that possible backward macros could work without +// requiring `extern crate core` downstream. +#[doc(hidden)] +pub extern crate core as core_; + +use core_::{ cmp::min, fmt, ops::{Deref, DerefMut}, From 617df718b0bbea04f5bb2ac507d4abdb7f77a0fa Mon Sep 17 00:00:00 2001 From: "webb.shi" Date: Thu, 16 May 2019 04:52:18 -0400 Subject: [PATCH 12/12] import core when --- parity-bytes/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index e1e94b094..7cd965c01 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -26,12 +26,10 @@ #[macro_use] extern crate alloc; -// Re-export libcore using an alias so that possible backward macros could work without -// requiring `extern crate core` downstream. -#[doc(hidden)] -pub extern crate core as core_; +#[cfg(feature = "std")] +extern crate core; -use core_::{ +use core::{ cmp::min, fmt, ops::{Deref, DerefMut},