Skip to content

Commit

Permalink
Merge pull request #2 from dojoengine/ci
Browse files Browse the repository at this point in the history
Setup ci
  • Loading branch information
tarrencev committed Nov 2, 2023
2 parents f3b793a + 9b79896 commit 7426b91
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 31 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: ci

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.70.0

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@v2
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install nextest test runner
uses: taiki-e/install-action@nextest
- run: |
cargo nextest run --all-features
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
targets: wasm32-unknown-unknown
components: clippy
- uses: Swatinem/rust-cache@v2
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: scripts/clippy.sh

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt
- uses: Swatinem/rust-cache@v2
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: scripts/rust_fmt.sh --check
118 changes: 118 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: release

on:
push:
tags:
- "*"

env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.70.0

jobs:
prepare:
name: Prepare release
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
fetch-depth: 0

build-and-release:
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
needs: prepare
runs-on: ${{ matrix.job.os }}
strategy:
matrix:
job:
# The OS is used for the runner
# The platform is a generic platform name
# The target is used by Cargo
# The arch is either 386, arm64 or amd64
# The svm target platform to use for the binary https://github.com/roynalnaruto/svm-rs/blob/84cbe0ac705becabdc13168bae28a45ad2299749/svm-builds/build.rs#L4-L24
- os: ubuntu-latest-32-cores
platform: linux
target: x86_64-unknown-linux-gnu
arch: amd64
- os: ubuntu-latest-32-cores
platform: linux
target: aarch64-unknown-linux-gnu
arch: arm64
svm_target_platform: linux-aarch64
- os: macos-latest
platform: darwin
target: x86_64-apple-darwin
arch: amd64
- os: macos-latest
platform: darwin
target: aarch64-apple-darwin
arch: arm64
- os: windows-latest
platform: win32
target: x86_64-pc-windows-msvc
arch: amd64

steps:
- uses: actions/checkout@v3

- uses: dtolnay/rust-toolchain@master
name: Rust Toolchain Setup
with:
targets: ${{ matrix.job.target }}
toolchain: ${{ env.RUST_VERSION }}

- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Apple M1 setup
if: ${{ matrix.job.target == 'aarch64-apple-darwin' }}
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Linux ARM setup
if: ${{ matrix.job.target == 'aarch64-unknown-linux-gnu' }}
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu libssl-dev
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Build binaries
run: cargo build --release --target ${{ matrix.job.target }}

- name: debug
run: ls target/${{ matrix.job.arch }}/release

- name: Package
run: |
if [[ "${{ matrix.job.os }}" == "macos-latest" ]]; then
tar -czvf torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz target/${{ matrix.job.arch }}/release/libtorii_c.dylib
elif [[ "${{ matrix.job.os }}" == "windows-latest" ]]; then
tar -czvf torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz target/${{ matrix.job.arch }}/release/libtorii_c.dll
else
tar -czvf torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz target/${{ matrix.job.arch }}/release/libtorii_c.so
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz
asset_name: torii-${{ matrix.job.target }}-${{ matrix.job.arch }}.tar.gz
asset_content_type: application/gzip
28 changes: 14 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
edition = "2021"
name = "torii-unity"
name = "torii-c"
version = "0.3.1"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ This package provides C bindings for the Torii Client SDK. The approach is to ge

```
cargo build --release
gcc example/main.c -L target/release -l torii_unity -I ..
gcc example/main.c -L target/release -l torii_c -I ..
```
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate cbindgen;

use std::env;

fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();

let mut config: cbindgen::Config = Default::default();
config.language = cbindgen::Language::C;
let config = cbindgen::Config {
language: cbindgen::Language::C,
..Default::default()
};

cbindgen::Builder::new()
.with_config(config)
Expand Down
3 changes: 3 additions & 0 deletions scripts/rust_fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo +nightly fmt --check --all -- "$@"
26 changes: 15 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub struct FieldElement {
data: [u8; 32],
}

impl Into<starknet::core::types::FieldElement> for &FieldElement {
fn into(self) -> starknet::core::types::FieldElement {
starknet::core::types::FieldElement::from_bytes_be(&self.data).unwrap()
impl From<&FieldElement> for starknet::core::types::FieldElement {
fn from(val: &FieldElement) -> Self {
starknet::core::types::FieldElement::from_bytes_be(&val.data).unwrap()
}
}

Expand All @@ -29,10 +29,10 @@ pub struct EntityModel {
pub keys_len: usize,
}

impl Into<dojo_types::schema::EntityModel> for &EntityModel {
fn into(self) -> dojo_types::schema::EntityModel {
let model = unsafe { CStr::from_ptr(self.model).to_string_lossy().into_owned() };
let keys = unsafe { std::slice::from_raw_parts(self.keys, self.keys_len).to_vec() };
impl From<&EntityModel> for dojo_types::schema::EntityModel {
fn from(val: &EntityModel) -> Self {
let model = unsafe { CStr::from_ptr(val.model).to_string_lossy().into_owned() };
let keys = unsafe { std::slice::from_raw_parts(val.keys, val.keys_len).to_vec() };

dojo_types::schema::EntityModel {
model,
Expand All @@ -42,7 +42,8 @@ impl Into<dojo_types::schema::EntityModel> for &EntityModel {
}

#[no_mangle]
pub extern "C" fn client_new(
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn client_new(
torii_url: *const c_char,
rpc_url: *const c_char,
world: &FieldElement,
Expand Down Expand Up @@ -79,7 +80,8 @@ pub extern "C" fn client_new(
}

#[no_mangle]
pub extern "C" fn client_add_entities_to_sync(
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn client_add_entities_to_sync(
client: *mut ToriiClient,
entities: *const EntityModel,
entities_len: usize,
Expand Down Expand Up @@ -107,7 +109,8 @@ pub extern "C" fn client_add_entities_to_sync(
}

#[no_mangle]
pub extern "C" fn client_remove_entities_to_sync(
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn client_remove_entities_to_sync(
client: *mut ToriiClient,
entities: *const EntityModel,
entities_len: usize,
Expand Down Expand Up @@ -139,7 +142,8 @@ pub extern "C" fn client_remove_entities_to_sync(
// back into a Box<ToriiClient>, which gets dropped at the end of the scope,
// deallocating the memory.
#[no_mangle]
pub extern "C" fn client_free(client: *mut ToriiClient) {
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn client_free(client: *mut ToriiClient) {
if !client.is_null() {
unsafe {
let _ = Box::from_raw(client);
Expand Down

0 comments on commit 7426b91

Please sign in to comment.