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 Jan 11, 2024
1 parent 654d91b commit 2031220
Show file tree
Hide file tree
Showing 9 changed files with 5,132 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ jobs:
run: |
rustup target add riscv64imac-unknown-none-elf
- name: Schemas Is Up to Date
run: |
make -f contracts.mk clean-schemas schemas
git diff --exit-code .
- name: Build & Test
run: make -f contracts.mk
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
17 changes: 12 additions & 5 deletions contracts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ CHECKSUM_FILE := build/checksums-$(MODE).txt
checksum: build
sha256sum build/$(MODE)/* > $(CHECKSUM_FILE)

inspect:
echo TOP=$(TOP)
echo $(dir $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

.PHONY: build test check clippy fmt cargo clean prepare checksum inpsect
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: build test check clippy fmt cargo clean prepare checksum
.PHONY: 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 2031220

Please sign in to comment.