Skip to content

Commit

Permalink
Fix and improve the build process for macOS (#40)
Browse files Browse the repository at this point in the history
* Fix linking on macOS

* Build sentry-native as a universal library on macOS

* GHA: Build libs for macOS

* Place build artifacts in separate directories for each platform

This prevents crashpad_handler from being overwritten

* Use release/debug in library names instead of build target

* Update README

* Fix `crashpad_handler` locations
  • Loading branch information
limbonaut authored Dec 12, 2024
1 parent 976bcff commit ec29191
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 47 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/build_gdextension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ jobs:
target: editor
arch: x86_64

- name: 🍎 macOS (universal, release)
runner: macos-latest
platform: macos
target: template_release
arch: universal

- name: 🍎 macOS (universal, debug)
runner: macos-latest
platform: macos
target: editor
arch: universal

steps:
- name: Checkout repo and submodules
uses: actions/checkout@v4
Expand All @@ -77,14 +89,15 @@ jobs:
- name: Separate debug symbols on Linux
if: matrix.platform == 'linux'
env:
BUILD_TYPE: ${{matrix.target == 'template_release' && 'release' || 'debug'}}
shell: bash
run: |
pushd project/addons/sentrysdk/bin/
libname=libsentrysdk.${{matrix.platform}}.${{matrix.target}}.${{matrix.arch}}.so
objcopy --only-keep-debug ${libname} ${libname}.debug
objcopy --add-gnu-debuglink ${libname}.debug ${libname}
strip --strip-debug ${libname}
popd
cd project/addons/sentrysdk/bin/linux/
lib=libsentrysdk.${{matrix.platform}}.${BUILD_TYPE}.${{matrix.arch}}.so
objcopy --only-keep-debug ${lib} ${lib}.debug
objcopy --add-gnu-debuglink ${lib}.debug ${lib}
strip --strip-debug ${lib}
- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
timeout-minutes: 5
run: |
scons project/addons/gdUnit4
chmod +x project/addons/sentrysdk/bin/crashpad_handler
chmod +x project/addons/sentrysdk/bin/{linux,macos}/crashpad_handler
echo "--- Rebuilding import cache.."
${GODOT_BIN} --headless --editor --path project/ --quit-after 2000 || true
echo "--- Finished rebuilding import cache."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ brew install scons
# run from the repository root dir
scons target=editor debug_symbols=yes
```
The build process should produce a GDExtension library file for the ***editor target*** at `project/addons/sentrysdk/bin/libsentrysdk.*.editor.*`.
The build process should produce a GDExtension library file for the ***editor target*** at `project/addons/sentrysdk/bin/...`.

To export a project in Godot that uses this extension, you'll also need the libraries for the export templates:
```bash
Expand Down
46 changes: 32 additions & 14 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ if env["platform"] in ["linux", "macos"]:
)
return result.returncode

crashpad_handler_target = "{bin}/{platform}/crashpad_handler".format(
bin=BIN_DIR,
platform=env["platform"]
)
sentry_native = env.Command(
["modules/sentry-native/install/lib/libsentry.a", BIN_DIR + "/crashpad_handler"],
[
"modules/sentry-native/install/lib/libsentry.a",
crashpad_handler_target,
],
["modules/sentry-native/src"],
[
build_sentry_native,
Copy(
BIN_DIR + "/crashpad_handler",
crashpad_handler_target,
"modules/sentry-native/install/bin/crashpad_handler",
),
],
Expand All @@ -47,12 +54,12 @@ elif env["platform"] == "windows":
return result.returncode

sentry_native = env.Command(
["modules/sentry-native/install/lib/sentry.lib", BIN_DIR + "/crashpad_handler.exe"],
["modules/sentry-native/install/lib/sentry.lib", BIN_DIR + "/windows/crashpad_handler.exe"],
["modules/sentry-native/src/"],
[
build_sentry_native,
Copy(
BIN_DIR + "/crashpad_handler.exe",
BIN_DIR + "/windows/crashpad_handler.exe",
"modules/sentry-native/install/bin/crashpad_handler.exe",
),
],
Expand All @@ -73,7 +80,6 @@ if env["platform"] in ["linux", "macos", "windows"]:
LIBS=[
"sentry",
"crashpad_client",
"crashpad_compat",
"crashpad_handler_lib",
"crashpad_minidump",
"crashpad_snapshot",
Expand All @@ -86,13 +92,21 @@ if env["platform"] in ["linux", "macos", "windows"]:
if env["platform"] == "windows":
env.Append(
LIBS=[
"crashpad_compat",
"winhttp",
"advapi32",
"DbgHelp",
"Version",
]
)
elif env["platform"] == "linux":
env.Append(
LIBS=[
"crashpad_compat",
"curl",
]
)
elif env["platform"] == "macos":
env.Append(
LIBS=[
"curl",
Expand All @@ -108,23 +122,27 @@ sources += Glob("src/sentry/*.cpp")
if env["platform"] in ["linux", "windows", "macos"]:
sources += Glob("src/sentry/native/*.cpp")

build_type = "release" if env["target"] == "template_release" else "debug"

if env["platform"] == "macos":
library = env.SharedLibrary(
"{bin_dir}/lib{name}.{platform}.{target}.framework/lib{name}.{platform}.{target}".format(
bin_dir=BIN_DIR,
"{bin}/{platform}/lib{name}.{platform}.{build_type}.framework/lib{name}.{platform}.{build_type}".format(
bin=BIN_DIR,
name=EXTENSION_NAME,
platform=env["platform"],
target=env["target"],
build_type=build_type,
),
source=sources,
)
else:
library = env.SharedLibrary(
"{bin_dir}/lib{name}{suffix}{shlib_suffix}".format(
bin_dir=BIN_DIR,
"{bin}/{platform}/lib{name}.{platform}.{build_type}.{arch}{shlib_suffix}".format(
bin=BIN_DIR,
name=EXTENSION_NAME,
suffix=env["suffix"],
shlib_suffix=env["SHLIBSUFFIX"],
platform=env["platform"],
build_type=build_type,
arch=env["arch"],
shlib_suffix=env["SHLIBSUFFIX"]
),
source=sources,
)
Expand All @@ -134,8 +152,8 @@ Default(library)
# *** Deploy extension manifest.

manifest = env.Substfile(
target="{bin_dir}/{name}.gdextension".format(
bin_dir=BIN_DIR,
target="{bin}/{name}.gdextension".format(
bin=BIN_DIR,
name=EXTENSION_NAME,
),
source="src/manifest.gdextension",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-sentry-native.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

cd modules/sentry-native
cmake -B build -DSENTRY_BUILD_SHARED_LIBS=OFF -DSENTRY_BACKEND=crashpad -DSENTRY_SDK_NAME="sentry.native.godot" -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake -B build -DSENTRY_BUILD_SHARED_LIBS=OFF -DSENTRY_BACKEND=crashpad -DSENTRY_SDK_NAME="sentry.native.godot" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build --target sentry --parallel --config RelWithDebInfo
cmake --build build --target crashpad_handler --parallel --config RelWithDebInfo
cmake --install build --prefix install --config RelWithDebInfo
Expand Down
44 changes: 22 additions & 22 deletions src/manifest.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ compatibility_minimum = "{compatibility_minimum}"

[libraries]

macos.debug = "res://addons/{name}/bin/lib{name}.macos.editor.framework"
macos.release = "res://addons/{name}/bin/lib{name}.macos.template_release.framework"
windows.debug.x86_32 = "res://addons/{name}/bin/lib{name}.windows.editor.x86_32.dll"
windows.release.x86_32 = "res://addons/{name}/bin/lib{name}.windows.template_release.x86_32.dll"
windows.debug.x86_64 = "res://addons/{name}/bin/lib{name}.windows.editor.x86_64.dll"
windows.release.x86_64 = "res://addons/{name}/bin/lib{name}.windows.template_release.x86_64.dll"
linux.debug.x86_64 = "res://addons/{name}/bin/lib{name}.linux.editor.x86_64.so"
linux.release.x86_64 = "res://addons/{name}/bin/lib{name}.linux.template_release.x86_64.so"
linux.debug.arm64 = "res://addons/{name}/bin/lib{name}.linux.editor.arm64.so"
linux.release.arm64 = "res://addons/{name}/bin/lib{name}.linux.template_release.arm64.so"
linux.debug.rv64 = "res://addons/{name}/bin/lib{name}.linux.editor.rv64.so"
linux.release.rv64 = "res://addons/{name}/bin/lib{name}.linux.template_release.rv64.so"
android.debug.arm64 = "res://addons/{name}/bin/lib{name}.android.template_debug.arm64.so"
android.release.arm64 = "res://addons/{name}/bin/lib{name}.android.template_release.arm64.so"
android.debug.arm32 = "res://addons/{name}/bin/lib{name}.android.template_debug.arm32.so"
android.release.arm32 = "res://addons/{name}/bin/lib{name}.android.template_release.arm32.so"
android.debug.x86_64 = "res://addons/{name}/bin/lib{name}.android.template_debug.x86_64.so"
android.release.x86_64 = "res://addons/{name}/bin/lib{name}.android.template_release.x86_64.so"
android.debug.x86_32 = "res://addons/{name}/bin/lib{name}.android.template_debug.x86_32.so"
android.release.x86_32 = "res://addons/{name}/bin/lib{name}.android.template_release.x86_32.so"
web.debug.wasm32 = "res://addons/{name}/bin/lib{name}.web.template_debug.wasm32.wasm"
web.release.wasm32 = "res://addons/{name}/bin/lib{name}.web.template_release.wasm32.wasm"
macos.debug = "res://addons/{name}/bin/macos/lib{name}.macos.debug.framework"
macos.release = "res://addons/{name}/bin/macos/lib{name}.macos.release.framework"
windows.debug.x86_32 = "res://addons/{name}/bin/windows/lib{name}.windows.debug.x86_32.dll"
windows.release.x86_32 = "res://addons/{name}/bin/windows/lib{name}.windows.release.x86_32.dll"
windows.debug.x86_64 = "res://addons/{name}/bin/windows/lib{name}.windows.debug.x86_64.dll"
windows.release.x86_64 = "res://addons/{name}/bin/windows/lib{name}.windows.release.x86_64.dll"
linux.debug.x86_64 = "res://addons/{name}/bin/linux/lib{name}.linux.debug.x86_64.so"
linux.release.x86_64 = "res://addons/{name}/bin/linux/lib{name}.linux.release.x86_64.so"
linux.debug.arm64 = "res://addons/{name}/bin/linux/lib{name}.linux.debug.arm64.so"
linux.release.arm64 = "res://addons/{name}/bin/linux/lib{name}.linux.release.arm64.so"
linux.debug.rv64 = "res://addons/{name}/bin/linux/lib{name}.linux.debug.rv64.so"
linux.release.rv64 = "res://addons/{name}/bin/linux/lib{name}.linux.release.rv64.so"
android.debug.arm64 = "res://addons/{name}/bin/android/lib{name}.android.debug.arm64.so"
android.release.arm64 = "res://addons/{name}/bin/android/lib{name}.android.release.arm64.so"
android.debug.arm32 = "res://addons/{name}/bin/android/lib{name}.android.debug.arm32.so"
android.release.arm32 = "res://addons/{name}/bin/android/lib{name}.android.release.arm32.so"
android.debug.x86_64 = "res://addons/{name}/bin/android/lib{name}.android.debug.x86_64.so"
android.release.x86_64 = "res://addons/{name}/bin/android/lib{name}.android.release.x86_64.so"
android.debug.x86_32 = "res://addons/{name}/bin/android/lib{name}.android.debug.x86_32.so"
android.release.x86_32 = "res://addons/{name}/bin/android/lib{name}.android.release.x86_32.so"
web.debug.wasm32 = "res://addons/{name}/bin/web/lib{name}.web.debug.wasm32.wasm"
web.release.wasm32 = "res://addons/{name}/bin/web/lib{name}.web.release.wasm32.wasm"

[dependencies]

Expand Down
10 changes: 8 additions & 2 deletions src/sentry/native/native_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,22 @@ void NativeSDK::initialize() {

// Establish handler path.
String handler_fn;
#if defined(LINUX_ENABLED) || defined(MACOS_ENABLED)
String platform_dir;
#ifdef LINUX_ENABLED
handler_fn = "crashpad_handler";
platform_dir = "linux";
#elif MACOS_ENABLED
handler_fn = "crashpad_handler";
platform_dir = "macos";
#elif WINDOWS_ENABLED
handler_fn = "crashpad_handler.exe";
platform_dir = "windows";
#else
ERR_PRINT("Sentry: Internal Error: NativeSDK should not be initialized on an unsupported platform (this should not happen).");
#endif
String handler_path = OS::get_singleton()->get_executable_path().get_base_dir() + "/" + handler_fn;
if (!FileAccess::file_exists(handler_path)) {
handler_path = ProjectSettings::get_singleton()->globalize_path("res://addons/sentrysdk/bin/" + handler_fn);
handler_path = ProjectSettings::get_singleton()->globalize_path("res://addons/sentrysdk/bin/" + platform_dir + "/" + handler_fn);
}
if (FileAccess::file_exists(handler_path)) {
sentry_options_set_handler_path(options, handler_path.utf8());
Expand Down

0 comments on commit ec29191

Please sign in to comment.