mirror of
https://github.com/godotengine/webrtc-native.git
synced 2026-01-03 14:09:58 +03:00
[macOS] Add support for universal builds.
Since the OpenSSL build system does not support macOS universal binaries, we first need to build the two libraries separately, then we join them together using lipo.
This commit is contained in:
12
.github/workflows/build_release.yml
vendored
12
.github/workflows/build_release.yml
vendored
@@ -84,17 +84,11 @@ jobs:
|
||||
|
||||
# macOS
|
||||
- platform: macos
|
||||
arch: 'x86_64'
|
||||
gdnative_flags: 'macos_arch=x86_64 bits=64'
|
||||
arch: 'universal'
|
||||
gdnative_flags: 'macos_arch=universal bits=64'
|
||||
sconsflags: ''
|
||||
os: 'macos-11'
|
||||
cache-name: macos-x86_64
|
||||
- platform: macos
|
||||
gdnative_flags: 'macos_arch=arm64 bits=64'
|
||||
arch: 'arm64'
|
||||
sconsflags: ''
|
||||
os: 'macos-11'
|
||||
cache-name: macos-arm64
|
||||
cache-name: macos-universal
|
||||
|
||||
# Windows
|
||||
- platform: windows
|
||||
|
||||
56
SConstruct
56
SConstruct
@@ -1,6 +1,7 @@
|
||||
#!python
|
||||
|
||||
import os, sys, platform, json, subprocess
|
||||
import SCons
|
||||
|
||||
|
||||
def add_sources(sources, dirpath, extension):
|
||||
@@ -101,14 +102,6 @@ if env["godot_version"] == "3":
|
||||
else:
|
||||
result_path = os.path.join("bin", "extension", "webrtc")
|
||||
|
||||
# Dependencies
|
||||
for tool in ["cmake", "common", "ssl", "rtc"]:
|
||||
env.Tool(tool, toolpath=["tools"])
|
||||
|
||||
ssl = env.BuildOpenSSL()
|
||||
env.NoCache(ssl) # Needs refactoring to properly cache generated headers.
|
||||
rtc = env.BuildLibDataChannel()
|
||||
|
||||
# Our includes and sources
|
||||
env.Append(CPPPATH=["src/"])
|
||||
env.Append(CPPDEFINES=["RTC_STATIC"])
|
||||
@@ -126,12 +119,48 @@ else:
|
||||
sources.append("src/init_gdnative.cpp")
|
||||
add_sources(sources, "src/net/", "cpp")
|
||||
|
||||
env.Depends(sources, [ssl, rtc])
|
||||
# Since the OpenSSL build system does not support macOS universal binaries, we first need to build the two libraries
|
||||
# separately, then we join them together using lipo.
|
||||
mac_universal = env["platform"] == "macos" and env["arch"] == "universal"
|
||||
build_targets = []
|
||||
build_envs = [env]
|
||||
|
||||
# Make the shared library
|
||||
result_name = "webrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
|
||||
library = env.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources)
|
||||
Default(library)
|
||||
# For macOS universal builds, setup one build environment per architecture.
|
||||
if mac_universal:
|
||||
build_envs = []
|
||||
for arch in ["x86_64", "arm64"]:
|
||||
benv = env.Clone()
|
||||
benv["arch"] = arch
|
||||
benv["CCFLAGS"] = SCons.Util.CLVar(str(benv["CCFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch))
|
||||
benv["LINKFLAGS"] = SCons.Util.CLVar(str(benv["LINKFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch))
|
||||
benv["suffix"] = benv["suffix"].replace("universal", arch)
|
||||
benv["SHOBJSUFFIX"] = benv["suffix"] + benv["SHOBJSUFFIX"]
|
||||
build_envs.append(benv)
|
||||
|
||||
# Build our library and its dependencies.
|
||||
for benv in build_envs:
|
||||
# Dependencies
|
||||
for tool in ["cmake", "common", "ssl", "rtc"]:
|
||||
benv.Tool(tool, toolpath=["tools"])
|
||||
|
||||
ssl = benv.BuildOpenSSL()
|
||||
benv.NoCache(ssl) # Needs refactoring to properly cache generated headers.
|
||||
rtc = benv.BuildLibDataChannel()
|
||||
|
||||
benv.Depends(sources, [ssl, rtc])
|
||||
|
||||
# Make the shared library
|
||||
result_name = "webrtc_native{}{}".format(benv["suffix"], benv["SHLIBSUFFIX"])
|
||||
library = benv.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources)
|
||||
build_targets.append(library)
|
||||
|
||||
Default(build_targets)
|
||||
|
||||
# For macOS universal builds, join the libraries using lipo.
|
||||
if mac_universal:
|
||||
result_name = "libwebrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
|
||||
universal_target = env.Command(os.path.join(result_path, "lib", result_name), build_targets, "lipo $SOURCES -output $TARGETS -create")
|
||||
Default(universal_target)
|
||||
|
||||
# GDNativeLibrary
|
||||
if env["godot_version"] == "3":
|
||||
@@ -143,4 +172,5 @@ if env["godot_version"] == "3":
|
||||
})
|
||||
else:
|
||||
extfile = env.InstallAs(os.path.join(result_path, "webrtc.gdextension"), "misc/webrtc.gdextension")
|
||||
|
||||
Default(extfile)
|
||||
|
||||
@@ -6,8 +6,7 @@ entry_symbol = "webrtc_extension_init"
|
||||
|
||||
linux.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.linux.template_debug.x86_64.so"
|
||||
linux.debug.x86_32 = "res://webrtc/lib/libwebrtc_native.linux.template_debug.x86_32.so"
|
||||
macos.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.macos.template_debug.x86_64.dylib"
|
||||
macos.debug.arm64 = "res://webrtc/lib/libwebrtc_native.macos.template_debug.arm64.dylib"
|
||||
macos.debug = "res://webrtc/lib/libwebrtc_native.macos.template_debug.universal.dylib"
|
||||
windows.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.windows.template_debug.x86_64.dll"
|
||||
windows.debug.x86_32 = "res://webrtc/lib/libwebrtc_native.windows.template_debug.x86_32.dll"
|
||||
android.debug.arm64 = "res://webrtc/lib/libwebrtc_native.android.template_debug.arm64.so"
|
||||
@@ -17,8 +16,7 @@ ios.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.ios.template_debug.x86_64.
|
||||
|
||||
linux.release.x86_64 = "res://webrtc/lib/libwebrtc_native.linux.template_release.x86_64.so"
|
||||
linux.release.x86_32 = "res://webrtc/lib/libwebrtc_native.linux.template_release.x86_32.so"
|
||||
macos.release.x86_64 = "res://webrtc/lib/libwebrtc_native.macos.template_release.x86_64.dylib"
|
||||
macos.release.arm64 = "res://webrtc/lib/libwebrtc_native.macos.template_release.arm64.dylib"
|
||||
macos.release = "res://webrtc/lib/libwebrtc_native.macos.template_release.universal.dylib"
|
||||
windows.release.x86_64 = "res://webrtc/lib/libwebrtc_native.windows.template_release.x86_64.dll"
|
||||
windows.release.x86_32 = "res://webrtc/lib/libwebrtc_native.windows.template_release.x86_32.dll"
|
||||
android.release.arm64 = "res://webrtc/lib/libwebrtc_native.android.template_release.arm64.so"
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
[resource]
|
||||
singleton = true
|
||||
reloadable = false
|
||||
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.x86_64.dylib"
|
||||
entry/OSX.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.arm64.dylib"
|
||||
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.macos.{TARGET}.universal.dylib"
|
||||
entry/Windows.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_64.dll"
|
||||
entry/Windows.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_32.dll"
|
||||
entry/X11.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
|
||||
@@ -16,11 +15,3 @@ entry/Android.x64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}
|
||||
entry/iOS.armv7 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.armv32.dylib"
|
||||
entry/iOS.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.arm64.dylib"
|
||||
entry/iOS.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.x86_64.simulator.dylib"
|
||||
dependency/Windows.64 = [ ]
|
||||
dependency/Windows.32 = [ ]
|
||||
dependency/X11.64 = [ ]
|
||||
dependency/X11.32 = [ ]
|
||||
dependency/Server.64 = [ ]
|
||||
dependency/Server.32 = [ ]
|
||||
dependency/Android.armeabi-v7a = [ ]
|
||||
dependency/Android.arm64-v8a = [ ]
|
||||
|
||||
Reference in New Issue
Block a user