near / cargo-near

Cargo extension for building Rust smart contracts on NEAR
Apache License 2.0
33 stars 16 forks source link

replace strict typed casting with deserialization #74

Closed miraclx closed 1 year ago

miraclx commented 1 year ago
CleanShot 2022-10-19 at 14 05 58@2x

Fixes #61, alternative to #73, depends on a small patch to SDK – https://github.com/near/near-sdk-rs/pull/939.

itegulov commented 1 year ago

But thinking about this a bit more, couldn't we avoid Rust ABI entirely and load this with libloading::Symbol<extern "C" fn() -> String> instead? We would have to change the way SDK exposes the symbol obviously, but that should not be a big deal.

miraclx commented 1 year ago

@itegulov, yeah I came to the same conclusion, but to be safe, we can replace String entirely with *const c_char

itegulov commented 1 year ago

Hmm, weird. Have you tried it? I am getting an empty file instead of ABI.

miraclx commented 1 year ago

Yeah, it works. Although, for posterity, the empty file issue was fixed in https://github.com/near/cargo-near/pull/75.

miraclx commented 1 year ago

This patch requires a version of near-sdk that uses near-abi v0.2.0. So we'll have to merge #55 before this.

CI fails for this reason. https://github.com/near/cargo-near/actions/runs/3281321184/jobs/5403176360#step:4:1081

miraclx commented 1 year ago

@itegulov, this is ready. What do you think? Can you test it out?

itegulov commented 1 year ago

@miraclx hmm weird it is not working for me. Tried our classic adder example and got this:

latest-screenshot

miraclx commented 1 year ago

Have you tried cleaning your target folder? Maybe cargo is returning an artifact from previous builds? In the meantime, I'll spin up a Linux machine and see if I can reproduce this.

itegulov commented 1 year ago

@miraclx yep, sorry, must have had some leftover artifacts indeed. Works fine now!

miraclx commented 1 year ago

You got it, chief!