Build Project #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-22.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: true | |
- 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.2.2'] | |
include: | |
- profile: 'macOS' | |
platform: darwin | |
vendor: apple | |
os: macos-14 | |
x86_64: true | |
aarch64: true | |
extension: '.dmg' | |
lib: libnative.dylib | |
template_dir: '$HOME/Library/Application\ Support/Godot/export_templates' | |
- profile: 'Windows' | |
platform: windows | |
env: '-msvc' | |
vendor: pc | |
os: ubuntu-22.04 | |
x86_64: true | |
aarch64: true | |
extension: '.exe' | |
lib: native.dll | |
template_dir: '$HOME/.local/share/godot/export_templates' | |
- profile: 'Linux' | |
platform: 'linux' | |
env: '-gnu' | |
vendor: 'unknown' | |
os: ubuntu-20.04 | |
lib: libnative.so | |
template_dir: '$HOME/.local/share/godot/export_templates' | |
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 | |
- name: setup Godot | |
uses: lihop/setup-godot@v2 | |
with: | |
version: ${{ matrix.version }} | |
export-templates: false | |
- 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 | |
run: | | |
set -x | |
platform_dir="${{ matrix.vendor }}-${{ matrix.platform }}${{ matrix.env }}" | |
x86_64="native/target/x86_64-$platform_dir" | |
aarch64="native/target/aarch64-$platform_dir" | |
universal="native/target/universal-$platform_dir" | |
if [[ -d "$x86_64/debug/" ]]; then | |
mkdir -p "$x86_64/release/" | |
cp $x86_64/debug/* "$x86_64/release/" | |
fi | |
if [[ -d "$aarch64/debug/" ]]; then | |
mkdir -p "$aarch64/release/" | |
cp $aarch64/debug/* "$aarch64/release/" | |
fi | |
if [[ -d "$universal/debug/" ]]; then | |
mkdir -p "$universal/release/" | |
cp $universal/debug/* "$universal/release/" | |
fi | |
- name: import godot project | |
run: | | |
# import assets | |
.github/build_godot_cache.sh | |
# restart to make sure all rust scripts are detected | |
.github/build_godot_cache.sh | |
- name: export-debug | |
if: ${{ !inputs.release }} | |
run: | | |
mkdir -p "${{ env.EXPORT_DIR }}" | |
godot --headless --export-debug ${{ env.EXPORT_ARGS }} | |
test $(ls -al "${{ env.EXPORT_DIR }}" | wc -l) -gt 1 | |
- name: export-release | |
if: inputs.release | |
run: | | |
mkdir -p "${{ env.EXPORT_DIR }}" | |
godot --headless --export-release ${{ env.EXPORT_ARGS }} | |
test $(ls -al "${{ env.EXPORT_DIR }}" | wc -l) -gt 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 }} |