Skip to content

Commit

Permalink
Enable #![no_std] (#579)
Browse files Browse the repository at this point in the history
* Enable #![no_std]

* database-sled depends on std

* Add comment

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tomaka and mergify[bot] committed Apr 8, 2021
1 parent 0ba1bec commit c6a32af
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
default = ["database-sled", "std"]
database-sled = [
"sled",
"std" # A database stored on the filesystem can't reasonably work without a filesystem.
]
std = [
"async-std",
Expand Down
2 changes: 1 addition & 1 deletion src/author/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::{
util,
};

use alloc::{string::String, vec::Vec};
use alloc::{borrow::ToOwned as _, string::String, vec::Vec};
use core::{iter, mem};
use hashbrown::HashMap;

Expand Down
2 changes: 1 addition & 1 deletion src/chain/chain_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use crate::{finality::grandpa, header};

use alloc::vec::Vec;
use alloc::{borrow::ToOwned as _, vec::Vec};
use core::num::NonZeroU64;

pub mod aura_config;
Expand Down
2 changes: 1 addition & 1 deletion src/chain/sync/all_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ use crate::{
header, verify,
};

use alloc::collections::VecDeque;
use alloc::{collections::VecDeque, vec::Vec};
use core::{
iter, mem,
num::{NonZeroU32, NonZeroU64},
Expand Down
5 changes: 4 additions & 1 deletion src/chain/sync/all_forks/pending_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
use crate::header;

use alloc::collections::{BTreeMap, BTreeSet};
use alloc::{
collections::{BTreeMap, BTreeSet},
vec::Vec,
};
use core::{
convert::TryFrom as _,
num::{NonZeroU32, NonZeroU64},
Expand Down
2 changes: 1 addition & 1 deletion src/chain/sync/all_forks/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! - An opaque user data, of type `TSrc`.
//!
use alloc::collections::BTreeSet;
use alloc::{collections::BTreeSet, vec::Vec};
use core::fmt;

/// Identifier for a source in the [`AllForksSources`].
Expand Down
2 changes: 2 additions & 0 deletions src/chain/sync/grandpa_warp_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::{
network::protocol::GrandpaWarpSyncResponse,
};

use alloc::vec::Vec;

/// Problem encountered during a call to [`grandpa_warp_sync`].
#[derive(Debug, derive_more::Display)]
pub enum Error {
Expand Down
1 change: 1 addition & 0 deletions src/chain/sync/optimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use crate::{
};

use alloc::{
borrow::ToOwned as _,
collections::{BTreeMap, VecDeque},
vec::Vec,
};
Expand Down
2 changes: 1 addition & 1 deletion src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use crate::chain::chain_information::{
BabeEpochInformation, ChainInformation, ChainInformationConsensus, ChainInformationFinality,
};
use alloc::string::String;
use alloc::{string::String, vec::Vec};
use core::num::NonZeroU64;

mod light_sync_state;
Expand Down
2 changes: 1 addition & 1 deletion src/chain_spec/light_sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::header::BabeNextConfig;

use alloc::{collections::BTreeMap, vec::Vec};
use alloc::{collections::BTreeMap, format, string::String, vec::Vec};
use parity_scale_codec::{Decode, DecodeAll as _, Encode};
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/chain_spec/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use super::light_sync_state::LightSyncState;

use alloc::{boxed::Box, string::String, vec::Vec};
use alloc::{boxed::Box, format, string::String, vec::Vec};
use fnv::FnvBuildHasher;
use hashbrown::{HashMap, HashSet};
use serde::{Deserialize, Serialize};
Expand Down
1 change: 1 addition & 0 deletions src/database/finalized_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use crate::chain::chain_information;

use alloc::{string::String, vec::Vec};
use core::iter;
use hashbrown::HashMap;

Expand Down
5 changes: 4 additions & 1 deletion src/executor/read_only_runtime_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

use crate::executor::{self, host, vm};

use alloc::{string::String, vec::Vec};
use alloc::{
string::{String, ToString as _},
vec::Vec,
};
use core::{fmt, iter};

/// Configuration for [`run`].
Expand Down
5 changes: 4 additions & 1 deletion src/executor/runtime_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ use crate::{
util,
};

use alloc::{string::String, vec::Vec};
use alloc::{
string::{String, ToString as _},
vec::Vec,
};
use core::{fmt, iter, slice};
use hashbrown::{HashMap, HashSet};

Expand Down
2 changes: 1 addition & 1 deletion src/executor/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod interpreter;
#[cfg(all(target_arch = "x86_64", feature = "std"))]
mod jit;

use alloc::vec::Vec;
use alloc::{string::String, vec::Vec};
use core::{convert::TryFrom, fmt};
use smallvec::SmallVec;

Expand Down
2 changes: 1 addition & 1 deletion src/executor/vm/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
Signature, StartErr, Trap, ValueType, WasmValue,
};

use alloc::{borrow::ToOwned as _, boxed::Box, format, sync::Arc, vec::Vec};
use alloc::{borrow::ToOwned as _, boxed::Box, format, string::ToString as _, sync::Arc, vec::Vec};
use core::{
cell::RefCell,
convert::{TryFrom, TryInto as _},
Expand Down
2 changes: 1 addition & 1 deletion src/finality/grandpa/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
header,
};

use alloc::vec::Vec;
use alloc::{borrow::ToOwned as _, vec::Vec};
use core::num::NonZeroU64;
use parity_scale_codec::DecodeAll as _;

Expand Down
2 changes: 2 additions & 0 deletions src/finality/grandpa/warp_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::finality::justification::verify::{
use crate::header::{DigestItemRef, GrandpaConsensusLogRef, Header};
use crate::network::protocol::GrandpaWarpSyncResponseFragment;

use alloc::vec::Vec;

#[derive(Debug, derive_more::Display)]
pub enum Error {
#[display(fmt = "{}", _0)]
Expand Down
2 changes: 1 addition & 1 deletion src/finality/justification/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct PrecommitsRefIter<'a> {
}

enum PrecommitsRefIterInner<'a> {
Decoded(std::slice::Iter<'a, Precommit>),
Decoded(core::slice::Iter<'a, Precommit>),
Undecoded {
remaining_len: usize,
pointer: &'a [u8],
Expand Down
9 changes: 8 additions & 1 deletion src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
use super::parse;
use crate::util;
use alloc::{format, string::String, vec::Vec};

use alloc::{
borrow::ToOwned as _,
boxed::Box,
format,
string::{String, ToString as _},
vec::Vec,
};
use core::convert::TryFrom as _;

/// Parses a JSON call (usually received from a JSON-RPC server).
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@
//! - TODO: telemetry
//!
// TODO: for `no_std`, fix all the compilation errors caused by the copy-pasted code
//#![cfg_attr(not(any(test, feature = "std")), no_std)]
// The library part of `smoldot` should as pure as possible and shouldn't rely on any environment
// such as a file system, environment variables, time, randomness, etc.
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![deny(broken_intra_doc_links)]
#![deny(unused_crate_dependencies)]

Expand Down
2 changes: 1 addition & 1 deletion src/libp2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
// the substream which is thought to be the old one but is actually the new one.
//

use alloc::sync::Arc;
use alloc::{string::String, sync::Arc, vec::Vec};
use connection::established;
use core::{
iter, mem,
Expand Down
5 changes: 4 additions & 1 deletion src/libp2p/connection/established.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ use crate::util::leb128;

use super::{multistream_select, noise, yamux};

use alloc::vec::{self, Vec};
use alloc::{
string::String,
vec::{self, Vec},
};
use core::{
cmp, fmt, iter, mem,
ops::{Add, Sub},
Expand Down
2 changes: 1 addition & 1 deletion src/libp2p/connection/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use super::{
yamux,
};

use alloc::vec;
use alloc::{boxed::Box, vec};
use core::{fmt, iter};

mod tests;
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
use crate::executor::{host, read_only_runtime_host};

use alloc::vec::Vec;
use alloc::{borrow::ToOwned as _, vec::Vec};

/// Retrieves the SCALE-encoded metadata from the given virtual machine prototype.
///
Expand Down
2 changes: 1 addition & 1 deletion src/network/protocol/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use super::schema;
use crate::libp2p::{peer_id::PublicKey, Multiaddr};

use alloc::vec::Vec;
use alloc::{borrow::ToOwned as _, vec::Vec};
use core::iter;
use prost::Message as _;

Expand Down
6 changes: 6 additions & 0 deletions src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ use crate::libp2p::{
};
use crate::network::protocol;
use crate::util;

use alloc::{
format,
string::{String, ToString as _},
vec::Vec,
};
use core::{
fmt, iter,
num::NonZeroUsize,
Expand Down
2 changes: 1 addition & 1 deletion src/trie/trie_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use super::nibble::Nibble;

use alloc::vec::Vec;
use alloc::{borrow::ToOwned as _, vec::Vec};
use core::{convert::TryFrom as _, fmt, iter};
use either::Either;
use slab::Slab;
Expand Down

0 comments on commit c6a32af

Please sign in to comment.