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

Add Rust specific build info to metadata #680

Merged
merged 22 commits into from
Oct 20, 2022
Merged

Add Rust specific build info to metadata #680

merged 22 commits into from
Oct 20, 2022

Conversation

HCastano
Copy link
Contributor

@HCastano HCastano commented Aug 8, 2022

Will close the metadata part of #525.

This is what the new metadata looks like:

  "source": {
    "hash": "0xad8e1a3d7d1c44b4c7b3f715765ab8003e15aa2d8d1146a64cbc9b8f7e0a8df9",
    "language": "ink! 4.0.0-alpha.3",
    "compiler": "rustc 1.64.0",
    "build_info": {
      "build_mode": "Release",
      "cargo_contract_version": "2.0.0-alpha.4",
      "rustc_version": "stable-x86_64-unknown-linux-gnu",
      "wasm_opt_settings": {
        "keep_debug_symbols": false,
        "optimization_passes": "Z"
      }
    }

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 the build_info for now since there's
no easy way to get it from the new wasm-opt library.

I'm going to assume that two installations of cargo-contract contain the same wasm-opt
library (this only holds if both were installed with --locked). We should add it back in the future
in order to give users a better indication of what went wrong during the verify phase.

@HCastano HCastano mentioned this pull request Aug 18, 2022
@HCastano HCastano marked this pull request as ready for review September 29, 2022 21:47
@HCastano HCastano requested a review from athei September 29, 2022 21:50
@athei
Copy link
Contributor

athei commented Sep 30, 2022

I don't think we should add the wasm-opt version. We should have a useable wasm-opt version as crate as early as next week. Then the version is described by the manifest alread.

@HCastano
Copy link
Contributor Author

I don't think we should add the wasm-opt version. We should have a useable wasm-opt version as crate as early as next week. Then the version is described by the manifest alread.

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,
Copy link
Collaborator

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")) {
Copy link
Collaborator

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.
@HCastano HCastano requested a review from ascjones October 19, 2022 22:55
///
/// Useful for producing deterministic builds.
#[serde(skip_serializing_if = "Option::is_none")]
pub build_info: Option<Map<String, Value>>,
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@HCastano HCastano merged commit f268549 into master Oct 20, 2022
@HCastano HCastano deleted the hc-add-build-info branch October 20, 2022 19:14
@ascjones ascjones mentioned this pull request Oct 27, 2022
@ascjones ascjones mentioned this pull request Feb 14, 2023
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.

3 participants