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

replace strict typed casting with deserialization #74

Merged
merged 10 commits into from
Oct 25, 2022

Conversation

miraclx
Copy link
Contributor

@miraclx miraclx commented Oct 19, 2022

CleanShot 2022-10-19 at 14 05 58@2x

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

Copy link
Contributor

@itegulov itegulov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this has fewer problems than our current approach, but it still depends on Rust ABI not changing between the point when you compiled cargo-near and when you are invoking it (e.g. you used rustc 1.61 to compile cargo-near, but now you are using rustc 1.64 to compile your smart contract).

From what I understand Rust ABI is not stable, so I would not be comfortable with depending on it not changing, unless someone has more insight on this topic. CC @austinabell

@itegulov
Copy link
Contributor

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
Copy link
Contributor Author

miraclx commented Oct 19, 2022

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

@itegulov
Copy link
Contributor

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

@miraclx
Copy link
Contributor Author

miraclx commented Oct 19, 2022

Yeah, it works. Although, for posterity, the empty file issue was fixed in #75.

@miraclx
Copy link
Contributor Author

miraclx commented Oct 19, 2022

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 miraclx requested a review from itegulov October 20, 2022 07:09
Copy link
Contributor

@itegulov itegulov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but lets wait for the SDK change to come in first

cargo-near/src/util/mod.rs Show resolved Hide resolved
@miraclx
Copy link
Contributor Author

miraclx commented Oct 24, 2022

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

@itegulov
Copy link
Contributor

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

latest-screenshot

@miraclx
Copy link
Contributor Author

miraclx commented Oct 25, 2022

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
Copy link
Contributor

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

Copy link
Contributor

@itegulov itegulov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Don't forget to update the git rev to the master commit though once the SDK PR is merged.

@miraclx
Copy link
Contributor Author

miraclx commented Oct 25, 2022

You got it, chief!

@miraclx miraclx merged commit 46d8989 into main Oct 25, 2022
@miraclx miraclx deleted the miraclx/fix-generic-dylib branch October 25, 2022 08:13
@miraclx miraclx mentioned this pull request Nov 10, 2022
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

Successfully merging this pull request may close these issues.

Add a check for near-abi version
3 participants