Skip to content

Commit 961c14c

Browse files
authored
refactor: crates for c, wasm core (#155)
1 parent 2c5fee6 commit 961c14c

29 files changed

+9402
-2753
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Install nextest test runner
2929
uses: taiki-e/install-action@nextest
3030
- run: |
31-
cargo nextest run --all-features --no-tests=pass
31+
cargo nextest run --workspace --all-features --no-tests=pass
3232
3333
ensure-wasm:
3434
name: Check WASM compilation
@@ -46,7 +46,25 @@ jobs:
4646
- name: Install wasm32 target
4747
run: rustup target add wasm32-unknown-unknown
4848
- name: Compile WASM
49-
run: cargo build --release --target wasm32-unknown-unknown
49+
run: cargo build --release --target wasm32-unknown-unknown -p wasm
50+
51+
ensure-c:
52+
name: Check C bindings compilation
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v3
56+
# Install system dependencies
57+
- name: Install dependencies
58+
run: sudo apt-get update && sudo apt-get install -y libdbus-1-dev pkg-config
59+
- uses: dtolnay/rust-toolchain@master
60+
with:
61+
toolchain: ${{ env.RUST_VERSION }}
62+
- uses: Swatinem/rust-cache@v2
63+
- uses: arduino/setup-protoc@v1
64+
with:
65+
repo-token: ${{ secrets.GITHUB_TOKEN }}
66+
- name: Compile C bindings
67+
run: cargo build --release -p c
5068

5169
clippy:
5270
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ jobs:
4646
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
4747

4848
- name: Build WASM (no-modules)
49-
run: wasm-pack build --out-dir pkg-no-modules --release --target no-modules
49+
run: wasm-pack build crates/wasm --out-dir ../../pkg-no-modules --release --target no-modules
5050

5151
- name: Build WASM (web)
52-
run: wasm-pack build --out-dir pkg-web --release --target web
52+
run: wasm-pack build crates/wasm --out-dir ../../pkg-web --release --target web
5353

5454
- name: Package WASM builds
5555
id: wasm_artifacts
@@ -82,6 +82,22 @@ jobs:
8282
platform: linux
8383
target: aarch64-unknown-linux-gnu
8484
arch: arm64
85+
- os: ubuntu-latest
86+
platform: android
87+
target: aarch64-linux-android
88+
arch: arm64
89+
- os: ubuntu-latest
90+
platform: android
91+
target: armv7-linux-androideabi
92+
arch: armv7
93+
- os: ubuntu-latest
94+
platform: android
95+
target: i686-linux-android
96+
arch: x86
97+
- os: ubuntu-latest
98+
platform: android
99+
target: x86_64-linux-android
100+
arch: x86_64
85101
- os: macos-latest
86102
platform: darwin
87103
target: x86_64-apple-darwin
@@ -133,9 +149,9 @@ jobs:
133149
- name: Build binaries
134150
run: |
135151
if [[ "${{ runner.os }}" == "Linux" ]]; then
136-
cross build --release --target ${{ matrix.job.target }}
152+
cross build --release --target ${{ matrix.job.target }} -p c
137153
else
138-
cargo build --release --target ${{ matrix.job.target }}
154+
cargo build --release --target ${{ matrix.job.target }} -p c
139155
fi
140156
shell: bash
141157

@@ -144,13 +160,13 @@ jobs:
144160
shell: bash
145161
run: |
146162
if [[ "${{ matrix.job.os }}" == "macos-latest" ]]; then
147-
tar -czvf torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz dojo.h target/${{ matrix.job.target }}/release/libdojo_c.dylib
163+
tar -czvf dojo-c-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz crates/c/dojo.h target/${{ matrix.job.target }}/release/libc.dylib
148164
elif [[ "${{ matrix.job.os }}" == "windows-latest" ]]; then
149-
tar -czvf torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz dojo.h target/${{ matrix.job.target }}/release/dojo_c.dll
165+
tar -czvf dojo-c-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz crates/c/dojo.h target/${{ matrix.job.target }}/release/c.dll
150166
else
151-
tar -czvf torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz dojo.h target/${{ matrix.job.target }}/release/libdojo_c.so
167+
tar -czvf dojo-c-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz crates/c/dojo.h target/${{ matrix.job.target }}/release/libc.so
152168
fi
153-
echo "file_name=torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz" >> $GITHUB_OUTPUT
169+
echo "file_name=dojo-c-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz" >> $GITHUB_OUTPUT
154170
155171
- name: Create release
156172
uses: softprops/action-gh-release@v1

Cargo.lock

Lines changed: 73 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
[package]
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"crates/dojo-core",
5+
"crates/c",
6+
"crates/wasm",
7+
]
8+
9+
[workspace.package]
210
edition = "2021"
3-
name = "dojo-c"
411
version = "1.8.3"
512

6-
[lib]
7-
crate-type = ["cdylib", "rlib", "staticlib"]
8-
9-
[dependencies]
13+
[workspace.dependencies]
14+
# Dojo dependencies
1015
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "0afeb1bc" }
1116
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "0afeb1bc" }
1217
torii-proto = { git = "https://github.com/dojoengine/torii", rev = "8378c63" }
1318
torii-client = { git = "https://github.com/dojoengine/torii", rev = "8378c63" }
1419
torii-grpc-client = { git = "https://github.com/dojoengine/torii", rev = "8378c63" }
1520

21+
# Starknet dependencies
1622
starknet = "0.17.0"
1723
starknet-crypto = "0.8"
1824
starknet-types-core = { version = "0.2.0", features = ["arbitrary"] }
1925

26+
# Core dependencies
2027
parking_lot = "0.12.1"
2128
tokio = { version = "1.39.2", default-features = false, features = ["rt"] }
2229
url = "2.5.0"
@@ -26,11 +33,14 @@ serde_json = "1.0.115"
2633
tokio-stream = "0.1.14"
2734
futures = "0.3.30"
2835
futures-channel = "0.3.30"
29-
wasm-bindgen = "0.2.92"
3036
stream-cancel = "0.8.2"
3137
cainome = "0.10.1"
3238
lazy_static = "1.5.0"
39+
crypto-bigint = "0.5.5"
40+
chrono = "0.4.41"
3341

42+
# WASM dependencies
43+
wasm-bindgen = "0.2.92"
3444
serde-wasm-bindgen = "0.6.3"
3545
wasm-bindgen-futures = "0.4.39"
3646
js-sys = "0.3.77"
@@ -41,25 +51,18 @@ web-sys = { version = "0.3.77", features = [
4151
'WorkerGlobalScope',
4252
'console',
4353
] }
44-
crypto-bigint = "0.5.5"
4554
tsify-next = { version = "0.5.4", features = ["js"] }
4655
instant = { version = "0.1.13", features = ["wasm-bindgen"] }
4756
gloo-timers = { version = "0.3.0", features = ["futures"] }
4857
gloo-utils = { version = "0.2.0", features = ["serde"] }
4958
num-bigint = "0.4.6"
59+
console_error_panic_hook = "0.1.5"
5060
num-traits = "0.2.19"
51-
chrono = "0.4.41"
52-
53-
[build-dependencies]
54-
# this addresses issue with cyclical dependencies when generating C header
55-
# see. https://github.com/mozilla/cbindgen/issues/43
56-
# cbindgen = { git = "https://github.com/flaviojs/cbindgen_tmp", branch = "resolve-order-dependencies-clike" }
57-
# cbindgen = "0.29"
58-
cbindgen = { git = "https://github.com/Larkooo/cbindgen", branch = "no-c-forward-enum" }
59-
6061

61-
[dev-dependencies]
62-
wasm-bindgen-test = "0.3.33"
62+
# Internal crates
63+
dojo-core = { path = "crates/dojo-core" }
64+
c = { path = "crates/c" }
65+
wasm = { path = "crates/wasm" }
6366

6467
[patch.crates-io]
6568
crunchy = { git = "https://github.com/nmathewson/crunchy", branch = "cross-compilation-fix" }

Cross.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ pre-build = [
1111
"protoc --version"
1212
]
1313

14+
[target.aarch64-linux-android]
15+
image = "ghcr.io/cross-rs/aarch64-linux-android:main"
16+
17+
[target.armv7-linux-androideabi]
18+
image = "ghcr.io/cross-rs/armv7-linux-androideabi:main"
19+
20+
[target.i686-linux-android]
21+
image = "ghcr.io/cross-rs/i686-linux-android:main"
22+
23+
[target.x86_64-linux-android]
24+
image = "ghcr.io/cross-rs/x86_64-linux-android:main"
25+

crates/c/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "c"
3+
version.workspace = true
4+
edition.workspace = true
5+
6+
[lib]
7+
crate-type = ["cdylib", "rlib", "staticlib"]
8+
9+
[dependencies]
10+
dojo-core = { workspace = true }
11+
12+
dojo-world.workspace = true
13+
dojo-types.workspace = true
14+
torii-proto.workspace = true
15+
torii-client.workspace = true
16+
17+
starknet.workspace = true
18+
starknet-crypto.workspace = true
19+
20+
tokio.workspace = true
21+
url.workspace = true
22+
anyhow.workspace = true
23+
serde.workspace = true
24+
serde_json.workspace = true
25+
tokio-stream.workspace = true
26+
futures.workspace = true
27+
stream-cancel.workspace = true
28+
cainome.workspace = true
29+
lazy_static.workspace = true
30+
crypto-bigint.workspace = true
31+
chrono.workspace = true
32+
33+
[build-dependencies]
34+
cbindgen = { git = "https://github.com/Larkooo/cbindgen", branch = "no-c-forward-enum" }
File renamed without changes.

0 commit comments

Comments
 (0)