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

Build ruby #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
185 changes: 185 additions & 0 deletions .github/workflows/ruby.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Ruby
env:
WORKING_DIRECTORY: bindings/c
MACOSX_DEPLOYMENT_TARGET: '10.13'

# this doesn't work until merged into master
# on:
# workflow_dispatch:

on:
pull_request:
paths-ignore:
# - 'bindings/**'
- 'examples/**'
- '.github/workflows/python.yaml'
- '.github/workflows/python-version-bump.yaml'
- '.github/workflows/node.yaml'
- '.github/workflows/node-version-bump.yaml'
# push:
# branches:
# - master
# tags-ignore:
# - '**'
# paths-ignore:
# # - 'bindings/**'
# - 'examples/**'
# - '.github/workflows/python.yaml'
# - '.github/workflows/python-version-bump.yaml'
# - '.github/workflows/node.yaml'
# - '.github/workflows/node-version-bump.yaml'

permissions: write-all

jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: 'x86_64-apple-darwin'
- host: macos-latest
target: 'aarch64-apple-darwin'
- host: ubuntu-latest
target: 'x86_64-unknown-linux-gnu'
- host: ubuntu-latest
target: 'aarch64-unknown-linux-gnu'
- host: windows-latest
target: 'x86_64-pc-windows-msvc'

name: ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}

steps:
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
target: ${{ matrix.settings.target }}
- uses: marcopolo/cargo@master
with:
use-cross: true
working-directory: bindings/c
# TODO: (Ruby) changed from all-features to no-default-features. Is that correct?
args: --release --no-default-features --target=${{ matrix.settings.target }} --locked
command: build

- name: List folder
if: ${{ matrix.settings.target != 'x86_64-pc-windows-msvc' }}
run: ls -lh ../../target/${{ matrix.settings.target }}/release

- name: List folder Windows
if: ${{ matrix.settings.target == 'x86_64-pc-windows-msvc' }}
run: dir ..\..\target\${{ matrix.settings.target }}\release

- name: Upload artifact
uses: actions/upload-artifact@v3
if: ${{ matrix.settings.target != 'x86_64-pc-windows-msvc' }}
with:
name: ${{ matrix.settings.target }}
path: target/${{ matrix.settings.target }}/release/libzen_ffi.[ads]*
if-no-files-found: error

- name: Upload artifact Windows (.lib)
uses: actions/upload-artifact@v3
if: ${{ matrix.settings.target == 'x86_64-pc-windows-msvc' }}
with:
name: ${{ matrix.settings.target }}
path: target/${{ matrix.settings.target }}/release/zen_ffi.lib
if-no-files-found: error

- name: Upload artifact Windows (.dll)
uses: actions/upload-artifact@v3
if: ${{ matrix.settings.target == 'x86_64-pc-windows-msvc' }}
with:
name: ${{ matrix.settings.target }}
path: target/${{ matrix.settings.target }}/release/zen_ffi.dll
if-no-files-found: error

# copy-common:
# name: Upload common file
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3

# - name: Upload artifact
# uses: actions/upload-artifact@v3
# with:
# name: common
# path: bindings/c/zen_engine.h
# if-no-files-found: error
# release:
# name: Release
# runs-on: ubuntu-latest
# needs:
# - build
# - copy-common
# steps:
# - name: Checkout zen-go
# uses: actions/checkout@v3
# with:
# repository: gorules/zen-go
# persist-credentials: false
# token: ${{ secrets.PAT }}
# - name: Download all artifacts
# uses: actions/download-artifact@v3
# with:
# path: artifacts

# - name: Move artifacts
# run: |
# mv artifacts/aarch64-apple-darwin/libzen_ffi.a deps/darwin_arm64/
# mv artifacts/x86_64-apple-darwin/libzen_ffi.a deps/darwin_amd64/
# mv artifacts/aarch64-unknown-linux-gnu/libzen_ffi.a deps/linux_arm64/
# mv artifacts/x86_64-unknown-linux-gnu/libzen_ffi.a deps/linux_amd64/
# mv artifacts/x86_64-pc-windows-msvc/zen_ffi.lib deps/windows_amd64/libzen_ffi.lib
# mv artifacts/common/zen_engine.h zen_engine.h
# rm -rf artifacts

# - name: Set branch name
# run: |
# echo "BRANCH_NAME=chore/${{ github.run_id }}-${{ github.run_attempt }}" >> $GITHUB_ENV

# - run: git config -l

# - name: Commit
# run: |
# BRANCH_NAME="${{ env.BRANCH_NAME }}"
# git checkout -b $BRANCH_NAME
# # Setup the committers identity.
# git config user.email "[email protected]"
# git config user.name "Bot GoRules"
# git config http.postBuffer 524288000
# git config http.lowSpeedTime 600

# # Commit the changes and push the feature branch to origin
# git add .
# git commit -m "chore: update deps"
# - name: Push changes
# uses: ad-m/github-push-action@master
# with:
# repository: gorules/zen-go
# github_token: ${{ secrets.PAT }}
# branch: ${{ env.BRANCH_NAME }}
# - name: Create PR
# run: |
# BRANCH_NAME="${{ env.BRANCH_NAME }}"
# # Store the PAT in a file that can be accessed by the
# # GitHub CLI.
# echo "${{ secrets.PAT }}" > token.txt

# # Authorize GitHub CLI for the current repository and
# # create a pull-requests containing the updates.
# echo "Authorizing for PR"
# gh auth login --with-token < token.txt
# gh pr create \
# --body "" \
# --title "chore: update deps" \
# --head "$BRANCH_NAME" \
# --base "master"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ execute [JSON Decision Model (JDM)](https://gorules.io/docs/rules-engine/json-de

An open-source React editor is available on our [JDM Editor](https://github.com/gorules/jdm-editor) repo.

## TMP: building ruby instructions

```
cargo build --release --no-default-features --target aarch64-apple-darwin
```

## Usage

ZEN Engine is built as embeddable BRE for your **Rust**, **NodeJS**, **Python** or **Go** applications.
Expand Down
4 changes: 3 additions & 1 deletion bindings/c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ zen-expression = { path = "../../core/expression" }
zen-tmpl = { path = "../../core/template" }

[lib]
crate-type = ["staticlib"]
# crate-type = ["cdylib"]
crate-type = ["cdylib", "staticlib"]
# crate-type = ["staticlib"]

[build-dependencies]
cbindgen = "0.26.0"
Expand Down
15 changes: 15 additions & 0 deletions bindings/c/src/languages/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub extern "C" fn zen_engine_new_golang(
}

#[allow(unused_doc_comments)]
#[cfg(feature = "go")]
/// cbindgen:ignore
extern "C" {
fn zen_engine_go_loader_callback(cb_ptr: usize, key: *const c_char) -> ZenDecisionLoaderResult;
Expand All @@ -97,3 +98,17 @@ extern "C" {
request: *const c_char,
) -> ZenCustomNodeResult;
}

#[allow(unused_doc_comments)]
#[cfg(not(feature = "go"))]
extern "C" {
fn zen_engine_go_loader_callback(cb_ptr: usize, key: *const c_char) -> ZenDecisionLoaderResult {
unimplemented!()
}
fn zen_engine_go_custom_node_callback(
cb_ptr: usize,
request: *const c_char,
) -> ZenCustomNodeResult {
unimplemented!()
}
}
42 changes: 42 additions & 0 deletions ruby-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
TARGETS=(
"x86_64-unknown-linux-gnu"
"aarch64-unknown-linux-gnu"
"x86_64-unknown-linux-musl"
)

set -e

for target in "${TARGETS[@]}"; do
echo "Building for $target..."

case $target in
"x86_64-unknown-linux-gnu")
DOCKER_PLATFORM="linux/amd64"
PACKAGES="build-essential"
;;
"aarch64-unknown-linux-gnu")
DOCKER_PLATFORM="linux/amd64"
PACKAGES="gcc-aarch64-linux-gnu"
;;
"x86_64-unknown-linux-musl")
DOCKER_PLATFORM="linux/amd64"
PACKAGES="musl-tools"
;;
*)
echo "Unknown target: $target"
exit 1
;;
esac

docker run --rm --platform $DOCKER_PLATFORM \
-v "$(pwd)":/workspace \
-w /workspace/bindings/c \
rust:1.73 bash -c "\
apt-get update && \
apt-get install -y $PACKAGES && \
rustup target add $target && \
QUICKJS_SYSTEM_MALLOC=1 \
QUICKJS_DISABLE_ATOMICS=1 \
cargo build --target $target --release --no-default-features"
done
Loading