Skip to content

Build Project

Build Project #2

Workflow file for this run

name: Build Project
on:
workflow_call:
inputs:
release:
type: boolean
default: false
required: false
workflow_dispatch:
inputs:
release:
type: boolean
default: true
required: false
jobs:
rust-build:
strategy:
matrix:
platform: ['linux', 'windows', 'darwin']
arch: ['x86_64', 'aarch64']
include:
- platform: linux
os: ubuntu-24.04
vendor: unknown
env: -gnu
lib: libnative.so
- platform: windows
os: windows-2019
vendor: pc
env: '-msvc'
lib: native.dll
- platform: darwin
os: macos-14
vendor: apple
lib: libnative.dylib
exclude:
- platform: linux
arch: aarch64
runs-on: ${{ matrix.os }}
env:
TARGET_TRIPLET: ${{ matrix.arch }}-${{ matrix.vendor }}-${{ matrix.platform }}${{ matrix.env }}
CARGO_BUILD: cargo build --target
RUST_BACKTRACE: full
steps:
- name: checkout
uses: actions/checkout@v4
with:
lfs: false
- name: Set up clang64
if: contains(matrix.os, 'windows')
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
- uses: Swatinem/rust-cache@v2
with:
workspaces: ./native/
key: ${{ matrix.arch }}
- name: Add Build target
run: |
cd native/
rustup target add ${{ env.TARGET_TRIPLET }}
- name: Build Debug
if: ${{ !inputs.release }}
run: |
cd native/
${{ env.CARGO_BUILD}} ${{ env.TARGET_TRIPLET}}
- name: Build Release
if: inputs.release
run: |
cd native/
${{ env.CARGO_BUILD }} ${{ env.TARGET_TRIPLET}} --release
- name: Artifacts
uses: actions/upload-artifact@v4
with:
name: libnative-${{ matrix.platform }}-${{ matrix.arch }}
path: native/target/${{ env.TARGET_TRIPLET }}/${{ inputs.release && 'release' || 'debug' }}/${{ matrix.lib }}
godot-export:
strategy:
matrix:
profile: ['macOS', 'Windows', 'Linux']
version: ['4.3']
include:
- profile: 'macOS'
platform: darwin
vendor: apple
os: macos-15
x86_64: true
aarch64: true
extension: '.dmg'
lib: libnative.dylib
template_dir: '$HOME/Library/Application\ Support/Godot/export_templates'
godot_artefact: 'macOS.universal'
- profile: 'Windows'
platform: windows
env: '-msvc'
vendor: pc
os: ubuntu-24.04
x86_64: true
aarch64: true
extension: '.exe'
lib: native.dll
template_dir: '$HOME/.local/share/godot/export_templates'
godot_artefact: 'linux.x86_64'
- profile: 'Linux'
platform: 'linux'
env: '-gnu'
vendor: 'unknown'
os: ubuntu-24.04
lib: libnative.so
template_dir: '$HOME/.local/share/godot/export_templates'
godot_artefact: 'linux.x86_64'
x86_64: true
needs: rust-build
runs-on: ${{ matrix.os }}
env:
EXPORT_DIR: build/${{ matrix.profile }}
EXPORT_ARGS: ${{ matrix.profile }} build/${{ matrix.profile }}/SimChopper${{ matrix.extension }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
lfs: true
- uses: hustcer/setup-nu@main
with:
version: "0.101.*"
- name: setup Godot
shell: nu {0}
run: |
let bin_path = "${{ startsWith(matrix.os, 'ubuntu') && format('./Godot_v{0}-stable_linux.x86_64', matrix.version) || './Godot.app/Contents/MacOS/Godot' }}"
mkdir .godot_bin
http get "https://github.com/godotengine/godot/releases/download/${{ matrix.version }}-stable/Godot_v${{ matrix.version }}-stable_${{ matrix.godot_artefact }}.zip"
| save -rf .godot_bin/godot.zip
cd .godot_bin
unzip godot.zip
chmod +x $bin_path
ln -s $bin_path "./godot"
ls -a
- name: download Godot export template
run: |
mkdir -p ${{ matrix.template_dir }}/${{ matrix.version }}.stable
cd ${{ matrix.template_dir }}/${{ matrix.version }}.stable
curl -LO https://github.com/godotengine/godot/releases/download/${{ matrix.version }}-stable/Godot_v${{ matrix.version }}-stable_export_templates.tpz
unzip -j Godot_v${{ matrix.version }}-stable_export_templates.tpz
- name: download host libs
if: ${{ matrix.platform != 'linux' && startsWith(matrix.os, 'ubuntu') }}
uses: actions/download-artifact@v4
with:
name: libnative-linux-x86_64
path: native/target/x86_64-unknown-linux-gnu/debug/
- name: download x86_64 libs
if: matrix.x86_64
uses: actions/download-artifact@v4
with:
name: libnative-${{ matrix.platform }}-x86_64
path: native/target/x86_64-${{ matrix.vendor }}-${{ matrix.platform }}${{ matrix.env }}/debug/
- name: download aarch64 libs
if: matrix.aarch64
uses: actions/download-artifact@v4
with:
name: libnative-${{ matrix.platform }}-aarch64
path: native/target/aarch64-${{ matrix.vendor }}-${{ matrix.platform }}${{ matrix.env }}/debug/
- name: create universal libnative
if: matrix.platform == 'darwin'
run: |
platform_dir="${{ matrix.vendor }}-${{ matrix.platform }}"
mkdir -p native/target/universal-$platform_dir/debug/
lipo -create native/target/x86_64-$platform_dir/debug/${{ matrix.lib }} native/target/aarch64-$platform_dir/debug/${{ matrix.lib }} -output native/target/universal-$platform_dir/debug/${{ matrix.lib }}
- name: copy libs
shell: nu {0}
run: |
let platform_dir = "${{ matrix.vendor }}-${{ matrix.platform }}${{ matrix.env }}"
let x86_64 = $"native/target/x86_64-($platform_dir)"
let aarch64 = $"native/target/aarch64-($platform_dir)"
let universal = $"native/target/universal-($platform_dir)"
if ($"($x86_64)/debug/" | path type) == "dir" {
mkdir $"($x86_64)/release/"
cp -v ($"($x86_64)/debug/*" | into glob) $"($x86_64)/release/"
}
if ($"($aarch64)/debug/" | path type) == "dir" {
mkdir $"($aarch64)/release/"
cp -v ($"($aarch64)/debug/*" | into glob) $"($aarch64)/release/"
}
if ($"($universal)/debug/" | path type) == "dir" {
mkdir $"($universal)/release/"
cp -v ($"($universal)/debug/*" | into glob) $"($universal)/release/"
}
- name: import godot project
shell: nu {0}
run: |
$env.PATH = $env.PATH | append ("./.godot_bin" | path expand)
godot --headless --verbose --import
- name: export-debug
shell: nu {0}
if: ${{ !inputs.release }}
run: |
$env.PATH = $env.PATH | append ("./.godot_bin" | path expand)
mkdir "${{ env.EXPORT_DIR }}"
godot --headless --verbose --export-debug ${{ env.EXPORT_ARGS }}
if (ls -a "${{ env.EXPORT_DIR }}" | length) < 1 { exit 1 }
- name: export-release
shell: nu {0}
if: inputs.release
run: |
$env.PATH = $env.PATH | append ("./.godot_bin" | path expand)
mkdir "${{ env.EXPORT_DIR }}"
godot --headless --export-release ${{ env.EXPORT_ARGS }}
if (ls -a "${{ env.EXPORT_DIR }}" | length) < 1 { exit 1 }
- name: describe revision
id: describe
run: echo "ref=$(git describe --tags --always)" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
with:
name: SimChopper_${{ matrix.profile }}_${{ steps.describe.outputs.ref }}
path: ${{ env.EXPORT_DIR }}