Skip to content

Commit

Permalink
Add rust client sdk (#41)
Browse files Browse the repository at this point in the history
* wip: add rust sdk generation

* wip: update generated code

* Update kinobi release

* Update generated code

* Add tests

* Add readme

* Tweak dependency versions

* Add rust sdk workflows

* Use program builds

* Run sdk workflows in parallel

* Rename program crate

* Update generated clients

* Fix program name

* Fix binary name

* Update description

* Fix markdown

* Bump kinobi version

* Bump kinobi version

* Update generated clients

* Update examples

* Add note on builders

* Increase compute units

* Fix print test

* Rename client workflows

* Refactor clients CI

* Updata shank version

* Tweaks

* Pass all arguments to test

* Update size config

* Add size information

* Use size constants

---------

Co-authored-by: febo <[email protected]>
  • Loading branch information
febo and febo authored Aug 25, 2023
1 parent b9aa26e commit d1a1327
Show file tree
Hide file tree
Showing 224 changed files with 59,577 additions and 1,176 deletions.
9 changes: 8 additions & 1 deletion .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ programs: &programs

client_common: &client_common
- *programs
- ".github/workflows/test-js.yml"
- ".github/workflows/test-js-client.yml"
- ".github/workflows/test-rust-client.yml"
- ".github/workflows/build-rust-client.yml"
- ".github/workflows/main.yml"
- ".github/file-filters.yml"
- ".github/.env"
Expand All @@ -34,8 +36,13 @@ js_client: &js_client
- *client_common
- "clients/js/**"

rust_client: &rust_client
- *client_common
- "clients/rust/**"

clients: &clients
- *js_client
- *rust_client

# Any.

Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/build-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build Rust Client

on:
workflow_call:
inputs:
rust:
type: string
solana:
type: string
workflow_dispatch:
inputs:
rust:
description: Rust version
default: 1.68.0
required: true
type: string
solana:
description: Solana version
default: 1.16.8
required: true
type: string

env:
CACHE: true

jobs:
build_sdk:
name: Build
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV

- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
toolchain: ${{ inputs.rust || env.RUST_VERSION }}

- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ inputs.solana || env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features --no-deps --manifest-path ./clients/rust/Cargo.toml

- name: Build Rust client
shell: bash
working-directory: clients/rust
run: cargo build --release

- name: Upload Rust client builds
uses: actions/upload-artifact@v3
with:
name: rust-client-builds
# First wildcard ensures exported paths are consistently under the clients folder.
path: ./client*/rust/target/release/*mpl_token_metadata*
if-no-files-found: error
36 changes: 12 additions & 24 deletions .github/workflows/create-proposal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,21 @@ jobs:
- name: Determine program version
run: |
IDL_NAME=`echo "${{ inputs.program }}" | tr - _`
VERSION=`jq '.version' ./idls/mpl_${IDL_NAME}.json | sed 's/"//g'`
VERSION=`jq '.version' ./idls/${IDL_NAME}.json | sed 's/"//g'`
MAJOR=`echo ${VERSION} | cut -d. -f1`
MINOR=`echo ${VERSION} | cut -d. -f2`
PATCH=`echo ${VERSION} | cut -d. -f3-4`
case "$PATCH" in
*"beta"*)
PRERELEASE=`echo ${PATCH} | cut -d. -f2`
PATCH=`echo ${PATCH} | cut -d- -f1`
;;
*)
PRERELEASE=0
;;
esac
if [ $PRERELEASE -eq 0 ]; then
if [ "${{ inputs.bump }}" == "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "${{ inputs.bump }}" == "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
PATCH=`echo ${VERSION} | cut -d. -f3`
if [ "${{ inputs.bump }}" == "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "${{ inputs.bump }}" == "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
echo PROGRAM_VERSION="${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_ENV
Expand Down
File renamed without changes.
92 changes: 92 additions & 0 deletions .github/workflows/deploy-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Deploy Rust Client

on:
workflow_dispatch:
inputs:
level:
description: Level
required: true
default: patch
type: choice
options:
- patch
- minor
- major
- rc
- beta
- alpha
- release
- version
version:
description: Version
required: false
type: string
dry_run:
description: Dry run
required: true
default: true
type: boolean

env:
CACHE: true

jobs:
build_rust_client:
name: Rust Client
uses: ./.github/workflows/build-rust-client.yml
secrets: inherit

test_rust_client:
name: Rust Client
needs: build_rust_client
uses: ./.github/workflows/test-rust-client.yml
secrets: inherit

publish_crate:
name: Rust Client / Publish Crate
runs-on: ubuntu-latest
needs: test_rust_client
permissions:
contents: write
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.SVC_TOKEN }}

- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV

- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Install cargo-release
uses: metaplex-foundation/actions/install-cargo-release@v1
with:
cache: ${{ env.CACHE }}

- name: Publish Crate
working-directory: ./clients/rust
run: |
if [ "${{ inputs.level }}" == "version" ]; then
BUMP=${{ inputs.version }}
else
BUMP=${{ inputs.level }}
fi
if [ "${{ inputs.dry_run }}" == "false" ]; then
OPTIONS="--no-confirm --execute"
fi
if [ "${{ inputs.level }}" == "version" ]; then
cargo login ${{ secrets.CRATES_TOKEN }}
cargo release $BUMP $OPTIONS
19 changes: 17 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
js_changed: ${{ steps.changes.outputs.js_client }}
rust_changed: ${{ steps.changes.outputs.rust_client }}
permissions:
contents: write
steps:
Expand Down Expand Up @@ -98,9 +99,23 @@ jobs:
with:
filters: .github/file-filters.yml

test_js:
test_js_client:
if: needs.generate_clients.outputs.js_changed == 'true'
name: JS Client
needs: generate_clients
uses: ./.github/workflows/test-js.yml
uses: ./.github/workflows/test-js-client.yml
secrets: inherit

build_rust_client:
if: needs.generate_clients.outputs.rust_changed == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/build-rust-client.yml
secrets: inherit

test_rust_client:
if: needs.generate_clients.outputs.rust_changed == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/test-rust-client.yml
secrets: inherit
File renamed without changes.
42 changes: 42 additions & 0 deletions .github/workflows/test-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test Rust Client

on:
workflow_call:
inputs:
program_matrix:
type: string

env:
CACHE: true

jobs:
test_sdk:
name: Test
runs-on: ubuntu-latest-16-cores
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV

- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Download program builds
uses: actions/download-artifact@v3
with:
name: program-builds

- name: Run tests
shell: bash
working-directory: configs/client-scripts
run: RUST_LOG=error ./test-rust-client.sh
Loading

0 comments on commit d1a1327

Please sign in to comment.