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

Re-export dependencies #142

Closed
MaksymZavershynskyi opened this issue Apr 30, 2020 · 4 comments · Fixed by #201
Closed

Re-export dependencies #142

MaksymZavershynskyi opened this issue Apr 30, 2020 · 4 comments · Fixed by #201
Assignees

Comments

@MaksymZavershynskyi
Copy link
Contributor

Currently contract developers have to export the following libraries along with near-sdk themselves:

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.45"
borsh = "0.6.0"
wee_alloc = { version = "0.4.5", default-features = false, features = [] }

The problem with that is that it makes DevX slightly worse and can create version mismatch, e.g. near_sdk::collections can use different version of borsh which will produce an obscure compilation error. We should export them into near_sdk and then contracts can access them from near_sdk::exports::. This is a common practice in Rust crates, e.g. see syn.

@evgenykuzyakov
Copy link
Contributor

@evgenykuzyakov
Copy link
Contributor

When building cross-contract-high-level example I get the following error:

examples/cross-contract-high-level  cargo +nightly rustc -- -Z macro-backtrace        Fri May  8 11:43:34 2020
   Compiling near-sdk v0.10.0 (/Users/ekwork/code/near-bindgen/near-sdk)
   Compiling cross-contract-high-level v0.1.0 (/Users/ekwork/code/near-bindgen/examples/cross-contract-high-level)
error[E0463]: can't find crate for `serde`
  --> src/lib.rs:23:1
   |
23 |   #[ext_contract(ext)]
   |   ^^^^^^^^^^^^^^^^^^^^
   |   |
   |   can't find crate
   |   in this macro invocation
   |
  ::: /Users/ekwork/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_derive-1.0.106/src/lib.rs:85:1
   |
85 | / pub fn derive_serialize(input: TokenStream) -> TokenStream {
86 | |     let input = parse_macro_input!(input as DeriveInput);
87 | |     ser::expand_derive_serialize(&input)
88 | |         .unwrap_or_else(to_compile_errors)
89 | |         .into()
90 | | }
   | |_- in this expansion of `#[derive(near_sdk::serde::Serialize)]`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `cross-contract-high-level`.

To learn more, run the command again with --verbose.

@lexfrl
Copy link
Contributor

lexfrl commented May 25, 2020

@nearmax @frol Please consider to inquire this to avoid common pitfalls related to the re-exporting practice rust-lang/api-guidelines#176

@frol
Copy link
Collaborator

frol commented May 26, 2020

@evgenykuzyakov Here is the fix: cb5a008

The issues are:

evgenykuzyakov pushed a commit that referenced this issue Jul 13, 2020
Re-exporting common crates from `near_sdk` to be reused by contracts and avoid version issues.
It still depends on the versions from `near-vm-logic` which can be addressed later.

Bump near-* dependencies to `1.0.0`.
Bump SDK version to `1.0.0`

Rebuild all examples.

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

Successfully merging a pull request may close this issue.

4 participants