diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dde4bc7f1..05cc989d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,8 @@ and this project adheres to - cosmwasm-std: Remove export of `ExternalApi`, `ExternalQuerier` and `ExternalStorage` as those are only needed by export implementations in cosmwasm-std. ([#2467]) +- cosmwasm-std: Add a new `exports` feature which needs to be enabled for the + primary cosmwasm_std dependency of a contract. ## Fixed diff --git a/contracts/cyberpunk/Cargo.toml b/contracts/cyberpunk/Cargo.toml index e16fb8dbdd..ca09a2fe60 100644 --- a/contracts/cyberpunk/Cargo.toml +++ b/contracts/cyberpunk/Cargo.toml @@ -24,6 +24,7 @@ overflow-checks = true cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ "cosmwasm_1_3", + "exports", "std", ] } rust-argon2 = "2.1" diff --git a/contracts/hackatom/Cargo.toml b/contracts/hackatom/Cargo.toml index 9876876e83..ab9947800c 100644 --- a/contracts/hackatom/Cargo.toml +++ b/contracts/hackatom/Cargo.toml @@ -26,6 +26,7 @@ overflow-checks = true cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ "cosmwasm_2_2", + "exports", "std", ] } schemars = "0.8.12" diff --git a/contracts/reflect/Cargo.toml b/contracts/reflect/Cargo.toml index 909b469466..39b13b2bdf 100644 --- a/contracts/reflect/Cargo.toml +++ b/contracts/reflect/Cargo.toml @@ -27,6 +27,7 @@ overflow-checks = true cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ "cosmwasm_2_2", + "exports", "staking", "stargate", "std", diff --git a/contracts/replier/Cargo.toml b/contracts/replier/Cargo.toml index 3759758dc4..191c789c91 100644 --- a/contracts/replier/Cargo.toml +++ b/contracts/replier/Cargo.toml @@ -26,6 +26,7 @@ overflow-checks = true cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ "cosmwasm_1_4", + "exports", "iterator", "std", ] } diff --git a/contracts/staking/Cargo.toml b/contracts/staking/Cargo.toml index 87b50325db..c13a0e9046 100644 --- a/contracts/staking/Cargo.toml +++ b/contracts/staking/Cargo.toml @@ -25,6 +25,7 @@ overflow-checks = true [dependencies] cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ + "exports", "staking", "std", ] } diff --git a/docs/USING_COSMWASM_STD.md b/docs/USING_COSMWASM_STD.md index 2365007881..c4fd9e40fd 100644 --- a/docs/USING_COSMWASM_STD.md +++ b/docs/USING_COSMWASM_STD.md @@ -33,16 +33,16 @@ in the dependency tree. Otherwise conflicting C exports are created. The library comes with the following features: -| Feature | Enabled by default | Description | -| ------------ | ------------------ | ------------------------------------------------------------------------------------ | -| iterator | x | Storage iterators | -| abort | x | DEPRECATED A panic handler that aborts the contract execution with a helpful message | -| stargate | | Cosmos SDK 0.40+ features and IBC | -| staking | | Access to the staking module | -| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain | -| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain | -| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain | -| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain | +| Feature | Enabled by default | Description | +| ------------ | ------------------ | -------------------------------------------------------------------------------- | +| exports | x | Adds exports and imports needed for basic communication between contract and VM. | +| iterator | x | Storage iterators | +| stargate | | Cosmos SDK 0.40+ features and IBC | +| staking | | Access to the staking module | +| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain | +| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain | +| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain | +| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain | ## The cosmwasm-std dependency for contract developers @@ -78,13 +78,13 @@ might move certain existing functionality to that feature in the future. Also libraries should define a loose version range that allows the contract developer to control which cosmwasm-std version they want to use in the final -project. E.g. if your library does not work with 1.0.0 due to a bug fixed in -1.0.1, your min version is 1.0.1 and not the latest stable. +project. E.g. if your library does not work with 3.0.0 due to a bug fixed in +3.0.1, your min version is 3.0.1 and not the latest stable. A typical dependency then looks like this: ```toml -# We really need `stargate` here as this is an IBC related library. `abort` and `iterator` are not needed. +# We really need `stargate` here as this is an IBC related library. `exports` and `iterator` are not needed. # `std` should always stay enabled. -cosmwasm-std = { version = "1.0.1", default-features = false, features = ["std", "stargate"] } +cosmwasm-std = { version = "3.0.1", default-features = false, features = ["std", "stargate"] } ``` diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 61a1c684ef..2999b0ea75 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -12,7 +12,10 @@ readme = "README.md" features = ["cosmwasm_2_2", "staking", "stargate", "ibc2"] [features] -default = ["iterator", "std"] +default = ["exports", "iterator", "std"] +# Enable if this cosmwasm-std is the primary version of cosmwas-std used in the contract. This +# adds exports and imports needed for basic communication between contract and VM. +exports = [] std = [] # iterator allows us to iterate over all DB items in a given range # optional as some merkle stores (like tries) don't support this diff --git a/packages/std/src/exports.rs b/packages/std/src/exports/exports.rs similarity index 99% rename from packages/std/src/exports.rs rename to packages/std/src/exports/exports.rs index 20e8ffac61..679488973e 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports/exports.rs @@ -12,6 +12,9 @@ use core::{marker::PhantomData, ptr}; use serde::de::DeserializeOwned; +use super::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; +use super::memory::{Owned, Region}; +use super::panic::install_panic_handler; use crate::deps::OwnedDeps; #[cfg(any(feature = "stargate", feature = "ibc2"))] use crate::ibc::IbcReceiveResponse; @@ -24,9 +27,6 @@ use crate::ibc::{ use crate::ibc::{IbcChannelOpenMsg, IbcChannelOpenResponse}; #[cfg(feature = "ibc2")] use crate::ibc2::{Ibc2PacketReceiveMsg, Ibc2PacketTimeoutMsg}; -use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; -use crate::memory::{Owned, Region}; -use crate::panic::install_panic_handler; use crate::query::CustomQuery; use crate::results::{ContractResult, QueryResponse, Reply, Response}; use crate::serde::{from_json, to_json_vec}; diff --git a/packages/std/src/imports.rs b/packages/std/src/exports/imports.rs similarity index 99% rename from packages/std/src/imports.rs rename to packages/std/src/exports/imports.rs index b31ed76f66..d68d2229a9 100644 --- a/packages/std/src/imports.rs +++ b/packages/std/src/exports/imports.rs @@ -1,19 +1,18 @@ use alloc::vec::Vec; use core::ptr; +#[cfg(feature = "iterator")] +use super::memory::get_optional_region_address; +use super::memory::{Owned, Region}; use crate::import_helpers::{from_high_half, from_low_half}; -use crate::memory::{Owned, Region}; +#[cfg(feature = "iterator")] +use crate::iterator::{Order, Record}; use crate::results::SystemResult; #[cfg(feature = "iterator")] use crate::sections::decode_sections2; use crate::sections::encode_sections; use crate::serde::from_json; use crate::traits::{Api, Querier, QuerierResult, Storage}; -#[cfg(feature = "iterator")] -use crate::{ - iterator::{Order, Record}, - memory::get_optional_region_address, -}; use crate::{Addr, CanonicalAddr}; #[cfg(feature = "cosmwasm_2_1")] use crate::{AggregationError, HashFunction, PairingEqualityError}; diff --git a/packages/std/src/memory.rs b/packages/std/src/exports/memory.rs similarity index 100% rename from packages/std/src/memory.rs rename to packages/std/src/exports/memory.rs diff --git a/packages/std/src/exports/mod.rs b/packages/std/src/exports/mod.rs new file mode 100644 index 0000000000..84d6aabda9 --- /dev/null +++ b/packages/std/src/exports/mod.rs @@ -0,0 +1,18 @@ +mod exports; +mod imports; +mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines. +mod panic; + +#[cfg(feature = "cosmwasm_2_2")] +pub use exports::do_migrate_with_info; +pub use exports::{ + do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate, + do_query, do_reply, do_sudo, +}; +#[cfg(feature = "ibc2")] +pub use exports::{do_ibc2_packet_receive, do_ibc2_packet_timeout}; +#[cfg(feature = "stargate")] +pub use exports::{ + do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack, + do_ibc_packet_receive, do_ibc_packet_timeout, +}; diff --git a/packages/std/src/panic.rs b/packages/std/src/exports/panic.rs similarity index 94% rename from packages/std/src/panic.rs rename to packages/std/src/exports/panic.rs index 862f2c0ff2..adfab4f34a 100644 --- a/packages/std/src/panic.rs +++ b/packages/std/src/exports/panic.rs @@ -3,7 +3,6 @@ /// /// This overrides any previous panic handler. See /// for details. -#[cfg(target_arch = "wasm32")] pub fn install_panic_handler() { use super::imports::handle_panic; std::panic::set_hook(Box::new(|info| { diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 3960c18548..043036b798 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -33,7 +33,6 @@ mod metadata; mod msgpack; mod never; mod pagination; -mod panic; mod query; mod results; mod sections; @@ -115,24 +114,23 @@ pub use crate::timestamp::Timestamp; pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage}; pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo}; -// Exposed in wasm build only -#[cfg(target_arch = "wasm32")] +// +// Exports +// + +#[cfg(all(feature = "exports", target_arch = "wasm32"))] mod exports; -#[cfg(target_arch = "wasm32")] -mod imports; -#[cfg(target_arch = "wasm32")] -mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines. -#[cfg(all(feature = "cosmwasm_2_2", target_arch = "wasm32"))] +#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "cosmwasm_2_2"))] pub use crate::exports::do_migrate_with_info; -#[cfg(target_arch = "wasm32")] +#[cfg(all(feature = "exports", target_arch = "wasm32"))] pub use crate::exports::{ do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate, do_query, do_reply, do_sudo, }; -#[cfg(all(feature = "ibc2", target_arch = "wasm32"))] +#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "ibc2"))] pub use crate::exports::{do_ibc2_packet_receive, do_ibc2_packet_timeout}; -#[cfg(all(feature = "stargate", target_arch = "wasm32"))] +#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "stargate"))] pub use crate::exports::{ do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack, do_ibc_packet_receive, do_ibc_packet_timeout,