diff --git a/.github/actions/install-sbpf/action.yml b/.github/actions/install-sbpf/action.yml new file mode 100644 index 0000000..8fcc96d --- /dev/null +++ b/.github/actions/install-sbpf/action.yml @@ -0,0 +1,29 @@ +# cspell:word sbpf +--- +description: 'Install sbpf CLI' +inputs: + sbpf-cli-revision: + description: 'sbpf CLI rev (git commit hash, tag, or branch) to install' + required: true +name: 'Install sbpf CLI' +runs: + steps: + - id: 'cache-sbpf' + name: 'Cache sbpf CLI' + uses: 'actions/cache@v5' + with: + key: 'sbpf-cli-${{ inputs.sbpf-cli-revision }}-${{ runner.os }}-${{ + runner.arch }}' + path: '~/.cargo/bin/sbpf' + - if: 'steps.cache-sbpf.outputs.cache-hit != ''true''' + name: 'Install sbpf CLI' + run: >- + cargo install + --git https://github.com/blueshift-gg/sbpf.git + --rev ${{ inputs.sbpf-cli-revision }} + shell: 'sh' + - name: 'Verify sbpf CLI' + run: 'sbpf --version' + shell: 'sh' + using: 'composite' +... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 789bd1d..4752f20 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,7 @@ env: NODE_VERSION: '25' PRE_COMMIT_VERSION: '4.5.1' PYTHON_VERSION: '3.14.3' + RUST_VERSION: 'stable' jobs: lint: env: @@ -28,6 +29,12 @@ jobs: steps.apt-cache.outputs.cache-hit == 'true' run: 'echo "$HOME/.local/bin" >> "$GITHUB_PATH"' - uses: 'actions/checkout@v6' + - uses: 'dtolnay/rust-toolchain@stable' + with: + components: 'clippy, rustfmt' + - uses: 'Swatinem/rust-cache@v2' + with: + shared-key: 'rust-${{ runner.os }}' - uses: 'actions/setup-node@v6' with: node-version: '${{ env.NODE_VERSION }}' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..907abb5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +# cspell:word sbpf +--- +env: + # https://github.com/blueshift-gg/sbpf/pull/109 + SBPF_CLI_REV: '5583e2b167e540b0143311aceb62afd98bfaa67b' +jobs: + test: + name: 'Test' + runs-on: 'ubuntu-latest' + steps: + - uses: 'actions/checkout@v6' + - uses: 'dtolnay/rust-toolchain@stable' + - uses: 'Swatinem/rust-cache@v2' + with: + shared-key: 'rust-${{ runner.os }}' + - uses: './.github/actions/install-sbpf' + with: + sbpf-cli-revision: '${{ env.SBPF_CLI_REV }}' + - name: 'Build assembly' + run: 'make asm' + - name: 'Run tests' + run: 'make test' +name: 'Test' +'on': + pull_request: null +... diff --git a/Makefile b/Makefile index af1a931..3176eb9 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,17 @@ .PHONY: all .PHONY: asm .PHONY: clean +.PHONY: lint .PHONY: test SBPF_ARCH ?= v0 DEPLOY_DIR ?= target/asm -all: docs-prettier pre-commit-lint +all: lint test clean: cargo clean + rm -rf docs/node_modules docs/.vitepress/cache docs/.vitepress/dist + rm -rf $(DEPLOY_DIR) # Run test cases. test: asm @@ -37,6 +40,9 @@ docs-prod: && npx vitepress build \ && (sleep 1 && open http://localhost:4173 &) && npx vitepress preview +# Run all lint checks. +lint: pre-commit-lint docs-prettier + # Run pre-commit lint checks on all files. pre-commit-lint: pre-commit run --config cfg/pre-commit/lint.yml --all-files diff --git a/cfg/dictionary.txt b/cfg/dictionary.txt index 37c44d8..60f5798 100644 --- a/cfg/dictionary.txt +++ b/cfg/dictionary.txt @@ -1,7 +1,9 @@ +clippy clrs codegen dasmac dropset +dtolnay globl idents insn @@ -16,5 +18,6 @@ repr sbpf shiki solana +swatinem vite vitepress diff --git a/cfg/pre-commit/lint.yml b/cfg/pre-commit/lint.yml index 3920335..f2f3cfc 100644 --- a/cfg/pre-commit/lint.yml +++ b/cfg/pre-commit/lint.yml @@ -66,6 +66,21 @@ repos: id: 'pretty-format-json' repo: 'https://github.com/pre-commit/pre-commit-hooks' rev: 'v6.0.0' +- hooks: + - entry: 'cargo fmt --' + id: 'rustfmt' + language: 'system' + name: 'rustfmt' + types: + - 'rust' + - entry: 'cargo clippy --all-targets -- -D warnings' + id: 'clippy' + language: 'system' + name: 'clippy' + pass_filenames: false + types: + - 'rust' + repo: 'local' - hooks: - id: 'checkmake' repo: 'https://github.com/checkmake/checkmake.git' diff --git a/macros/src/lib.rs b/macros/src/lib.rs index aef7031..578d2a1 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -43,7 +43,13 @@ pub fn constant_group(input: TokenStream) -> TokenStream { pub fn discriminant_enum(attr: TokenStream, item: TokenStream) -> TokenStream { let target = parse_macro_input!(attr as LitStr); let input = parse_macro_input!(item as syn::ItemEnum); - TokenStream::from(enum_to_asm::expand(&target.value(), "DISC", 0, "u8", &input)) + TokenStream::from(enum_to_asm::expand( + &target.value(), + "DISC", + 0, + "u8", + &input, + )) } /// Attribute macro for error code enums. diff --git a/src/lib.rs b/src/lib.rs index e69de29..8b13789 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -0,0 +1 @@ +