Sfoglia il codice sorgente

interface: Add WASM build to CI and fix it (#28)

* interface: Add WASM build to CI and fix it

#### Problem

The solana-system-interface crate is meant to work with WASM, but it's
not currently tested in CI.

#### Summary of changes

* Add `crate-type` to Cargo.toml, which is required for wasm-pack
* Add step testing `wasm-pack` in CI

* Use `program-id` to decide if a crate is a program
Jon C 11 mesi fa
parent
commit
96a04380ee
5 ha cambiato i file con 41 aggiunte e 1 eliminazioni
  1. 22 0
      .github/workflows/main.yml
  2. 3 0
      interface/Cargo.toml
  3. 1 0
      package.json
  4. 14 0
      scripts/interface/wasm.mjs
  5. 1 1
      scripts/utils.mjs

+ 22 - 0
.github/workflows/main.yml

@@ -70,6 +70,28 @@ jobs:
       - name: Lint / Docs
         run: pnpm zx ./scripts/interface/lint-docs.mjs
 
+  wasm_interface:
+    name: Build Interface in WASM
+    runs-on: ubuntu-latest
+    needs: format_and_lint_interface
+    steps:
+      - name: Git Checkout
+        uses: actions/checkout@v4
+
+      - name: Setup Environment
+        uses: ./.github/actions/setup
+        with:
+          cargo-cache-key: cargo-wasm-interface
+          solana: true
+
+      - name: Install wasm-pack
+        uses: taiki-e/install-action@v2
+        with:
+          tool: wasm-pack
+
+      - name: Build Interface with wasm-pack
+        run: pnpm interface:wasm
+
   test_interface:
     name: Test Interface
     runs-on: ubuntu-latest

+ 3 - 0
interface/Cargo.toml

@@ -54,3 +54,6 @@ frozen-abi = [
     "solana-pubkey/std"
 ]
 serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"]
+
+[lib]
+crate-type = ["cdylib", "rlib"]

+ 1 - 0
package.json

@@ -19,6 +19,7 @@
     "interface:format": "zx ./scripts/interface/format.mjs",
     "interface:lint": "zx ./scripts/interface/lint.mjs",
     "interface:test": "zx ./scripts/interface/test.mjs",
+    "interface:wasm": "zx ./scripts/interface/wasm.mjs",
     "template:upgrade": "zx ./scripts/upgrade-template.mjs"
   },
   "devDependencies": {

+ 14 - 0
scripts/interface/wasm.mjs

@@ -0,0 +1,14 @@
+#!/usr/bin/env zx
+import 'zx/globals';
+import {
+  cliArguments,
+  workingDirectory,
+} from '../utils.mjs';
+
+// Configure additional arguments here, e.g.:
+// ['--arg1', '--arg2', ...cliArguments()]
+const buildArgs = cliArguments();
+const cratePath = path.join(workingDirectory, 'interface');
+
+// Build the interface.
+await $`wasm-pack build --target nodejs --dev ${cratePath} --features bincode ${buildArgs}`;

+ 1 - 1
scripts/utils.mjs

@@ -66,7 +66,7 @@ export function getProgramFolders() {
 
 export function getAllProgramFolders() {
   return getCargo().workspace.members.filter((member) =>
-    (getCargo(member).lib?.['crate-type'] ?? []).includes('cdylib')
+    getCargo(member).package?.metadata?.solana?.['program-id']
   );
 }