Skip to content

feat(wasm-builder): New approach to build demos#3602

Closed
ark0f wants to merge 85 commits into
masterfrom
al/no-wasm-builder
Closed

feat(wasm-builder): New approach to build demos#3602
ark0f wants to merge 85 commits into
masterfrom
al/no-wasm-builder

Conversation

@ark0f

@ark0f ark0f commented Dec 17, 2023

Copy link
Copy Markdown
Member

This is a new approach to build Gear programs which can replace gear-wasm-builder.

Schematic architecture:
image

Pipeline:
image

Purpose of program build script is just write features to lock file and don't use any cargo:rerun-if instructions so default cargo heuristics are enabled.

Binaries crate build script list its build dependencies and corresponding reads lock files to obtain program features then it runs cargo build -p program1 -p program2 so cargo builds WASM binaries effectively and concurrently. Then it writes to lock files to skip cargo invocation in next or in another binaries crate to avoid few seconds cache verification

Pros:

  • Advanced feature tracking.
    Features are tracked automatically so we don't need to re-run build script each time like in gear-wasm-builder (can be mitigated by cargo-metadata and Cargo.toml tracking)
  • Faster build.
    gear-wasm-builder builds program via new cargo command in the same target directory so each cargo process blocks other. wasm-dep-builder collects list of programs so only one cargo process runs.

Cons:

  • Create and import binaries crate.
    It is important to create binaries create that will list and build programs

Current problem:
image

When crate includes itself as dev dependency (any integration tests) with different feature set then cargo build and runs 2 different versions of build script - for workspace and for tests.

gear-wasm-builder case is that cargo builds and runs script just once with merged feature set.

So, how to resolve these features? Should we deliver different WASM binaries? Or just merge feature sets?
I vote for merging but we need some mechanism to obtain all of feature sets cargo resolved for each build script invocation of program before build script invocation of binaries crate if we don't want to waste time on WASM build with incomplete feature set

@clearloop

Copy link
Copy Markdown
Contributor

plz check this #3588 (comment) btw

@gshep gshep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job! 🥇

Comment thread gclient/binaries/build.rs Outdated
@@ -0,0 +1,21 @@
// This file is part of Gear.
//
// Copyright (C) 2023 Gear Technologies Inc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest removing the year number from the copyright since it is not consistent across the source code and we will not update it later

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see most of files have year when just a few don't

Comment thread utils/wasm-dep-builder/src/utils.rs
Comment thread core/src/pages.rs

//! Module for memory pages.

#![allow(clippy::assertions_on_constants)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

merge master and remove this

@@ -0,0 +1 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why examples/signal-wait/** is empty?

Comment thread Cargo.toml
gear-stack-buffer = { path = "stack-buffer" }
gear-utils = { path = "utils/utils" }
gear-wasm-builder = { path = "utils/wasm-builder", default-features = false }
wasm-dep-builder = { path = "utils/wasm-dep-builder" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to prefix it with gear as for the others?

[dependencies]
gcore.workspace = true
parity-scale-codec.workspace = true
gstd = { workspace = true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
gstd = { workspace = true }
gstd.workspace = true

Comment on lines +5 to +6

[dependencies]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

redundant

Comment on lines +5 to +6

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

redundant

Comment on lines +5 to +6

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

redundant

Comment thread gclient/Cargo.toml
gmeta = { workspace = true }
gstd = { workspace = true, features = ["debug"] }
demo-wat.workspace = true
gclient-binaries = { path = "binaries" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be better to call it demo-binaries?

Comment thread gsdk/Cargo.toml

[dev-dependencies]
gsdk = { path = ".", features = ["testing"] }
gsdk-binaries = { path = "binaries" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-> demo-binaries?

Comment thread gtest/Cargo.toml
demo-ping.workspace = true
demo-futures-unordered.workspace = true
demo-meta-io.workspace = true
gtest-binaries = { path = "binaries" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-> demo-binaries?

prometheus-endpoint.workspace = true

[dev-dependencies]
gear-authorship-binaries = { path = "binaries" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-> demo-binaries?

repository.workspace = true

[dependencies]
cargo_metadata = "0.18.1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want to move them into the workspace deps?

@ark0f

ark0f commented Feb 7, 2024

Copy link
Copy Markdown
Member Author

cargo check may be failed because of missing .lock. Investigating...

@NikVolf

NikVolf commented Feb 25, 2024

Copy link
Copy Markdown
Member

Can you describe the approach in the PR outline?

@NikVolf

NikVolf commented Feb 26, 2024

Copy link
Copy Markdown
Member

Can we maybe put "dependency builder" inside gear-wasm-builder itself?

@breathx

breathx commented Feb 26, 2024

Copy link
Copy Markdown
Member

Can we maybe put "dependency builder" inside gear-wasm-builder itself?

It will replace gear_wasm_builder some day, so is there any reason to merge them now?

Just for notice: as it was mentioned, there are a few problems with these approach, and as far as we discussed with @ark0f they're already solved, but not pushed

@ark0f

ark0f commented Mar 12, 2024

Copy link
Copy Markdown
Member Author

Can you describe the approach in the PR outline?

Done

@breathx

breathx commented May 6, 2024

Copy link
Copy Markdown
Member

Temporary closing in favour of opened referencing issue as won't be implemented

@breathx breathx closed this May 6, 2024
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.

7 participants