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

Add macOS ARM64 (Apple Silicon) support. #529

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ jobs:

- name: Build godot-cpp
run: |
scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu)
scons target=release macos_arch=x86_64 generate_bindings=yes -j $(sysctl -n hw.logicalcpu)

- name: Upload artifact
uses: actions/upload-artifact@v2.2.3
with:
name: godot-cpp-macos-x86_64-release
path: bin/libgodot-cpp.osx.release.64.a
path: bin/libgodot-cpp.osx.release.x86_64.a
if-no-files-found: error

- name: Build test GDNative library
run: |
scons target=release platform=osx bits=64 -j $(sysctl -n hw.logicalcpu) -C test
scons target=release platform=osx macos_arch=x86_64 -j $(sysctl -n hw.logicalcpu) -C test

- name: Run test GDNative library
run: |
Expand Down
32 changes: 27 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ opts.Add(EnumVariable(
'arm64',
['armv7', 'arm64', 'x86_64']
))
opts.Add(EnumVariable(
'macos_arch',
'Target macOS architecture',
'universal',
['universal', 'arm64', 'x86_64']
))
opts.Add(BoolVariable(
'ios_simulator',
'Target iOS Simulator',
Expand Down Expand Up @@ -217,14 +223,28 @@ elif env['platform'] == 'osx':
'Only 64-bit builds are supported for the macOS target.'
)

env.Append(CCFLAGS=['-std=c++14', '-arch', 'x86_64'])
if env['macos_arch'] == 'universal':
env.Append(CCFLAGS=['-std=c++14', '-arch', 'x86_64', '-arch', 'arm64'])
else:
env.Append(CCFLAGS=['-std=c++14', '-arch', env['macos_arch']])

if env['macos_deployment_target'] != 'default':
env.Append(CCFLAGS=['-mmacosx-version-min=' + env['macos_deployment_target']])

if env['macos_arch'] == 'universal':
env.Append(LINKFLAGS=[
'-arch',
'x86_64',
'-arch',
'arm64'
])
else:
env.Append(LINKFLAGS=[
'-arch',
env['macos_arch']
])

env.Append(LINKFLAGS=[
'-arch',
'x86_64',
'-framework',
'Cocoa',
'-Wl,-undefined,dynamic_lookup',
Expand Down Expand Up @@ -439,10 +459,12 @@ add_sources(sources, 'src/gen', 'cpp')
arch_suffix = env['bits']
if env['platform'] == 'android':
arch_suffix = env['android_arch']
if env['platform'] == 'ios':
elif env['platform'] == 'ios':
arch_suffix = env['ios_arch']
if env['platform'] == 'javascript':
elif env['platform'] == 'javascript':
arch_suffix = 'wasm'
elif env['platform'] == 'osx':
arch_suffix = env['macos_arch']

library = env.StaticLibrary(
target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format(
Expand Down
16 changes: 12 additions & 4 deletions test/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ opts.Add(EnumVariable('bits', 'Target platform bits', '64', ('32', '64')))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/', PathVariable.PathAccept))
opts.Add(PathVariable('target_name', 'The library name.', 'libgdexample', PathVariable.PathAccept))
opts.Add(EnumVariable('macos_arch', 'Target macOS architecture', 'universal', ['universal', 'arm64', 'x86_64']))

# Local dependency paths, adapt them to your setup
godot_headers_path = "../godot-headers/"
Expand Down Expand Up @@ -75,11 +76,15 @@ if env['platform'] == '':

# Check our platform specifics
if env['platform'] == "osx":
if env['macos_arch'] == 'universal':
env.Append(CCFLAGS=['-std=c++17', '-arch', 'x86_64', '-arch', 'arm64'])
env.Append(LINKFLAGS=['-arch', 'x86_64', '-arch', 'arm64'])
else:
env.Append(CCFLAGS=['-std=c++17', '-arch', env['macos_arch']])
env.Append(LINKFLAGS=['-arch', env['macos_arch']])

env['target_path'] += 'osx/'
cpp_library += '.osx'
env.Append(CCFLAGS=['-arch', 'x86_64'])
env.Append(CXXFLAGS=['-std=c++17'])
env.Append(LINKFLAGS=['-arch', 'x86_64'])
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS=['-g', '-O2'])
else:
Expand Down Expand Up @@ -117,7 +122,10 @@ if env['target'] in ('debug', 'd'):
else:
cpp_library += '.release'

cpp_library += '.' + str(bits)
if env['platform'] == 'osx':
cpp_library += '.' + env['macos_arch']
else:
cpp_library += '.' + str(bits)

# make sure our binding library is properly includes
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
Expand Down