Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix dep job, add feature-checks job #64

Merged
merged 1 commit into from
Jun 4, 2023
Merged
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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ jobs:
- name: test
run: cargo test --workspace ${{ matrix.flags }}

feature-checks:
name: feature checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
- name: cargo hack
run: cargo hack check --feature-powerset --depth 2 --all-targets

clippy:
name: clippy
runs-on: ubuntu-latest
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/deny.yml → .github/workflows/deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ name: deps
on:
push:
branches: [main]
paths: [Cargo.lock]
pull_request:
branches: [main]
paths: [Cargo.lock]

concurrency: deps-${{ github.head_ref || github.run_id }}
schedule: [cron: "00 00 * * *"]

jobs:
deny:
name: deny
cargo-deny:
name: cargo deny check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: "recursive"
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check all
1 change: 1 addition & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ std = ["bytes/std", "hex/std", "ethers-rlp?/std", "proptest?/std", "serde/std"]
rlp = ["dep:ethers-rlp", "ruint/fastrlp"]
serde = ["dep:serde", "bytes/serde", "hex/serde", "ruint/serde"]
arbitrary = [
"std",
"ruint/arbitrary",
"ruint/proptest",
"dep:arbitrary",
Expand Down
3 changes: 1 addition & 2 deletions crates/rlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ hex-literal.workspace = true

[features]
default = ["std", "derive"]
std = ["arrayvec/std", "bytes/std"]
derive = ["dep:ethers-rlp-derive"]
std = ["alloc", "arrayvec/std", "bytes/std"]
alloc = []
4 changes: 2 additions & 2 deletions crates/rlp/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ mod std_impl {
}
}

#[cfg(feature = "alloc")]
mod alloc_impl {
use super::*;

Expand Down Expand Up @@ -387,7 +386,7 @@ mod alloc_impl {
}
}

#[cfg(all(test, feature = "alloc"))]
#[cfg(test)]
mod tests {
use super::*;
use alloc::{string::String, vec::Vec};
Expand Down Expand Up @@ -498,6 +497,7 @@ mod tests {
(Err(DecodeError::InputTooShort), &hex!("C1")[..]),
(Err(DecodeError::InputTooShort), &hex!("D7")[..]),
]);
#[cfg(feature = "std")]
check_decode::<std::net::IpAddr, _>(vec![
(Err(DecodeError::InputTooShort), &hex!("C1")[..]),
(Err(DecodeError::InputTooShort), &hex!("D7")[..]),
Expand Down
151 changes: 73 additions & 78 deletions crates/rlp/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,78 @@ max_encoded_len_uint!(u128);

impl_max_encoded_len!(bool, <u8 as MaxEncodedLenAssoc>::LEN);

impl<'a, T: ?Sized + alloc::borrow::ToOwned + Encodable> Encodable for alloc::borrow::Cow<'a, T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::boxed::Box<T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::rc::Rc<T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::sync::Arc<T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: Encodable> Encodable for alloc::vec::Vec<T> {
#[inline]
fn length(&self) -> usize {
list_length(self)
}

#[inline]
fn encode(&self, out: &mut dyn BufMut) {
encode_list(self, out)
}
}

impl Encodable for alloc::string::String {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
self.as_bytes().encode(out);
}

#[inline]
fn length(&self) -> usize {
self.as_bytes().length()
}
}

#[cfg(feature = "std")]
mod std_support {
use super::*;
Expand Down Expand Up @@ -245,83 +317,6 @@ mod std_support {
}
}

#[cfg(feature = "alloc")]
mod alloc_support {
use super::*;

impl<'a, T: ?Sized + alloc::borrow::ToOwned + Encodable> Encodable for alloc::borrow::Cow<'a, T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::boxed::Box<T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::rc::Rc<T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::sync::Arc<T> {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

#[inline]
fn length(&self) -> usize {
(**self).length()
}
}

impl<T: Encodable> Encodable for alloc::vec::Vec<T> {
#[inline]
fn length(&self) -> usize {
list_length(self)
}

#[inline]
fn encode(&self, out: &mut dyn BufMut) {
encode_list(self, out)
}
}

impl Encodable for alloc::string::String {
#[inline]
fn encode(&self, out: &mut dyn BufMut) {
self.as_bytes().encode(out);
}

#[inline]
fn length(&self) -> usize {
self.as_bytes().length()
}
}
}

macro_rules! slice_impl {
($t:ty) => {
impl $crate::Encodable for $t {
Expand Down Expand Up @@ -415,7 +410,7 @@ pub fn encode_fixed_size<E: MaxEncodedLen<LEN>, const LEN: usize>(v: &E) -> Arra
out
}

#[cfg(all(test, feature = "alloc"))]
#[cfg(test)]
mod tests {
use super::*;
use bytes::BytesMut;
Expand Down
3 changes: 2 additions & 1 deletion crates/rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ fn main() {
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "alloc")]
#[macro_use]
#[allow(unused_imports)]
extern crate alloc;

// Used in alloc tests.
Expand Down
4 changes: 1 addition & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ exceptions = [
# so we prefer to not have dependencies using it
# https://tldrlegal.com/license/creative-commons-cc0-1.0-universal
{ allow = ["CC0-1.0"], name = "tiny-keccak" },
{ allow = ["CC0-1.0"], name = "trezor-client" },
{ allow = ["CC0-1.0"], name = "constant_time_eq" },
]

[[licenses.clarify]]
Expand All @@ -86,4 +84,4 @@ license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
unknown-registry = "deny"
# Lint level for what to happen when a crate from a git repository that is not
# in the allow list is encountered
unknown-git = "deny"
unknown-git = "warn" # TODO: switch back to deny once `ruint` is released