-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add Rust specific build info to metadata #680
Conversation
Since we hardcode these into `cargo-contract` we shouldn't need to track these manually
I don't think we should add the wasm-opt version. We should have a useable |
Sure, but until that happens this is still needed. We can get rid of that field once that crate is published. |
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct BuildInfo { | ||
/// The stable version of `rustc` used to build the contract. | ||
pub rustc_version: Version, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should we also add the toolchain which contains the architecture? e.g. stable-x86_64-unknown-linux-gnu
. I remember there being some discussions about this affecting the wasm bytecode output, can't remember what the conclusions were.
@@ -650,7 +655,29 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result<BuildResult> { | |||
&crate_metadata.contract_artifact_name, | |||
)?; | |||
|
|||
Ok(optimization_result) | |||
let cargo_contract_version = | |||
if let Ok(version) = Version::parse(env!("CARGO_PKG_VERSION")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU CARGO_PKG_VERSION
is only available at compile time (and also during cargo run
). So would need to be captured in a const
e.g. const VERSION: &'static str = env!("CARGO_PKG_VERSION");
Since we're using the `wasm-opt` library from crates.io we'll assume that every matching version of `cargo-contract` contains the same version of `wasm-opt`. This doesn't hold if a user installs without the `--locked` flag though, so we may want to add this back in the future to warn users if there are mismatching `wasm-opt` versions.
/// | ||
/// Useful for producing deterministic builds. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub build_info: Option<Map<String, Value>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we convert to loosely typed json Map
here? Is that for alt. compilers e.g. solang
to provide arbitrary data here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, other compilers may want to include other info here. It's also useful for us if we decide that we need to add/remove info later on
Will close the metadata part of #525.
This is what the new metadata looks like:
The stuff related to the
verify
command will be done in a follow-up.Note: I've ended up removing the
wasm-opt
version from thebuild_info
for now since there'sno easy way to get it from the new
wasm-opt
library.I'm going to assume that two installations of
cargo-contract
contain the samewasm-opt
library (this only holds if both were installed with
--locked
). We should add it back in the futurein order to give users a better indication of what went wrong during the
verify
phase.