Skip to content

Commit

Permalink
✨ Generate rust code from schemas
Browse files Browse the repository at this point in the history
Create a crate ckb-dao-cobuild-schemas and generate the rust code in it.
  • Loading branch information
doitian committed Feb 2, 2024
1 parent 6ad9f2e commit 4df5f0f
Show file tree
Hide file tree
Showing 9 changed files with 5,161 additions and 3 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ env:
CARGO_TERM_COLOR: always

jobs:
check-schemas:
name: Contract - Check Schemas
timeout-minutes: 15
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Set up Clang
uses: egor-tensin/setup-clang@v1
with:
version: 17

- name: Setup up Rust
run: |
rustup target add riscv64imac-unknown-none-elf
- name: Schemas Is Up to Date
run: |
cargo install moleculec --locked
make clean-schemas schemas
git diff --exit-code .
linters:
name: Contract - Linters
timeout-minutes: 15
Expand Down Expand Up @@ -67,4 +93,11 @@ jobs:
rustup target add riscv64imac-unknown-none-elf
- name: Build & Test
run: make contract
run: |
touch crates/ckb-dao-cobuild-schemas/src/schemas/*
make contract
- uses: actions/upload-artifact@v4
with:
name: contracts
path: build/release/
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"

members = [
"crates/ckb-dao-cobuild-schemas",
# Please don't remove the following line, we use it to automatically
# detect insertion point for newly generated crates.
# @@INSERTION_POINT@@
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ web:
pnpm lint
pnpm test

contract:
contract: schemas
make -f contracts.mk build
make CARGO_ARGS="-- --nocapture" -f contracts.mk test

.PHONY: all web contract
SCHEMA_MOL_FILES := $(wildcard schemas/*.mol)
SCHEMA_RUST_FILES := $(patsubst %.mol,crates/ckb-dao-cobuild-schemas/src/%.rs,$(SCHEMA_MOL_FILES))
crates/ckb-dao-cobuild-schemas/src/%.rs: %.mol
moleculec --language rust --schema-file $< > $@
cargo fmt

schemas: $(SCHEMA_RUST_FILES)
clean-schemas:
rm -f $(SCHEMA_RUST_FILES)

.PHONY: all web contract schemas clean-schemas
9 changes: 9 additions & 0 deletions crates/ckb-dao-cobuild-schemas/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "ckb-dao-cobuild-schemas"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
molecule = { version = "0.7.5", default-features = false }
3 changes: 3 additions & 0 deletions crates/ckb-dao-cobuild-schemas/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod schemas;

pub use schemas::dao::*;
Loading

0 comments on commit 4df5f0f

Please sign in to comment.