diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ecb637..6d705aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Prevent usage of Godot logger during crash handling on Windows/Linux ([#398](https://github.com/getsentry/sentry-godot/pull/398)) - Add missing Cocoa SDK symbols to builds ([#401](https://github.com/getsentry/sentry-godot/pull/401)) - Add build option to separate debug symbols for GDExtension and crashpad_handler, and do it in the official builds ([#399](https://github.com/getsentry/sentry-godot/pull/399)) +- Support separating debug symbols of Android targets ([#404](https://github.com/getsentry/sentry-godot/pull/404)) - Generate Info.plist for macOS during build ([#403](https://github.com/getsentry/sentry-godot/pull/403)) ### Fixes diff --git a/SConstruct b/SConstruct index 8ce46131..2e519cf3 100644 --- a/SConstruct +++ b/SConstruct @@ -59,7 +59,7 @@ def add_custom_bool_option(name, description, default=False): # Define our custom options add_custom_bool_option("generate_ios_framework", "Generate iOS xcframework from static libraries", False) add_custom_bool_option("build_android_lib", "Build Android bridge library", False) -add_custom_bool_option("separate_debug_symbols", "Separate debug symbols (supported on macOS, iOS, Linux)", True) +add_custom_bool_option("separate_debug_symbols", "Separate debug symbols (supported on macOS, iOS, Linux, Android)", True) # Workaround: Remove custom options from ARGUMENTS to avoid warnings from godot-cpp. # Godot complains about variables it does not recognize. See: https://github.com/godotengine/godot-cpp/issues/1334 @@ -172,6 +172,7 @@ if internal_sdk == SDK.NATIVE: elif internal_sdk == SDK.ANDROID: sources += Glob("src/sentry/android/*.cpp") env.Append(CPPDEFINES=["SDK_ANDROID"]) + env.Append(LINKFLAGS="-Wl,--build-id=sha1") # Add Build ID to binaries. elif internal_sdk == SDK.COCOA: sources += Glob("src/sentry/cocoa/*.cpp") sources += Glob("src/sentry/cocoa/*.mm") @@ -259,12 +260,10 @@ if env["debug_symbols"] and env["separate_debug_symbols"]: # Note: Windows/MSVC separates by default. if platform in ["macos", "ios"]: dsym_path = f"{out_dir}/dSYMs/{lib_name}.framework.dSYM" - separate_symbols = env.SeparateDebugSymbols(Dir(dsym_path), File(lib_path)) - Default(separate_symbols) - elif platform == "linux": + env.SeparateDebugSymbols(Dir(dsym_path), library) + elif platform in ["linux", "android"]: symbols_path = f"{lib_path}.debug" - separate_symbols = env.SeparateDebugSymbols(File(symbols_path), File(lib_path)) - Default(separate_symbols) + env.SeparateDebugSymbols(File(symbols_path), library) # *** Build Android lib diff --git a/site_scons/site_tools/separate_debug_symbols.py b/site_scons/site_tools/separate_debug_symbols.py index 567617a5..f5225767 100644 --- a/site_scons/site_tools/separate_debug_symbols.py +++ b/site_scons/site_tools/separate_debug_symbols.py @@ -1,59 +1,75 @@ """ Tool to separate debug symbols. + +Adds SeparateDebugSymbols pseudo-builder that registers a post-action for splitting +symbols, with a cleanup. """ from SCons.Script import Clean, Exit, Action import os - -def separate_debug_symbols(target, source, env): +def separate_debug_symbols(target, source, env, p_symbols_path): platform = env["platform"] - target_path = str(target[0]) - source_path = str(source[0]) - - def run(cmd): - err = os.system(cmd) - return os.WEXITSTATUS(err) + binary_path = str(target[0]) + symbols_path = str(p_symbols_path) if platform in ["macos", "ios"]: - err = run(f'dsymutil "{source_path}" -o "{target_path}"') + err = env.Execute(f'dsymutil "{binary_path}" -o "{symbols_path}"') if err != 0: print(f"ERROR: Failed to split debug symbols (exit code {err})") Exit(1) - err = run(f'strip -u -r "{source_path}"') + err = env.Execute(f'strip -u -r "{binary_path}"') if err != 0: print(f"ERROR: Failed to strip debug symbols (exit code {err})") Exit(1) + elif platform == "linux": - err = run(f'objcopy --only-keep-debug --compress-debug-sections=zlib "{source_path}" "{target_path}"') + err = env.Execute(f'objcopy --only-keep-debug --compress-debug-sections=zlib "{binary_path}" "{symbols_path}"') + if err != 0: + print(f"ERROR: Failed to split debug symbols (exit code {err})") + Exit(1) + + err = env.Execute(f'strip --strip-debug --strip-unneeded "{binary_path}"') + if err != 0: + print(f"ERROR: Failed to strip debug symbols (exit code {err})") + Exit(1) + + err = env.Execute(f'objcopy --add-gnu-debuglink="{symbols_path}" "{binary_path}"') + if err != 0: + print(f"ERROR: Failed to add debug link (exit code {err})") + Exit(1) + + elif platform == "android": + err = env.Execute(f'llvm-objcopy --only-keep-debug --compress-debug-sections=zlib "{binary_path}" "{symbols_path}"') if err != 0: print(f"ERROR: Failed to split debug symbols (exit code {err})") Exit(1) - err = run(f'strip --strip-debug --strip-unneeded "{source_path}"') + err = env.Execute(f'llvm-strip --strip-debug --strip-unneeded "{binary_path}"') if err != 0: print(f"ERROR: Failed to strip debug symbols (exit code {err})") Exit(1) - err = run(f'objcopy --add-gnu-debuglink="{target_path}" "{source_path}"') + err = env.Execute(f'llvm-objcopy --add-gnu-debuglink="{symbols_path}" "{binary_path}"') if err != 0: print(f"ERROR: Failed to add debug link (exit code {err})") Exit(1) + else: print("ERROR: Can't separate debug symbols on this platform") Exit(1) -def command(env, target, source): - result = env.Command( - target, - source, - Action(separate_debug_symbols, cmdstr="Separating debug symbols: $SOURCE -> $TARGET") - ) - Clean(target, target) - return result +def command(env, symbols_path, binary): + # Closure captures symbols_path + def action(target, source, env): + separate_debug_symbols(target, source, env, symbols_path) + + env.AddPostAction(binary, Action(action, cmdstr=f"Separating debug symbols: {binary} -> {symbols_path}")) + env.Clean(binary, symbols_path) + return binary def generate(env):