Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Generate rust code from schemas #29

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading