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

wasm crate works only as workspace non-member #12274

Closed
deepink-mas opened this issue Jun 15, 2023 · 3 comments
Closed

wasm crate works only as workspace non-member #12274

deepink-mas opened this issue Jun 15, 2023 · 3 comments
Labels
A-features2 Area: issues specifically related to the v2 feature resolver A-workspaces Area: workspaces C-bug Category: bug

Comments

@deepink-mas
Copy link

Problem

I have the following (minimal) example wasm crate (it is a soroban smart contract):

src/lib.rs:

#![no_std]
use soroban_sdk::{contractimpl, vec, Env, Symbol, Vec};

pub struct Contract;

#[contractimpl]
impl Contract {
    pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> {
        vec![&env, Symbol::short("Hello"), to]
    }
}

which builds (cargo b --target wasm32-unknown-unknown) fine with this Cargo.toml:

[package]
name = "soroban"
version = "0.1.0"
edition = "2021"

[dependencies]
soroban-sdk = "0.8.6"

however if I place it into a workspace:

[workspace]
members = ["soroban-workspace"]
exclude = ["soroban"]

[workspace.dependencies]
soroban-sdk = "0.8.6"

then it fails with the following error:

   Compiling soroban-sdk v0.8.6
error[E0152]: found duplicate lang item `panic_impl`
  --> /home/werk/.cargo/registry/src/github.51.al-1ecc6299db9ec823/soroban-sdk-0.8.6/src/lib.rs:51:1
   |
51 | fn handle_panic(_: &core::panic::PanicInfo) -> ! {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: the lang item is first defined in crate `std` (which `soroban_env_common` depends on)
   = note: first definition in `std` loaded from /usr/lib/rust/1.69.0/lib/rustlib/wasm32-unknown-unknown/lib/libstd-2dad762beb228465.rlib
   = note: second definition in the local crate (`soroban_sdk`)

Steps

  1. move working wasm crate into workspace
  2. cargo b --target wasm32-unknown-unknown
  3. it now fails with duplicate lang item panic_impl

Possible Solution(s)

No response

Notes

No response

Version

$ cargo version --verbose
cargo 1.69.0-nightly
release: 1.69.0-nightly
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 8.1.0 (sys:0.4.59+curl-7.86.0 system ssl:GnuTLS/3.8.0 (NSS/3.89.1) (OpenSSL/3.0.8))
os: Gentoo Linux 2.13 [64-bit]
@deepink-mas deepink-mas added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 15, 2023
@weihanglo
Copy link
Member

This can be resolved by adding resolver = "2" under [workspace] section in the root workspace Cargo.toml. A warning has been added via #10910. If you run with the current nightly, you'll Cargo recommend you setting that value. We also plan something like #10587 to enable it by default.

Closing as it is a known issue having a workaround. Let us know if it doesn't work for you.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2023
@weihanglo weihanglo added A-workspaces Area: workspaces A-features2 Area: issues specifically related to the v2 feature resolver and removed S-triage Status: This issue is waiting on initial triage. labels Jun 15, 2023
@deepink-mas
Copy link
Author

Thanks, adding resolver = "2" worked for me.

Is there a backwards compatibility problem with defaulting to resolver = "2" if at least one workspace crate is using edition 2021? It seems like that would not break any existing pre-2021 workspaces...

@weihanglo
Copy link
Member

Resolver is a global setting for a workspace. If one of the member package is notusing edition 2021 and still inresolver = "1". If Cargo implicitly sets resolver to v2, that package might get a different set of feature` to compile. That's my understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features2 Area: issues specifically related to the v2 feature resolver A-workspaces Area: workspaces C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants