Skip to content

Commit

Permalink
Upgraded build system, better platform support and dependency managem…
Browse files Browse the repository at this point in the history
…ent (#60)
  • Loading branch information
Luke authored Sep 8, 2022
1 parent d9c2034 commit c091bca
Show file tree
Hide file tree
Showing 10,541 changed files with 516,313 additions and 365,625 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/build
/out
/cmake/vcpkg/buildtrees/
/cmake/vcpkg/build*/
/cmake/vcpkg/downloads/
/cmake/vcpkg/installed*/
/cmake/vcpkg/packages/
/cmake/vcpkg/scripts/buildsystems/tmp/
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ensure shell script uses LF.
Dockerfile eol=lf
*.sh eol=lf
73 changes: 73 additions & 0 deletions .github/actions/android-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 'Android build for libnakama'
description: 'Not generic, tailored for libnakama.'
inputs:
GITHUB_TOKEN:
description: 'Github token for Github Package Registry'
required: true


outputs:
artifact_name:
description: 'Artifact name'
value: ${{ steps.artifact_name.outputs.name }}

runs:
using: "composite"
steps:
# gradle invokes cmake to build native code, so our usual vcpkg config is still necessary
# NOTE: 'Source' here is the name of NuGet registry created by actions/setup-dotnet@v2
- run: echo "VCPKG_BINARY_SOURCES=clear;nuget,Source,readwrite" >> $GITHUB_ENV
shell: bash

- uses: actions/setup-dotnet@v2
with:
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: ${{ inputs.GITHUB_TOKEN }}

- name: Installing prerequisites
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
sudo ./ci/setup-ubuntu.sh install_ninja setup_vcpkg
elif [[ "${{ runner.os }}" == "macOS" ]]; then
./ci/setup-osx.sh
fi
# looks like setup done by actions/setup-dotnet is not enough, and
# without 'setapikey' vcpkg can't upload build cache to NuGet registry
- name: Setup NuGet API key
shell: bash
run: >
mono `vcpkg fetch nuget | tail -n 1`
setapikey "${{ inputs.GITHUB_TOKEN }}"
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- run: rm -rf out
shell: bash

- uses: gradle/gradle-build-action@v2
with:
arguments: assembleMinSizeRel --info --no-parallel --no-daemon
build-root-directory: ./android
- id: artifact_name
shell: bash
run: |
sha=${{ github.sha }}
name="libnakama-android-MinSizeRel-git.${sha:0:8}"
echo "::set-output name=artifact::${name}"
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifact_name.outputs.artifact }}
path: ./android/build/outputs/aar/nakama-minsizerel.aar
retention-days: ${{ inputs.artifact_retention_days }}
- if: failure()
uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifact_name.outputs.artifact }}-workdir-debug
path: |
./android/build
./android/.cxx
./cmake/vcpkg/buildtrees
!./android/**/.git
retention-days: 1
122 changes: 122 additions & 0 deletions .github/actions/cmake-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: 'CMake build for libnakama'
description: 'Configures build environment and invokes CMake. Not generic, tailored for libnakama.'
inputs:
preset:
description: 'Configure preset name'
required: true
build_type:
description: 'Build config: MinSizeRel or Debug'
required: true
default: 'MinSizeRel'
flavour:
description: 'Possible values: Unreal, libcxx'
required: false
artifact_retention_days:
description: 'Artifact retention days'
default: 2
GITHUB_TOKEN:
description: 'Github token for Github Package Registry'
required: true


outputs:
artifact_name:
description: 'Artifact name'
value: ${{ steps.artifact_name.outputs.name }}
runs:
using: "composite"
steps:
- run: echo "VCPKG_BINARY_SOURCES=clear;nuget,GitHub,readwrite" >> $GITHUB_ENV
shell: bash

- name: 'Setup NuGet Credentials'
shell: bash
run: >
mono=$( type -p mono || :);
nuget="$mono $(vcpkg fetch nuget | tail -n 1)";
$nuget sources list | grep -q ${{ github.repository_owner }} || $nuget sources add
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
-storepasswordincleartext
-name "GitHub"
-username "heroiclabs"
-password "${{ inputs.GITHUB_TOKEN }}"
- name: Setup NuGet API key
shell: bash
run: >
$( type -p mono || :) `vcpkg fetch nuget | tail -n 1`
setapikey "${{ inputs.GITHUB_TOKEN }}"
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- id: cmake_args
shell: bash
if: ${{ inputs.flavour }}
run: |
if [[ "${{inputs.flavour}}" == "Unreal" ]]; then
echo "::set-output name=args::-DUNREAL=ON"
elif [[ "${{inputs.flavour}}" == "libcxx" ]]; then
echo "::set-output name=args::-DWITH_LIBCXX=ON"
else
echo "::error::Unexpected 'input' flavour value: ${{ inputs.flavour }}"
fi
- name: Installing prerequisites
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
sudo ./ci/setup-ubuntu.sh
elif [[ "${{ runner.os }}" == "macOS" ]]; then
./ci/setup-osx.sh
fi
if [[ "${{ runner.os }}" == "Linux" ]]; then
echo 'CC=/usr/bin/gcc-11' >> "$GITHUB_ENV"
echo 'CXX=/usr/bin/g++-11' >> "$GITHUB_ENV"
fi
shell: bash
- run: rm -rf out
shell: bash
- run: cmake --preset ${{ inputs.preset }} ${{ steps.cmake_args.outputs.args }}
shell: bash
- run: cmake --build ./build/${{ inputs.preset }} --config ${{ inputs.build_type }} --verbose
shell: bash
- run: cmake --install ./build/${{ inputs.preset }} --config ${{ inputs.build_type }}
shell: bash
- id: artifact_name
shell: bash
run: |
sha=${{ github.sha }}
preset="${{ inputs.preset }}"
# strip -host_{arm64,x64} from the preset, because it is not relevant for users
preset=${preset%-host_*}
if [[ -n "${{ inputs.flavour }}" ]]; then
name="libnakama-${{ inputs.flavour }}-${preset}-${{ inputs.build_type }}-git.${sha:0:8}"
else
name="libnakama-${preset}-${{ inputs.build_type }}-git.${sha:0:8}"
fi
echo "::set-output name=artifact::${name}"
#
- run: >
rm -rf ./out/*/*libHttpClient*.{lib,a};
rm -rf ./out/Nakama/libnakama/*/*libHttpClient*.{lib,a};
shell: bash
- name: Prepare artifact archive
run: |
bin7z=$(type -p 7z || type -p 7zr) # windows and linux/osx has different 7z binaries names
cd out
${bin7z} a ../${{ steps.artifact_name.outputs.artifact }}.7z '*'
shell: bash

- uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifact_name.outputs.artifact }}
path: ./${{ steps.artifact_name.outputs.artifact }}.7z
retention-days: ${{ inputs.artifact_retention_days }}
- if: failure()
uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifact_name.outputs.artifact }}-workdir-debug
path: |
./build
./cmake/vcpkg/buildtrees
retention-days: 1
33 changes: 33 additions & 0 deletions .github/actions/run-nakama/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Builds and runs nakama'
description: 'Builds and runs Nakama'
inputs:
ref:
description: 'Nakama git ref to run'
required: false
default: v3.13.1
postgres_uri:
description: 'PostgreSQL connection URI'
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
with:
repository: heroiclabs/nakama
path: nakama.git
ref: "${{ inputs.ref }}"
fetch-depth: 1
- uses: actions/setup-go@v3
with:
go-version: '1.18'
cache: true
cache-dependency-path: nakama.git/go.sum
- run: go build -v .
shell: bash
working-directory: nakama.git
- run: ./nakama migrate up -database.address "${{ inputs.postgres_uri }}"
shell: bash
working-directory: nakama.git
- run: nohup ./nakama &>/tmp/nakama.log &
shell: bash
working-directory: nakama.git
128 changes: 128 additions & 0 deletions .github/workflows/buildall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Build All
on: [workflow_call, workflow_dispatch]
jobs:
windows_matrix:
timeout-minutes: 30
strategy:
matrix:
build_type: [MinSizeRel, Debug]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cmake-build
with:
preset: win-x64
build_type: ${{ matrix.build_type }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Unreal Engine doesn't officially support debug (/MDd flag) builds,
# so we build Unreal flavour in release config only
- if: ${{ matrix.build_type == 'MinSizeRel' }}
uses: ./.github/actions/cmake-build
with:
preset: win-x64
build_type: ${{ matrix.build_type }}
flavour: Unreal
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

linux_matrix:
timeout-minutes: 30
strategy:
matrix:
flavour: [ "", "libcxx" ]
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cmake-build
with:
preset: linux-amd64
flavour: ${{ matrix.flavour }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Once libc++ version is built, same build tree can be reused for Unreal
- if: matrix.flavour == 'libcxx'
uses: ./.github/actions/cmake-build
with:
preset: linux-amd64
flavour: Unreal
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

android:
timeout-minutes: 60
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/android-build
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

apple_matrix:
timeout-minutes: 30
strategy:
matrix:
preset: ["ios-arm64-host_x64", "iphonesimulator-x64-host_x64", "macosx-x64-host_x64", "macosx-arm64-host_x64"]
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cmake-build
with:
preset: ${{ matrix.preset }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Unreal module
uses: ./.github/actions/cmake-build
with:
preset: ${{ matrix.preset }}
flavour: Unreal
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

combine:
needs: [windows_matrix, linux_matrix, apple_matrix]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: restore apple's lipo from cache
id: lipo_cache
uses: actions/cache@v3
with:
path: cctools/cctools/misc/lipo
key: lipo-${{ hashFiles('ci/build-lipo.sh') }}
- name: build apple's lipo
if: steps.lipo_cache.outputs.cache-hit != 'true'
run: ./ci/build-lipo.sh
- name: make lipo available on system path
run: echo "$PWD/cctools/cctools/misc" >> $GITHUB_PATH
- uses: actions/download-artifact@v3
with:
path: artifacts7z

- name: Unpack artifacts as if they were plain dir uploads
run: |
for f in artifacts7z/*/*.7z; do
destdir=artifacts/$(basename $(dirname $f))
echo "Unpacking $f to $destdir"
7zr x -o$destdir $f
done
- id: combine
run: /bin/bash -x ./ci/combine-artifacts.sh artifacts

- name: Prepare artifacts archives
run: |
(
cd ./${{ steps.combine.outputs.unreal-artifact-dir }}
7zr a ../${{ steps.combine.outputs.unreal-artifact-name }}.7z '*'
)
(
cd ./${{ steps.combine.outputs.generic-artifact-dir }}
7zr a ../${{ steps.combine.outputs.generic-artifact-name }}.7z '*'
)
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.combine.outputs.unreal-artifact-name }}
path: ./${{ steps.combine.outputs.unreal-artifact-dir }}.7z
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.combine.outputs.generic-artifact-name }}
path: ./${{ steps.combine.outputs.generic-artifact-dir }}.7z
retention-days: 2

Loading

0 comments on commit c091bca

Please sign in to comment.