diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index efde891..d7dd6dc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,63 +14,168 @@ concurrency: cancel-in-progress: true jobs: - check: + # Fast format check - fails early if formatting is wrong + check-fmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install toolchain - uses: dtolnay/rust-toolchain@stable - with: - targets: wasm32-unknown-unknown - components: rust-src, rustfmt, clippy + - name: Setup toolchain + run: | + rustup toolchain install 1.84.1 --profile minimal --component rustfmt + rustup default 1.84.1 - uses: Swatinem/rust-cache@v2 - name: Check format run: cargo fmt --all -- --check - - name: Make dummy poc-guest files - run: make dummy-guests + check-wasm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup toolchain + run: | + rustup toolchain install 1.84.1 --profile minimal --component clippy + rustup default 1.84.1 + + - uses: Swatinem/rust-cache@v2 - - name: Check no-std + - name: Check wasm run: make check-wasm - - name: Install pvq-program-metadata-gen - run: cargo install --path pvq-program-metadata-gen + # Root workspace clippy linting + clippy-root: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive - - name: Clippy - run: make clippy + - name: Setup toolchain + run: | + rustup toolchain install 1.84.1 --profile minimal --component clippy + rustup default 1.84.1 + + - uses: Swatinem/rust-cache@v2 + + - name: Clippy root workspace + run: make clippy-root + + # Guest examples clippy linting + clippy-guests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup toolchain + run: | + rustup toolchain install nightly-2025-06-09 --profile minimal --component clippy + rustup default nightly-2025-06-09 + + - uses: Swatinem/rust-cache@v2 + with: + cache-bin: "false" + + - name: Install polkatool and pvq-program-metadata-gen + run: | + make polkatool + make pvq-program-metadata-gen + + + - name: Clippy guest examples + run: make clippy-guests + + + # Run tests + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup toolchain + run: | + rustup toolchain install 1.84.1 --profile minimal + rustup default 1.84.1 + + - uses: Swatinem/rust-cache@v2 + + - name: Make dummy poc-guest files + run: make dummy-guests - name: Run tests run: make test + # Build guest programs in parallel using matrix build-guest: runs-on: ubuntu-latest + strategy: + matrix: + guest: [ + sum-balance, + sum-balance-hand-written, + sum-balance-percent, + swap-info, + total-supply, + total-supply-hand-written, + transparent-call-hand-written + ] steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install toolchain - uses: dtolnay/rust-toolchain@stable - with: - components: rust-src, rustfmt, clippy + - name: Setup toolchain + run: | + rustup toolchain install nightly-2025-06-09 --profile minimal --component rust-src + rustup default nightly-2025-06-09 - uses: Swatinem/rust-cache@v2 with: - workspaces: | - guest-examples -> guest-examples/target - cache-all-crates: true + cache-bin: "false" + prefix-key: "guest-${{ matrix.guest }}" - - name: Install polkatool - run: make polkatool + - name: Install polkatool and pvq-program-metadata-gen + run: | + make polkatool + make pvq-program-metadata-gen - - name: Install pvq-program-metadata-gen - run: cargo install --path pvq-program-metadata-gen + - name: Build guest ${{ matrix.guest }} + run: make guest-${{ matrix.guest }} - - name: Build guests - run: make guests + - name: Upload guest artifact + uses: actions/upload-artifact@v4 + with: + name: guest-${{ matrix.guest }} + path: output/guest-${{ matrix.guest }}.polkavm + retention-days: 1 + + # Collect all guest artifacts (optional - for when you need all guests together) + collect-guests: + runs-on: ubuntu-latest + needs: build-guest + if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'full-build') + steps: + - name: Download all guest artifacts + uses: actions/download-artifact@v4 + with: + pattern: guest-* + path: output/ + merge-multiple: true + + - name: Upload combined guests + uses: actions/upload-artifact@v4 + with: + name: all-guests + path: output/ + retention-days: 7 diff --git a/Cargo.lock b/Cargo.lock index 7f9cbc8..12a6fbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1271,14 +1271,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "example-fungibles" -version = "0.1.0" - -[[package]] -name = "example-helloworld" -version = "0.1.0" - [[package]] name = "expander" version = "2.2.1" diff --git a/Cargo.toml b/Cargo.toml index 6f24267..7fa3a57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,6 @@ members = [ "pvq-primitives", "pvq-runtime-api", "pvq-test-runner", - - "examples/example-fungibles", - "examples/example-helloworld", ] exclude = ["guest-examples", "vendor"] diff --git a/Makefile b/Makefile index f9730a9..4ecb4f9 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ guests: $(GUEST_TARGETS) dummy-guests: $(DUMMY_GUEST_TARGETS) guest-%: - cd guest-examples; METADATA_OUTPUT_DIR=$(realpath output) cargo build --release --bin guest-$* -p guest-$* mkdir -p output + cd guest-examples; METADATA_OUTPUT_DIR=$(shell pwd)/output cargo build --release --bin guest-$* -p guest-$* polkatool link --run-only-if-newer -s guest-examples/target/riscv32emac-unknown-none-polkavm/release/guest-$* -o output/guest-$*.polkavm dummy-guest-%: @@ -42,18 +42,29 @@ fmt: .PHONY: check-wasm check-wasm: - cargo check --no-default-features --target=wasm32-unknown-unknown -p pvq-program -p pvq-executor -p pvq-extension-core -p pvq-extension-fungibles -p pvq-extension -p pvq-primitives -p pvq-runtime-api - SKIP_WASM_BUILD= cargo check --no-default-features --target=wasm32-unknown-unknown -p poc-runtime + cargo check --no-default-features --target=wasm32-unknown-unknown \ + -p pvq-program \ + -p pvq-program-metadata-gen \ + -p pvq-executor \ + -p pvq-extension-core \ + -p pvq-extension-fungibles \ + -p pvq-extension-swap \ + -p pvq-extension \ + -p pvq-primitives \ + -p pvq-runtime-api + cargo check -p poc-runtime -.PHONY: check -check: check-wasm - SKIP_WASM_BUILD= cargo check - cd pvq-program/examples; cargo check +.PHONY: clippy-root +clippy-root: + SKIP_WASM_BUILD=1 cargo clippy -- -D warnings + +.PHONY: clippy-guests +clippy-guests: + mkdir -p output + cd guest-examples; METADATA_OUTPUT_DIR=$(shell pwd)/output cargo clippy --all .PHONY: clippy -clippy: - SKIP_WASM_BUILD= cargo clippy -- -D warnings - cd guest-examples; METADATA_OUTPUT_DIR=$(realpath output) cargo clippy --all +clippy: clippy-root clippy-guests .PHONY: test test: diff --git a/examples/example-fungibles/Cargo.toml b/examples/example-fungibles/Cargo.toml deleted file mode 100644 index f8f99fc..0000000 --- a/examples/example-fungibles/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "example-fungibles" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/examples/example-fungibles/src/main.rs b/examples/example-fungibles/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/examples/example-fungibles/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/examples/example-helloworld/Cargo.toml b/examples/example-helloworld/Cargo.toml deleted file mode 100644 index c104d84..0000000 --- a/examples/example-helloworld/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "example-helloworld" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/examples/example-helloworld/src/main.rs b/examples/example-helloworld/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/examples/example-helloworld/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/guest-examples/Cargo.lock b/guest-examples/Cargo.lock index 00dbc58..e3ae771 100644 --- a/guest-examples/Cargo.lock +++ b/guest-examples/Cargo.lock @@ -103,15 +103,6 @@ dependencies = [ "pvq-program", ] -[[package]] -name = "guest-test-swap-extension" -version = "0.1.0" -dependencies = [ - "parity-scale-codec", - "polkavm-derive", - "pvq-program", -] - [[package]] name = "guest-total-supply" version = "0.1.0" diff --git a/guest-examples/Cargo.toml b/guest-examples/Cargo.toml index bc31bea..ca94138 100644 --- a/guest-examples/Cargo.toml +++ b/guest-examples/Cargo.toml @@ -6,7 +6,6 @@ members = [ "total-supply", "total-supply-hand-written", "transparent-call-hand-written", - "test-swap-extension", "swap-info", ] resolver = "2" diff --git a/guest-examples/sum-balance/build.rs b/guest-examples/sum-balance/build.rs index 00031b3..592da70 100644 --- a/guest-examples/sum-balance/build.rs +++ b/guest-examples/sum-balance/build.rs @@ -7,9 +7,7 @@ fn main() { println!("cargo:rerun-if-changed=src/main.rs"); let current_dir = env::current_dir().expect("Failed to get current directory"); // Determine the output directory for the metadata - let output_dir = PathBuf::from(env::var("METADATA_OUTPUT_DIR").expect("METADATA_OUTPUT_DIR is not set")) - .canonicalize() - .expect("Failed to canonicalize output directory"); + let output_dir = PathBuf::from(env::var("METADATA_OUTPUT_DIR").expect("METADATA_OUTPUT_DIR is not set")); // Build and run the command let status = Command::new("pvq-program-metadata-gen") diff --git a/guest-examples/swap-info/build.rs b/guest-examples/swap-info/build.rs index f20692e..0b48870 100644 --- a/guest-examples/swap-info/build.rs +++ b/guest-examples/swap-info/build.rs @@ -7,9 +7,7 @@ fn main() { // println!("cargo:rerun-if-changed=src/main.rs"); let current_dir = env::current_dir().expect("Failed to get current directory"); // Determine the output directory for the metadata - let output_dir = PathBuf::from(env::var("METADATA_OUTPUT_DIR").expect("METADATA_OUTPUT_DIR is not set")) - .canonicalize() - .expect("Failed to canonicalize output directory"); + let output_dir = PathBuf::from(env::var("METADATA_OUTPUT_DIR").expect("METADATA_OUTPUT_DIR is not set")); // Build and run the command let status = Command::new("pvq-program-metadata-gen") diff --git a/guest-examples/test-swap-extension/Cargo.toml b/guest-examples/test-swap-extension/Cargo.toml deleted file mode 100644 index 0a7b090..0000000 --- a/guest-examples/test-swap-extension/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "guest-test-swap-extension" -version = "0.1.0" -edition = "2021" - -[dependencies] -parity-scale-codec = { workspace = true } -polkavm-derive = { workspace = true } -pvq-program = { workspace = true } diff --git a/guest-examples/test-swap-extension/src/main.rs b/guest-examples/test-swap-extension/src/main.rs deleted file mode 100644 index 6210c07..0000000 --- a/guest-examples/test-swap-extension/src/main.rs +++ /dev/null @@ -1,59 +0,0 @@ -#![no_std] -#![no_main] - -#[pvq_program::program] -mod query_pools { - - type AssetId = alloc::vec::Vec; - type Balance = u128; - const UNITS: Balance = 1_000_000_000_000; - - #[program::extension_fn(extension_id = 13206387959972970661u64, fn_index = 0)] - fn quote_price_tokens_for_exact_tokens( - asset1: AssetId, - asset2: AssetId, - amount: Balance, - include_fee: bool, - ) -> Option { - } - - #[program::extension_fn(extension_id = 13206387959972970661u64, fn_index = 1)] - fn quote_price_exact_tokens_for_tokens( - asset1: AssetId, - asset2: AssetId, - amount: Balance, - include_fee: bool, - ) -> Option { - } - - #[program::extension_fn(extension_id = 13206387959972970661u64, fn_index = 2)] - fn get_liquidity_pool(asset1: AssetId, asset2: AssetId) -> Option<(Balance, Balance)> {} - - #[program::extension_fn(extension_id = 13206387959972970661u64, fn_index = 3)] - fn list_pools() -> alloc::vec::Vec<(AssetId, AssetId, Balance, Balance)> {} - - #[program::entrypoint] - fn test_swap_extension(asset1: AssetId, asset2: AssetId) -> Option<(Balance, Balance)> { - // Check quote prices - let amount_in = quote_price_tokens_for_exact_tokens(asset1.clone(), asset2.clone(), 10 * UNITS, false) - .expect("Quote price exists"); - - assert!(amount_in == 20 * UNITS); - let amount_out = quote_price_exact_tokens_for_tokens(asset1.clone(), asset2.clone(), 20 * UNITS, false) - .expect("Quote price exists"); - assert!(amount_out == 10 * UNITS); - - // // Check list_pools - let pools = list_pools(); - assert!(pools.len() == 1); - let (pool_asset1, pool_asset2, pool_balance1, pool_balance2) = &pools[0]; - assert!(pool_asset1 == &asset1); - assert!(pool_asset2 == &asset2); - assert!(*pool_balance1 == 100 * UNITS); - assert!(*pool_balance2 == 50 * UNITS); - - // Check get_liquidity_pool - let (balance1, balance2) = get_liquidity_pool(asset1, asset2).expect("Pool exists"); - Some((balance1, balance2)) - } -}