Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

pwasm-abi-derive is not compatible with no-std libs #54

Closed
Pzixel opened this issue Jun 29, 2018 · 11 comments
Closed

pwasm-abi-derive is not compatible with no-std libs #54

Pzixel opened this issue Jun 29, 2018 · 11 comments
Assignees

Comments

@Pzixel
Copy link
Contributor

Pzixel commented Jun 29, 2018

I've tested it with serde, but I'm pretty sure the problem is wider.

Sample code

#![no_std]

extern crate pwasm_ethereum;
#[macro_use]
extern crate serde_derive;
extern crate serde;

Cargo.toml

[package]
name = "pwasm-tutorial-contract"
version = "0.1.0"
authors = ["Alexey Frolov <[email protected]>"]

[dependencies]
pwasm-std = "0.9"
pwasm-ethereum = "0.5"
pwasm-abi = "0.1.2"
pwasm-abi-derive = "0.1.2"
serde_derive = { version = "1.0", default-features = false }
serde = { version = "1.0", default-features = false }

[lib]
crate-type = ["cdylib"]

[profile.release]
panic = "abort"
lto = true
opt-level = "z"

Expected result

everything compiles

Actual result:

$ ./build.sh
   Compiling pwasm-tutorial-contract v0.1.0 (file:///C:/Users/Alex/Documents/Repo/pwasm-tutorial/step-0)
warning: unused `#[macro_use]` import
 --> src\lib.rs:6:1
  |
6 | #[macro_use]
  | ^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error: duplicate lang item in crate `std`: `panic_impl`.
  |
  = note: first defined in crate `pwasm_std`.

error: duplicate lang item in crate `std`: `oom`.
  |
  = note: first defined in crate `pwasm_std`.

error: aborting due to 2 previous errors

error: Could not compile `pwasm-tutorial-contract`.

P.S.

Combinations that work:

  • Cargo.toml without pwasm-abi-derive = "0.1.2"
  • lib.rs without extern crate serde;
@Pzixel Pzixel changed the title pwasm-abi is not compatibel with no-std libs pwasm-abi is not compatible with no-std libs Jun 29, 2018
@Pzixel Pzixel changed the title pwasm-abi is not compatible with no-std libs pwasm-abi-derive is not compatible with no-std libs Jun 29, 2018
@lexfrl lexfrl self-assigned this Jul 1, 2018
@lexfrl
Copy link
Contributor

lexfrl commented Jul 2, 2018

It's expected.
If any of crates is not #![no_std] std will be linked. So the goal is to find which one brings it..
@pepyakin has been around the block - is there any solution/or script found to check which crate links std?

@pepyakin
Copy link
Contributor

pepyakin commented Jul 2, 2018

None I'm aware of.

When I had to bisect which crate pulled std library in, I simply ran a build with cargo build --verbose, and checked every library that might pull std (i.e. doesn't contain #![no_std] attribute in it's lib.rs). If the #![no_std] attribute is behind the cfg feature flags, it is also simple to check in cargo verbose log if the correct feature flags are passed when compiling.

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 2, 2018

Well, afaik serde supports no_std scenarios, so if it's incompatible with pwasm-abi-derive I'd suspect the latter crate rather than the former one.

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 3, 2018

Maybe it's caused by

#[cfg(not(feature="std"))]
extern crate alloc;

?

@lexfrl
Copy link
Contributor

lexfrl commented Jul 3, 2018

@Pzixel no it shouldn't..

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 16, 2018

This code compiles fine:

#![feature(lang_items)]
#![no_std]

extern crate pwasm_std;
#[macro_use]
extern crate serde_derive;
extern crate serde;

#[lang = "eh_unwind_resume"]
#[no_mangle]
pub extern fn rust_eh_unwind_resume() {}
[package]
name = "issue54"
version = "0.1.0"
authors = ["Psilon <[email protected]>"]

[dependencies]
pwasm-std = "0.9.2"
serde_derive = { version = "1.0.70", default-features = false }
serde = { version = "1.0.70", default-features = false }

[lib]
crate-type = ["cdylib"]

[profile.release]
panic = "abort"
lto = true
opt-level = "z"

Investigting further..

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 16, 2018

I cloned latest pwasm-abi-derive. Here is changed cargo.toml:

[dependencies]
pwasm-abi = { path = "..", version = "0.1" }
quote = "0.3"
syn = { version = "0.11", features = ["full"] }
tiny-keccak = { version = "1", default-features = false }
byteorder = { version = "1", default-features = false }
parity-hash = { version = "1", default-features = false }
serde = { version = "1", default-features = false }
serde_derive = { version = "1", default-features = false }

that works, but if we add serde_json:

[dependencies]
pwasm-abi = { path = "..", version = "0.1" }
quote = "0.3"
syn = { version = "0.11", features = ["full"] }
tiny-keccak = { version = "1", default-features = false }
byteorder = { version = "1", default-features = false }
parity-hash = { version = "1", default-features = false }
serde = { version = "1", default-features = false }
serde_json = { version = "1", default-features = false }
serde_derive = { version = "1", default-features = false }

Then this error happens.

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 16, 2018

@NikVolf
Copy link
Collaborator

NikVolf commented Jul 16, 2018

probably not related

check your Cargo.lock, there must be 2 different versions of pwasm-std compiled in binary

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 16, 2018

@NikVolf no, there isn't. See repo: https://github.com/Pzixel/issue54

https://github.com/Pzixel/issue54/blob/42157efa3bcdcfc16e76b821a1fa095f902fc5b6/Cargo.lock#L37

There is single 0.9.2 across entire lock file.

@Pzixel
Copy link
Contributor Author

Pzixel commented Jul 19, 2018

See #59

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

No branches or pull requests

4 participants