Skip to content

Commit 583ba59

Browse files
committed
*: initial commit
Signed-off-by: Gyuho Lee <[email protected]>
1 parent a42aa76 commit 583ba59

File tree

11 files changed

+399
-0
lines changed

11 files changed

+399
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
name: Test and release
2+
3+
# ref. https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
4+
on:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- "*"
10+
pull_request:
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
static_analysis:
17+
name: Static analysis
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Install Rust
23+
uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: nightly
26+
profile: minimal
27+
components: rustfmt, clippy
28+
override: true
29+
- name: Check Rust version
30+
run: rustc --version
31+
- uses: Swatinem/rust-cache@v1
32+
with:
33+
cache-on-failure: true
34+
- name: Run static analysis tests
35+
shell: bash
36+
run: scripts/static-analysis.sh
37+
38+
check_cargo_unused:
39+
name: Check Cargo unused
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v3
44+
- name: Install Rust
45+
uses: actions-rs/toolchain@v1
46+
with:
47+
toolchain: nightly
48+
profile: minimal
49+
components: rustfmt, clippy
50+
override: true
51+
- name: Check Rust version
52+
run: rustc --version
53+
- uses: Swatinem/rust-cache@v1
54+
with:
55+
cache-on-failure: true
56+
- name: Check unused Cargo dependencies
57+
shell: bash
58+
run: scripts/cargo.unused.sh
59+
60+
unit_tests:
61+
name: Unit tests
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v3
66+
- name: Install Rust
67+
uses: actions-rs/toolchain@v1
68+
with:
69+
toolchain: stable
70+
profile: minimal
71+
override: true
72+
- name: Check Rust version
73+
run: rustc --version
74+
- uses: Swatinem/rust-cache@v1
75+
with:
76+
cache-on-failure: true
77+
- name: Run unit tests
78+
run: scripts/tests.unit.sh
79+
80+
release:
81+
name: Release ${{ matrix.job.target }} (${{ matrix.job.os }})
82+
runs-on: ${{ matrix.job.os }}
83+
needs: [static_analysis, check_cargo_unused, unit_tests]
84+
strategy:
85+
matrix:
86+
job:
87+
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
88+
- os: ubuntu-latest
89+
platform: linux
90+
target: x86_64-unknown-linux-gnu
91+
- os: macos-latest
92+
platform: darwin
93+
target: x86_64-apple-darwin
94+
- os: ubuntu-latest
95+
platform: linux
96+
target: aarch64-unknown-linux-musl
97+
- os: macos-latest
98+
platform: darwin
99+
target: aarch64-apple-darwin
100+
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v3
104+
105+
- name: Install Rust
106+
uses: actions-rs/toolchain@v1
107+
with:
108+
profile: minimal
109+
toolchain: stable
110+
target: ${{ matrix.job.target }}
111+
override: true
112+
- name: Check Rust version
113+
run: rustc --version
114+
115+
- uses: Swatinem/rust-cache@v1
116+
with:
117+
cache-on-failure: true
118+
119+
# ref. https://github.com/gakonst/foundry/blob/master/.github/workflows/cross-platform.yml
120+
- name: Apple M1 setup
121+
if: matrix.job.target == 'aarch64-apple-darwin'
122+
run: |
123+
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
124+
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
125+
126+
# ref. https://github.com/gakonst/foundry/blob/master/.github/workflows/cross-platform.yml
127+
# ref. https://github.com/briansmith/ring/blob/main/mk/install-build-tools.sh
128+
# ref. https://github.com/briansmith/ring/issues/1414
129+
# ref. https://github.com/zellij-org/zellij/blob/main/.github/workflows/release.yml
130+
# ref. https://github.com/sfackler/rust-openssl/issues/621
131+
- name: Linux ARM64 setup with musl-tools
132+
if: matrix.job.target == 'aarch64-unknown-linux-musl'
133+
run: |
134+
sudo apt-get install -y --no-install-recommends pkg-config libssl-dev musl-tools clang llvm
135+
echo "CC_aarch64_unknown_linux_musl=clang" >> $GITHUB_ENV
136+
echo "AR_aarch64_unknown_linux_musl=llvm-ar" >> $GITHUB_ENV
137+
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS=\"-Clink-self-contained=yes -Clinker=rust-lld\"" >> $GITHUB_ENV
138+
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
139+
140+
- name: Compile binaries
141+
env:
142+
RUSTFLAGS: -C link-args=-s
143+
uses: actions-rs/cargo@v1
144+
with:
145+
command: build
146+
args: --release --bin mini-kvvm-rs --target ${{ matrix.job.target }}
147+
148+
- name: Compress binaries
149+
id: release_artifacts
150+
env:
151+
PLATFORM_NAME: ${{ matrix.job.platform }}
152+
TARGET: ${{ matrix.job.target }}
153+
shell: bash
154+
run: |
155+
if [ "$PLATFORM_NAME" == "linux" ]; then
156+
157+
./target/${TARGET}/release/mini-kvvm-rs
158+
cp ./target/${TARGET}/release/mini-kvvm-rs mini-kvvm-rs.${TARGET}
159+
echo "::set-output name=file_name_mini-kvvm-rs::mini-kvvm-rs.${TARGET}"
160+
tar -czvf mini-kvvm-rs_${TARGET}.tar.gz -C ./target/${TARGET}/release mini-kvvm-rs
161+
echo "::set-output name=file_name_mini-kvvm-rs_tar_gz::mini-kvvm-rs_${TARGET}.tar.gz"
162+
163+
elif [ "$PLATFORM_NAME" == "darwin" ]; then
164+
165+
cp ./target/${TARGET}/release/mini-kvvm-rs mini-kvvm-rs.${TARGET}
166+
echo "::set-output name=file_name_mini-kvvm-rs::mini-kvvm-rs.${TARGET}"
167+
gtar -czvf mini-kvvm-rs_${TARGET}.tar.gz -C ./target/${TARGET}/release mini-kvvm-rs
168+
echo "::set-output name=file_name_mini-kvvm-rs_tar_gz::mini-kvvm-rs_${TARGET}.tar.gz"
169+
170+
else
171+
172+
echo "skipping $PLATFORM_NAME"
173+
174+
fi
175+
176+
# release tip from latest commits
177+
# https://github.com/softprops/action-gh-release
178+
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
179+
- name: Release latest
180+
uses: softprops/action-gh-release@v1
181+
if: ${{ github.ref == 'refs/heads/main' }}
182+
with:
183+
name: Latest release
184+
tag_name: latest
185+
prerelease: true
186+
body: Latest builds from the last commit.
187+
files: |
188+
${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs }}
189+
${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs_tar_gz }}
190+
191+
# release only for tags
192+
# https://github.com/softprops/action-gh-release
193+
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
194+
- name: Release tag
195+
uses: softprops/action-gh-release@v1
196+
if: startsWith(github.ref, 'refs/tags/')
197+
with:
198+
name: ${{ github.ref_name }}
199+
tag_name: ${{ github.ref_name }}
200+
draft: true
201+
prerelease: true
202+
body: Release builds for ${{ github.ref_name }}.
203+
files: |
204+
${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs }}
205+
${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs_tar_gz }}

.rustfmt.nightly.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# ref. https://github.com/rust-lang/rustfmt/blob/master/Configurations.md
2+
binop_separator = "Back"
3+
blank_lines_lower_bound = 0
4+
blank_lines_upper_bound = 1
5+
brace_style = "SameLineWhere"
6+
color = "Auto"
7+
combine_control_expr = true
8+
comment_width = 80
9+
condense_wildcard_suffixes = true
10+
control_brace_style = "AlwaysSameLine"
11+
edition = "2021"
12+
empty_item_single_line = true
13+
enum_discrim_align_threshold = 20
14+
error_on_line_overflow = true
15+
error_on_unformatted = false
16+
fn_args_layout = "Tall"
17+
fn_call_width = 60
18+
fn_single_line = false
19+
force_explicit_abi = true
20+
force_multiline_blocks = false
21+
format_code_in_doc_comments = true
22+
format_generated_files = true
23+
format_macro_bodies = true
24+
format_macro_matchers = true
25+
format_strings = true
26+
hard_tabs = false
27+
imports_granularity = "Crate"
28+
imports_indent = "Block"
29+
imports_layout = "Mixed"
30+
indent_style = "Block"
31+
max_width = 100
32+
normalize_doc_attributes = true
33+
reorder_imports = true
34+
trailing_comma = "Vertical"
35+
trailing_semicolon = true
36+
unstable_features = true
37+
use_field_init_shorthand = true
38+
use_small_heuristics = "Off"
39+
use_try_shorthand = true
40+
where_single_line = false
41+
wrap_comments = true

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "mini-kvvm-rs"
3+
version = "0.0.0"
4+
edition = "2021"
5+
rust-version = "1.60"
6+
publish = false
7+
description = "Mini key-value store VM for Avalanche in Rust"
8+
license = "BSD-3-Clause"
9+
homepage = "https://avax.network"
10+
repository = "https://github.com/ava-labs/mini-kvvm-rs"
11+
readme = "README.md"
12+
13+
[dependencies]
14+
clap = { version = "3.1.8", features = ["cargo", "derive"] }
15+
env_logger = "0.9.0"
16+
log = "0.4.16"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1+
2+
![Github Actions](https://github.com/gyuho/mini-kvvm-rs/actions/workflows/test-and-release.yml/badge.svg)
3+
14
# mini-kvvm-rs
5+
26
Mini key-value store VM in Rust for Avalanche
7+
8+
```bash
9+
cd ${HOME}/go/src/github.com/ava-labs/subnet-cli
10+
go install -v .
11+
subnet-cli create VMID minikvvmrs
12+
# qBnAKUQ2mxjMHCneWjq5nFuhntoWrsKsCjaYSouFjpuCB2o5d
13+
14+
cd ${HOME}/mini-kvvm-rs
15+
./scripts/build.x86_64-linux-musl.sh
16+
cp \
17+
./target/x86_64-unknown-linux-musl/release/mini-kvvm-rs \
18+
${HOME}/go/src/github.com/ava-labs/avalanchego/build/plugins/qBnAKUQ2mxjMHCneWjq5nFuhntoWrsKsCjaYSouFjpuCB2o5d
19+
```

scripts/build.release.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -xue
3+
4+
if ! [[ "$0" =~ scripts/build.release.sh ]]; then
5+
echo "must be run from repository root"
6+
exit 255
7+
fi
8+
9+
# "--bin" can be specified multiple times for each directory in "bin/*" or workspaces
10+
cargo build \
11+
--release \
12+
--bin mini-kvvm-rs
13+
14+
./target/release/mini-kvvm-rs -V

scripts/build.x86_64-linux-musl.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -xue
3+
4+
if ! [[ "$0" =~ scripts/build.x86_64-linux-musl.sh ]]; then
5+
echo "must be run from repository root"
6+
exit 255
7+
fi
8+
9+
# https://github.com/clux/muslrust
10+
docker pull clux/muslrust
11+
docker run -v $PWD:/volume --rm -t clux/muslrust \
12+
cargo build \
13+
--release \
14+
--bin mini-kvvm-rs \
15+
--target x86_64-unknown-linux-musl
16+
17+
BIN_PATH=./target/x86_64-unknown-linux-musl/release
18+
${BIN_PATH}/mini-kvvm-rs --help || true

scripts/cargo.unused.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -xue
3+
4+
if ! [[ "$0" =~ scripts/cargo.unused.sh ]]; then
5+
echo "must be run from repository root"
6+
exit 255
7+
fi
8+
9+
# cargo install cargo-udeps --locked
10+
# https://github.com/est31/cargo-udeps
11+
cargo install cargo-udeps --locked
12+
cargo +nightly udeps
13+
14+
echo "ALL SUCCESS!"

scripts/static-analysis.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -xue
3+
4+
if ! [[ "$0" =~ scripts/static-analysis.sh ]]; then
5+
echo "must be run from repository root"
6+
exit 255
7+
fi
8+
9+
# https://rust-lang.github.io/rustup/installation/index.html
10+
# rustup toolchain install nightly --allow-downgrade --profile minimal --component clippy
11+
#
12+
# https://github.com/rust-lang/rustfmt
13+
# rustup component add rustfmt
14+
# rustup component add rustfmt --toolchain nightly
15+
# rustup component add clippy
16+
# rustup component add clippy --toolchain nightly
17+
18+
rustup default stable
19+
cargo fmt --all --verbose -- --check
20+
21+
# TODO: enable nightly fmt
22+
rustup default nightly
23+
cargo +nightly fmt --all -- --config-path .rustfmt.nightly.toml --verbose --check || true
24+
25+
# TODO: enable this
26+
cargo +nightly clippy --all --all-features -- -D warnings || true
27+
28+
rustup default stable
29+
30+
echo "ALL SUCCESS!"

scripts/tests.unit.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -xue
3+
4+
if ! [[ "$0" =~ scripts/tests.unit.sh ]]; then
5+
echo "must be run from repository root"
6+
exit 255
7+
fi
8+
9+
RUST_LOG=debug cargo test --all --all-features -- --show-output
10+
# RUST_LOG=debug cargo test --all --all-features -- --show-output --ignored
11+
12+
echo "ALL SUCCESS!"

0 commit comments

Comments
 (0)