Skip to content

Commit 02673cd

Browse files
authored
Merge pull request #2470 from CosmWasm/exports-feature
Add "exports" feature
2 parents af40836 + e27ef1d commit 02673cd

File tree

14 files changed

+60
-36
lines changed

14 files changed

+60
-36
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ and this project adheres to
7878
- cosmwasm-std: Remove export of `ExternalApi`, `ExternalQuerier` and
7979
`ExternalStorage` as those are only needed by export implementations in
8080
cosmwasm-std. ([#2467])
81+
- cosmwasm-std: Add a new `exports` feature which needs to be enabled for the
82+
primary cosmwasm_std dependency of a contract.
8183

8284
## Fixed
8385

contracts/cyberpunk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ overflow-checks = true
2424
cosmwasm-schema = { path = "../../packages/schema" }
2525
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
2626
"cosmwasm_1_3",
27+
"exports",
2728
"std",
2829
] }
2930
rust-argon2 = "2.1"

contracts/hackatom/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ overflow-checks = true
2626
cosmwasm-schema = { path = "../../packages/schema" }
2727
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
2828
"cosmwasm_2_2",
29+
"exports",
2930
"std",
3031
] }
3132
schemars = "0.8.12"

contracts/reflect/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ overflow-checks = true
2727
cosmwasm-schema = { path = "../../packages/schema" }
2828
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
2929
"cosmwasm_2_2",
30+
"exports",
3031
"staking",
3132
"stargate",
3233
"std",

contracts/replier/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ overflow-checks = true
2626
cosmwasm-schema = { path = "../../packages/schema" }
2727
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
2828
"cosmwasm_1_4",
29+
"exports",
2930
"iterator",
3031
"std",
3132
] }

contracts/staking/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ overflow-checks = true
2525
[dependencies]
2626
cosmwasm-schema = { path = "../../packages/schema" }
2727
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
28+
"exports",
2829
"staking",
2930
"std",
3031
] }

docs/USING_COSMWASM_STD.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ in the dependency tree. Otherwise conflicting C exports are created.
3333

3434
The library comes with the following features:
3535

36-
| Feature | Enabled by default | Description |
37-
| ------------ | ------------------ | ------------------------------------------------------------------------------------ |
38-
| iterator | x | Storage iterators |
39-
| abort | x | DEPRECATED A panic handler that aborts the contract execution with a helpful message |
40-
| stargate | | Cosmos SDK 0.40+ features and IBC |
41-
| staking | | Access to the staking module |
42-
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
43-
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
44-
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
45-
| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain |
36+
| Feature | Enabled by default | Description |
37+
| ------------ | ------------------ | -------------------------------------------------------------------------------- |
38+
| exports | x | Adds exports and imports needed for basic communication between contract and VM. |
39+
| iterator | x | Storage iterators |
40+
| stargate | | Cosmos SDK 0.40+ features and IBC |
41+
| staking | | Access to the staking module |
42+
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
43+
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
44+
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
45+
| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain |
4646

4747
## The cosmwasm-std dependency for contract developers
4848

@@ -78,13 +78,13 @@ might move certain existing functionality to that feature in the future.
7878

7979
Also libraries should define a loose version range that allows the contract
8080
developer to control which cosmwasm-std version they want to use in the final
81-
project. E.g. if your library does not work with 1.0.0 due to a bug fixed in
82-
1.0.1, your min version is 1.0.1 and not the latest stable.
81+
project. E.g. if your library does not work with 3.0.0 due to a bug fixed in
82+
3.0.1, your min version is 3.0.1 and not the latest stable.
8383

8484
A typical dependency then looks like this:
8585

8686
```toml
87-
# We really need `stargate` here as this is an IBC related library. `abort` and `iterator` are not needed.
87+
# We really need `stargate` here as this is an IBC related library. `exports` and `iterator` are not needed.
8888
# `std` should always stay enabled.
89-
cosmwasm-std = { version = "1.0.1", default-features = false, features = ["std", "stargate"] }
89+
cosmwasm-std = { version = "3.0.1", default-features = false, features = ["std", "stargate"] }
9090
```

packages/std/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ readme = "README.md"
1212
features = ["cosmwasm_2_2", "staking", "stargate", "ibc2"]
1313

1414
[features]
15-
default = ["iterator", "std"]
15+
default = ["exports", "iterator", "std"]
16+
# Enable if this cosmwasm-std is the primary version of cosmwas-std used in the contract. This
17+
# adds exports and imports needed for basic communication between contract and VM.
18+
exports = []
1619
std = []
1720
# iterator allows us to iterate over all DB items in a given range
1821
# optional as some merkle stores (like tries) don't support this

packages/std/src/exports.rs renamed to packages/std/src/exports/exports.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use core::{marker::PhantomData, ptr};
1212

1313
use serde::de::DeserializeOwned;
1414

15+
use super::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
16+
use super::memory::{Owned, Region};
17+
use super::panic::install_panic_handler;
1518
use crate::deps::OwnedDeps;
1619
#[cfg(any(feature = "stargate", feature = "ibc2"))]
1720
use crate::ibc::IbcReceiveResponse;
@@ -24,9 +27,6 @@ use crate::ibc::{
2427
use crate::ibc::{IbcChannelOpenMsg, IbcChannelOpenResponse};
2528
#[cfg(feature = "ibc2")]
2629
use crate::ibc2::{Ibc2PacketReceiveMsg, Ibc2PacketTimeoutMsg};
27-
use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
28-
use crate::memory::{Owned, Region};
29-
use crate::panic::install_panic_handler;
3030
use crate::query::CustomQuery;
3131
use crate::results::{ContractResult, QueryResponse, Reply, Response};
3232
use crate::serde::{from_json, to_json_vec};

packages/std/src/imports.rs renamed to packages/std/src/exports/imports.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
use alloc::vec::Vec;
22
use core::ptr;
33

4+
#[cfg(feature = "iterator")]
5+
use super::memory::get_optional_region_address;
6+
use super::memory::{Owned, Region};
47
use crate::import_helpers::{from_high_half, from_low_half};
5-
use crate::memory::{Owned, Region};
8+
#[cfg(feature = "iterator")]
9+
use crate::iterator::{Order, Record};
610
use crate::results::SystemResult;
711
#[cfg(feature = "iterator")]
812
use crate::sections::decode_sections2;
913
use crate::sections::encode_sections;
1014
use crate::serde::from_json;
1115
use crate::traits::{Api, Querier, QuerierResult, Storage};
12-
#[cfg(feature = "iterator")]
13-
use crate::{
14-
iterator::{Order, Record},
15-
memory::get_optional_region_address,
16-
};
1716
use crate::{Addr, CanonicalAddr};
1817
#[cfg(feature = "cosmwasm_2_1")]
1918
use crate::{AggregationError, HashFunction, PairingEqualityError};

0 commit comments

Comments
 (0)