Skip to content

Commit

Permalink
use sentry binaries from s3 in protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Roshan Padaki committed Jul 30, 2021
1 parent 5318ce4 commit ce1e32b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 89 deletions.
66 changes: 10 additions & 56 deletions protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ if (CPPCHECK AND ${CI} MATCHES "TRUE" AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
"--error-exitcode=1" # Propagate cppcheck errors to cmake
"--suppress=shiftTooManyBitsSigned"
"--suppress=*:${CMAKE_SOURCE_DIR}/fractal/clipboard/clipboard_osx.m" # suppress all warnings for clipboard_osx.m since cppcheck isn't supported on Objective-C
"--suppress=*:*/sentry-native/*.c" # Ignore errors that occur in sentry-native c files. We shouldn't ignore errors in sentry-native h files
"--suppress=*:*/sentry-native/vendor/*" # However, we should ignore errors in the c and h files of sentry-native's build dependencies
"--suppress=*:${CMAKE_SOURCE_DIR}/fractal/utils/lodepng.*" # suppress all lodepng warnings, since this is an external library that we should not touch
"-D__linux" # Needed for sentry.h to pass
"--inline-suppr" # Allow cppcheck-suppress comments in code
)
else()
Expand Down Expand Up @@ -227,7 +224,16 @@ else()
find_package(OpenSSL REQUIRED)
endif()


find_library(LIB_SENTRY NAMES sentry PATHS "${CMAKE_BINARY_DIR}/lib/${arch}/sentry/${CMAKE_SYSTEM_NAME}"
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
NO_CMAKE_FIND_ROOT_PATH)
if (NOT LIB_SENTRY)
message(FATAL_ERROR "Library sentry was not found! ${CMAKE_BINARY_DIR}/lib/${arch}/sentry/${CMAKE_SYSTEM_NAME}")
endif()

find_library(STATIC_SDL2 NAMES SDL2 SDL2-static PATHS "${CMAKE_BINARY_DIR}/lib/${arch}/SDL2/${CMAKE_SYSTEM_NAME}"
NO_DEFAULT_PATH
Expand All @@ -252,40 +258,6 @@ if ((NOT LIBMFX AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
message(FATAL_ERROR "Library LIBMFX was not found! ${CMAKE_SOURCE_DIR}/lib/${arch}/mfx/${CMAKE_SYSTEM_NAME}")
endif()

#download and install Sentry CMake project
# This is fixed to sdk version 0.4.8
set(sentry_url https://github.com/getsentry/sentry-native/releases/download/0.4.10/sentry-native.zip)
set(sentry_dir sentry-native)
MESSAGE(VERBOSE ${CMAKE_SOURCE_DIR}/${sentry_dir})
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/${sentry_dir})
MESSAGE(STATUS "Downloading Sentry")
file(DOWNLOAD ${sentry_url} "${CMAKE_SOURCE_DIR}/${sentry_dir}.zip"
STATUS sentry_dl_status)
MESSAGE(VERBOSE ${sentry_dl_status})
file(MAKE_DIRECTORY ${sentry_dir})

execute_process(
COMMAND ${CMAKE_COMMAND} -E tar -xzf ${CMAKE_SOURCE_DIR}/${sentry_dir}.zip
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/${sentry_dir}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_SOURCE_DIR}/${sentry_dir}.zip
)
endif()

# Do this before setting the OSX compiler so we do not mess with the sentry-native build
message("Setting Sentry options")
set(SENTRY_BUILD_SHARED_LIBS ON CACHE BOOL "sentry create shared lib" FORCE)
set(SENTRY_BUILD_RUNTIMESTATIC ON CACHE BOOL "sentry runtimestatic" FORCE)
set(SENTRY_BACKEND crashpad CACHE STRING "sentry backend" FORCE)
add_subdirectory(sentry-native)

# set a standard location for the sentry shared lib so we can copy it into client/server build folders as a post build step
set_target_properties(sentry PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/sentry-native
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/sentry-native
)

#Set OSX compiler and SDK globally
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_C_COMPILER clang)
Expand All @@ -297,28 +269,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) # deployment target must be <= than compiler SDK above
endif()

# Store compiler options of native libraries, for now, we simply pass in "-w" to disable warnings
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(NONFRACTAL_COMPILE_OPTIONS -w)
target_compile_options(mini_chromium PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_compile_options(crashpad_compat PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
endif()
target_compile_options(crashpad_util PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(crashpad_client PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(crashpad_snapshot PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(crashpad_minidump PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(crashpad_handler_lib PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(crashpad_tools PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(crashpad_handler PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
target_compile_options(sentry PRIVATE ${NONFRACTAL_COMPILE_OPTIONS})
endif()

# Tell CMake where to look for includes
# Use SYSTEM flag to not get warnings from their files
include_directories(${CMAKE_SOURCE_DIR}) # For #include <fractal/**> semantics
include_directories(SYSTEM include)
include_directories(SYSTEM sentry-native/include)
include_directories(SYSTEM ${CMAKE_BINARY_DIR}/include)
include_directories(SYSTEM ${CMAKE_BINARY_DIR}/include/ffmpeg)

Expand Down
20 changes: 4 additions & 16 deletions protocol/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,21 @@ set_target_properties(FractalClient PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/client/build${arch}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/client/build${arch})

# copy the sentry shared library to the build folder after the build
# copy the sentry shared library and crashpad handler to the build folder after the build
add_custom_command(
TARGET FractalClient POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/sentry-native/${CMAKE_SHARED_LIBRARY_PREFIX}sentry${CMAKE_SHARED_LIBRARY_SUFFIX}
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_BINARY_DIR}/lib/64/sentry/${CMAKE_SYSTEM_NAME}/
$<TARGET_FILE_DIR:FractalClient>)

# MacOS and Windows default to crashpad for Sentry, and crashpad_handler needs to be in
# the same folder as the executable
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_custom_command(
TARGET FractalClient POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/sentry-native/crashpad_build/handler/crashpad_handler
$<TARGET_FILE_DIR:FractalClient>)
add_custom_command(
TARGET FractalClient POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/client/fclient
${CMAKE_BINARY_DIR})
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_custom_command(
TARGET FractalClient POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/sentry-native/crashpad_build/handler/crashpad_handler.exe
$<TARGET_FILE_DIR:FractalClient>)
add_custom_command(
TARGET FractalClient POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
Expand Down Expand Up @@ -120,7 +108,7 @@ target_link_libraries(FractalClient
fractalLogging
fractalUtils
${STATIC_SDL2}
sentry
${LIB_SENTRY}
)

#[[
Expand Down
39 changes: 39 additions & 0 deletions protocol/download-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,45 @@ if has_updated "$SDL_LIB"; then
aws s3 cp --only-show-errors "s3://fractal-protocol-shared-libs/$SDL_LIB" - | tar -xz -C "$SDL_LIB_DIR"
fi

###############################
# Download Sentry headers
###############################

# If the include/sentry directory doesn't exist, make it and fill it
# Or, if the lib has updated, refill the directory
LIB="fractal-sentry-headers.tar.gz"
SENTRY_DIR="$DEST_DIR/include/sentry"
if has_updated "$LIB" || [[ ! -d "$SENTRY_DIR" ]]; then
rm -rf "$SENTRY_DIR"
mkdir -p "$SENTRY_DIR"
aws s3 cp --only-show-errors "s3://fractal-protocol-shared-libs/$LIB" - | tar -xz -C "$SENTRY_DIR"

# Pull all SDL2 include files up a level and delete encapsulating folder
mv "$SENTRY_DIR/include"/* "$SENTRY_DIR"
rmdir "$SENTRY_DIR/include"
fi

###############################
# Download Sentry libraries
###############################

# Select sentry lib dir and sentry lib targz name based on OS
SENTRY_LIB_DIR="$DEST_DIR/lib/64/sentry/$OS"
if [[ "$OS" =~ "Windows" ]]; then
SENTRY_LIB="fractal-windows-sentry-shared-lib.tar.gz"
elif [[ "$OS" == "Darwin" ]]; then
SENTRY_LIB="fractal-macos-sentry-shared-lib.tar.gz"
elif [[ "$OS" == "Linux" ]]; then
SENTRY_LIB="fractal-linux-sentry-shared-lib.tar.gz"
fi

# Check if SENTRY_LIB has updated, and if so, create the dir and copy the libs into the source dir
if has_updated "$SENTRY_LIB"; then
rm -rf "$SENTRY_LIB_DIR"
mkdir -p "$SENTRY_LIB_DIR"
aws s3 cp --only-show-errors "s3://fractal-protocol-shared-libs/$SENTRY_LIB" - | tar -xz -C "$SENTRY_LIB_DIR"
fi

###############################
# Download OpenSSL headers
###############################
Expand Down
2 changes: 1 addition & 1 deletion protocol/fractal/logging/error_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Includes
============================
*/

#include <sentry.h>
#include <sentry/sentry.h>
#include <fractal/core/fractal.h>
#include "error_monitor.h"

Expand Down
20 changes: 4 additions & 16 deletions protocol/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,21 @@ set_target_properties(FractalServer PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/server/build${arch}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/server/build${arch})

# copy the sentry shared library to the build folder after the build
# copy the sentry shared library and crashpad handler to the build folder after the build
add_custom_command(
TARGET FractalServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/sentry-native/${CMAKE_SHARED_LIBRARY_PREFIX}sentry${CMAKE_SHARED_LIBRARY_SUFFIX}
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_BINARY_DIR}/lib/64/sentry/${CMAKE_SYSTEM_NAME}/
$<TARGET_FILE_DIR:FractalServer>)

# MacOS and Windows default to crashpad for Sentry, and crashpad_handler needs to be in
# the same folder as the executable
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_custom_command(
TARGET FractalServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/sentry-native/crashpad_build/handler/crashpad_handler
$<TARGET_FILE_DIR:FractalServer>)
add_custom_command(
TARGET FractalServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/server/fserver
${CMAKE_BINARY_DIR})
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_custom_command(
TARGET FractalServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/sentry-native/crashpad_build/handler/crashpad_handler.exe
$<TARGET_FILE_DIR:FractalServer>)
add_custom_command(
TARGET FractalServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
Expand Down Expand Up @@ -103,8 +91,8 @@ target_link_libraries(FractalServer
fractalLogging
fractalUtils
${STATIC_SDL2}
${LIB_SENTRY}
${LIBMFX}
sentry
)

#[[
Expand Down

0 comments on commit ce1e32b

Please sign in to comment.