Skip to content

Commit

Permalink
feat: build for Apple Silicon with new GitHub Action
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit afcf14e
Author: karl <[email protected]>
Date:   Fri Aug 16 11:34:26 2024 +0200

    fix: remove debug info from GH Action

commit 4bc4f21
Author: karl <[email protected]>
Date:   Fri Aug 16 11:13:06 2024 +0200

    fix: arch env variable not being used

commit 19b5274
Author: karl <[email protected]>
Date:   Thu Aug 15 23:25:34 2024 +0200

    fix: add missing CCPPATH append for macos

commit 5d0957b
Author: karl <[email protected]>
Date:   Thu Aug 15 22:25:39 2024 +0200

    fix/WIP: osgeo_path fix

commit eb4d55e
Author: karl <[email protected]>
Date:   Thu Aug 15 20:55:37 2024 +0200

    fix/WIP: more detaild error message for compile issue

commit 2968af2
Author: LandscapeLab Office <[email protected]>
Date:   Wed Aug 14 15:54:36 2024 +0200

    update godot-cpp to current 4.3 RC

    workaround to get builds working without the BoolVariable issue recently introduced

commit c4d849e
Author: LandscapeLab Office <[email protected]>
Date:   Wed Aug 14 15:44:19 2024 +0200

    fix: macos runner versions

commit 387b888
Author: karl <[email protected]>
Date:   Tue Oct 31 19:06:38 2023 +0100

    feat: first attempt at Apple Silicon runner
  • Loading branch information
kb173 committed Aug 16, 2024
1 parent 48602cc commit 50b2df9
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: macos-latest
runs-on: macos-12

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/build-silicon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Compile Geodot for Apple Silicon

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master, godot3, silicon-action ]
pull_request:
branches: [ master, godot3 ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: macos-14

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Get godot-cpp commit hash
id: get-godot-cpp-hash
run: |
echo "hash=$(git submodule | head -n1 | awk '{print $1;}')" >> $GITHUB_OUTPUT
shell: bash

- name: Cache generated godot-cpp bindings
id: cache-bindings
uses: actions/cache@v2
env:
cache-name: godot-cpp-cache
with:
path: godot-cpp
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.ref_name }}-${{ steps.get-godot-cpp-hash.outputs.hash }}-silicon

- name: Initialize submodules
if: steps.cache-bindings.outputs.cache-hit != 'true'
run: git submodule update --init --recursive

- name: Install dependencies
run: |
brew install gdal
brew install scons
brew install dylibbundler
- name: Generate Godot-CPP bindings
if: steps.cache-bindings.outputs.cache-hit != 'true'
run: scons arch=arm64 generate_bindings=yes
working-directory: godot-cpp

- name: Build Geodot
run: scons platform=macos arch=arm64 osgeo_path=$(brew info gdal | grep '/opt/homebrew/Cellar/' | cut -d ' ' -f 1)

- name: Bundle dependencies
run: dylibbundler -of -b -x ./demo/addons/geodot/macos/libgeodot.dylib -d ./demo/addons/geodot/macos/ -p @executable_path

- name: Publish Artifacts
uses: actions/upload-artifact@v2
with:
name: macos-build
path: |
demo
13 changes: 9 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ opts.Add(EnumVariable('target', "Compilation target",
'debug', ['d', 'debug', 'r', 'release']))
opts.Add(EnumVariable('platform', 'Compilation platform', host_platform,
allowed_values=('linux', 'macos', 'windows'), ignorecase=2))
opts.Add(EnumVariable('arch', 'Compilation architecture (for Apple Silicon)', 'x86_64', ['x86_64', 'arm64']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(BoolVariable('compiledb',
"Build a Compilation Database, e.g. for live error reporting in VSCodium", 'no'))
Expand Down Expand Up @@ -102,15 +103,16 @@ if env['platform'] == "macos":
cpp_library += '.macos'
gdal_lib_name = 'gdal'

env.Append(LINKFLAGS=['-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', env['arch']])

if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS=['-g', '-O2', '-arch', 'x86_64'])
env.Append(CCFLAGS=['-g', '-O2'])
else:
env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64'])
env.Append(CCFLAGS=['-g', '-O3'])

env.Append(LIBS=['libgdal.dylib'])
env.Append(LIBPATH=[os.path.join(env['osgeo_path'], "lib")])
env.Append(CPPPATH=[os.path.join(env['osgeo_path'], "include")])

elif env['platform'] in ('x11', 'linux'):
env['target_path'] += 'x11/'
Expand Down Expand Up @@ -151,7 +153,10 @@ else:
cpp_library += '.release'

if env['platform'] == "macos":
cpp_library += ".universal"
if env['arch'] == "x86_64":
cpp_library += ".universal"
else:
cpp_library += ".arm64"
else:
cpp_library += '.x86_' + str(bits)

Expand Down
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 138 files
2 changes: 1 addition & 1 deletion src/raster-tile-extractor/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ elif env['platform'] == 'macos':
gdal_lib_name = "libgdal.dylib"

if not os.path.exists(gdal_include_path) or not os.path.exists(gdal_lib_path):
print("OSGeo paths are invalid!")
print(f"OSGeo paths are invalid! Should be: {env['osgeo_path']}")
quit()

env.Append(CPPPATH=[gdal_include_path])
Expand Down

0 comments on commit 50b2df9

Please sign in to comment.