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

no_std support #26

Closed
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
131 changes: 74 additions & 57 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "cw-storage-plus"
version = "1.0.1"
version = "1.0.2"
authors = ["Ethan Frey <[email protected]>"]
edition = "2021"
description = "Enhanced storage engines"
Expand All @@ -14,18 +14,19 @@ homepage = "https://cosmwasm.com"
all-features = true # include macro feature when building docs

[features]
default = ["iterator"]
default = ["iterator", "std"]
iterator = ["cosmwasm-std/iterator"]
macro = ["cw-storage-macro"]
std = ["cosmwasm-std/std", "schemars"]

[lib]
# See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false

[dependencies]
cosmwasm-std = { version = "1.1.6", default-features = false }
schemars = "0.8.3"
serde = { version = "1.0", default-features = false, features = ["derive"] }
cosmwasm-std = { git = "https://github.com/dzmitry-lahoda-forks/cosmwasm.git", rev = "1277597cbf380a8d04dbe676d9cb344ca31634b6", default-features = false }
schemars = { version = "0.8.3", optional = true}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import alloc only when no std would be better, right?

cw-storage-macro = { version = "1.0.0", optional = true, path = "macros" }

[dev-dependencies]
Expand Down
11 changes: 11 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[toolchain]
channel = "nightly-2022-11-17"
components = [
"rust-src",
"cargo",
]
targets = [
"wasm32-unknown-unknown",
# that is the way to test that it checks and builds againt no_std target
"thumbv7em-none-eabi"
]
24 changes: 24 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ pkgs ? import <nixpkgs> { overlays = [ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/refs/heads/stable.zip")) ]; } }:
let
rust-as-on-ci = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
features = " --features iterator";
package="cw-storage-plus";
check-no-std = pkgs.writeShellApplication rec {
name = "check-no-std";
runtimeInputs = [ rust-as-on-ci ];
text = ''
cargo build --no-default-features --target thumbv7em-none-eabi --package ${package} ${features}
'';
};
check-std = pkgs.writeShellApplication rec {
name = "check-std";
runtimeInputs = [ rust-as-on-ci ];
text = ''
cargo build --target wasm32-unknown-unknown ${features},std --package ${package}
cargo build ${features},std --package ${package}
'';
};
in
pkgs.mkShell {
nativeBuildInputs = [ rust-as-on-ci check-no-std check-std];
}
3 changes: 2 additions & 1 deletion src/bound.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![cfg(feature = "iterator")]

use crate::no_std::marker::PhantomData;
use crate::no_std::prelude::*;
use cosmwasm_std::Addr;
use std::marker::PhantomData;

use crate::de::KeyDeserialize;
use crate::{Prefixer, PrimaryKey};
Expand Down
7 changes: 4 additions & 3 deletions src/de.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::array::TryFromSliceError;
use std::convert::TryInto;

use crate::no_std::array::TryFromSliceError;
use crate::no_std::convert::TryInto;
use crate::no_std::prelude::*;
use cosmwasm_std::{Addr, StdError, StdResult};

use crate::int_key::IntKey;
Expand Down Expand Up @@ -199,6 +199,7 @@ impl<T: KeyDeserialize, U: KeyDeserialize, V: KeyDeserialize> KeyDeserialize for
#[cfg(test)]
mod test {
use super::*;
use crate::no_std::prelude::*;
use crate::PrimaryKey;

const BYTES: &[u8] = b"Hello";
Expand Down
Loading