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

feat: populate metadata with build information #55

Merged
merged 6 commits into from
Oct 20, 2022

Conversation

itegulov
Copy link
Contributor

@itegulov itegulov commented Sep 21, 2022

Fixes #19

Depends on near/near-sdk-rs#927

@@ -51,6 +45,12 @@ pub(crate) fn run(args: BuildCommand) -> anyhow::Result<()> {
)?;
min_abi_path.replace(util::copy(&path, &out_dir)?);
}
contract_abi.metadata.build = Some(BuildInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we do this before writing out the embedded version of the ABI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is opinionated I guess. Do you think this information should be embedded inside of the wasm file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unsure, but this, in a sense, is part of the contract's signature.

We could make it opt-in, though, so another flag for including build information in the embedded ABI?

near/near-abi-rs#8 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, decided to include the build information in the end. It is only ~30 extra bytes anyway and we can always come up with a flag that disables it if there is a demand.

Also, probably wise to try and keep embedded and non-embedded ABI to look as close as possible.

contract_abi.metadata.build = Some(BuildInfo {
compiler: format!("rustc {}", rustc_version::version()?),
builder: format!("cargo-near {}", env!("CARGO_PKG_VERSION")),
image: None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious how we're going to inject this bit of information. Env var only set when built from contract-builder?

Because either way, that information needs to be known at this stage to be embedded in the wasm file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Env var only set when built from contract-builder?

Most likely. There no built-in way to get the docker image name from inside of the container from what I have researched.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if sdk-js gets an equivalent of contract-builder at some point and what that would mean for this field. I guess in a sense, the builder information plus the image helps better describe what type of contract-builder this is. But it's a non-issue, we have a long way ahead before we're at that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually wondering if it makes sense to "demote" contract-builder to only serve as an operating system and then just install whatever is necessary based on the build info (e.g. rustc 1.61.0, cargo-near 0.2.0). This way it could potentially work for both sdk-rs and sdk-js.

Also, presumably sometime in the future rustc/cargo will reach the point where wasm builds can be bit-by-bit reproducible and hedonistic and we will not need an image anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good point, not sure what the size overhead would be from including the JS SDK in the same docker image, but it would certainly help unify things. Also, imho, the current docker image might be a little too big, I'll try to see if we can cut things down a bit, drop unnecessary binaries, strip some maybe etc. Doesn't seem like the official rust image makes much of an effort to reduce size anyway.

@miraclx
Copy link
Contributor

miraclx commented Oct 19, 2022

Looks like we're going to have to merge this in before #74, since it depends on a version of near-sdk that in-turn depends on near-abi v0.2.0. CI

@itegulov
Copy link
Contributor Author

@miraclx I was waiting for 4.1.0-pre.4 release (expected it to come a bit sooner) to not have to bother with git revs, but will update & merge this PR to unblock you.

integration-tests/tests/util.rs Outdated Show resolved Hide resolved
integration-tests/tests/util.rs Show resolved Hide resolved
@itegulov itegulov merged commit 2cfcf31 into main Oct 20, 2022
@itegulov itegulov deleted the daniyar/metadata-with-buildinfo branch October 20, 2022 06:03
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
schemars = "0.8"

[patch.crates-io]
near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "792d5eb26d26a0878dbf59e304afa4e19540c317" }
near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "792d5eb26d26a0878dbf59e304afa4e19540c317", git = "https://github.com/near/near-sdk-rs.git", rev = "6d73c9ff4fd095fc23eaa000c14ab65c15c4aa6b" }
Copy link
Contributor

Choose a reason for hiding this comment

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

lol 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha, interesting that this is still a valid toml syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am working on a PR right now that will allow us not to update all the toml files every time we upgrade the SDK version, so will fix there

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Can't wait to see it.

@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.

Include code hash in ABI output
2 participants