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

Using std package without exports for target=wasm32 #1962

Open
kromsten opened this issue Nov 20, 2023 · 3 comments
Open

Using std package without exports for target=wasm32 #1962

kromsten opened this issue Nov 20, 2023 · 3 comments

Comments

@kromsten
Copy link

When a project references cosmwasm_std crate as one of the dependencies and is being compiled to wasm32 architecture, the package injects entrypoint exports into the final wasm build

#[cfg(target_arch = "wasm32")]
pub use crate::exports::{do_execute, do_instantiate, do_migrate, do_query, do_reply, do_sudo};

It might not be desirable when developing interfaces and libraries that only need certain types like Binary, Uint128and so on.

It unnecessarily increases the size when building for Javascript environment and causes issues when building for virtual machines with custom constraints

A possible solution would be to only inject the exports when referencing cosmwasm contract specific entities like entrypoint or to provide additional feature flag for the crate (e.g. library) for opting out of injection

@webmaster128
Copy link
Member

Good point. I thought about this from time to time too in the past but it was never a priority to fix. Could be done using a macro you need to call explicitly from a contract.

Could you explain the use case in mode detail, specially the envorinment you want to use this in and the goal of your project? So far all JavaScript usage is clients and they don't really need the types as Addr, Uint128 and Binary are simply strings in the JSON interface.

@webmaster128
Copy link
Member

Also is your problem exports or imports?

  • Exports is functionality provided by the contract to the env (e.g. allocate, requires_iterator, execute)
  • Imports is something the contact requires from the host (e.g. abort, secp256k1_verify)

@kromsten
Copy link
Author

The javascript issue is indeed not of higher priority. Compiling for javascript solely for porting the primitives wouldn't make sense for sure. However if it was a library that uses those primitives for an algorithm or a complex function it can be beneficial to use the same code in multiple environments. Possible some performance improvements for JS if it is doing cryptography or matrix calculations

What I am personally face right now is issues caused by referencing an interface package that depends on cosmwam-std and trying to compile it for a different virtual machine.

Here is a package I am trying to reference but I believe it is going to be identical with cw1 it is extending or any other package for that matter

If I try to reference the package from a project that uses a fork of the cosmwasm it will fail since both of the version are injecting the same exports on build (on target_arch = wasm32)

note: rust-lld: error: duplicate symbol: interface_version_8
          >>> defined in /project_path/target/wasm32-unknown-unknown/release/deps/libsecret_cosmwasm_std-c4688300c5c7376b.rlib(secret_cosmwasm_std-c4688300c5c7376b.secret_cosmwasm_std.ad677aa44ba95ce7-cgu.14.rcgu.o)
          >>> defined in /project_path/target/wasm32-unknown-unknown/release/deps/libcosmwasm_std-c39caa4aaadbfe82.rlib(cosmwasm_std-c39caa4aaadbfe82.cosmwasm_std.6539afbd309a16f9-cgu.04.rcgu.o)
          
note: rust-lld: error: duplicate symbol: allocate
     ***
note: rust-lld: error: duplicate symbol: deallocate
     ***

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants