diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b9e1cba4..e53acf6f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,17 @@ jobs: - uses: actions/checkout@v2 - run: make style + build-ios: + name: Xcode Build for iOS + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: "recursive" + - run: | + cmake -B sentry-native-xcode -GXcode -DCMAKE_SYSTEM_NAME=iOS + xcodebuild build -project sentry-native-xcode/Sentry-Native.xcodeproj + test: strategy: fail-fast: false diff --git a/CMakeLists.txt b/CMakeLists.txt index c83d06c6a..73f9edec4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ endif() if(WIN32) set(SENTRY_DEFAULT_TRANSPORT "winhttp") -elseif(APPLE OR LINUX) +elseif((APPLE AND NOT IOS) OR LINUX) # TODO: iOS needs its own transport set(SENTRY_DEFAULT_TRANSPORT "curl") else() set(SENTRY_DEFAULT_TRANSPORT "none") @@ -399,11 +399,15 @@ if(SENTRY_BACKEND_CRASHPAD) $ $ ) - install(EXPORT crashpad_export NAMESPACE sentry_crashpad:: FILE sentry_crashpad-targets.cmake - DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" - ) + if(NOT IOS) # TODO: figure out whats going on here + install(EXPORT crashpad_export NAMESPACE sentry_crashpad:: FILE sentry_crashpad-targets.cmake + DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" + ) + endif() + endif() + if(NOT IOS) + add_dependencies(sentry crashpad::handler) endif() - add_dependencies(sentry crashpad::handler) elseif(SENTRY_BACKEND_BREAKPAD) option(SENTRY_BREAKPAD_SYSTEM "Use system breakpad" OFF) if(SENTRY_BREAKPAD_SYSTEM) diff --git a/external/crashpad b/external/crashpad index fba97d0d5..3fc9e7166 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit fba97d0d5556ebd2dc94d183304ff990d2462820 +Subproject commit 3fc9e71661c1b2388e4d33aa6eb19948bbb383e2 diff --git a/include/sentry.h b/include/sentry.h index 93baaef63..d874cabc2 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -31,7 +31,12 @@ extern "C" { #ifdef _WIN32 # define SENTRY_PLATFORM_WINDOWS #elif defined(__APPLE__) -# define SENTRY_PLATFORM_MACOS +# include +# if defined(TARGET_OS_OSX) && TARGET_OS_OSX +# define SENTRY_PLATFORM_MACOS +# elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE +# define SENTRY_PLATFORM_IOS +# endif # define SENTRY_PLATFORM_DARWIN # define SENTRY_PLATFORM_UNIX #elif defined(__ANDROID__) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70505656e..71e63be4e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,9 +98,15 @@ endif() # backends if(SENTRY_BACKEND_CRASHPAD) target_compile_definitions(sentry PRIVATE SENTRY_BACKEND_CRASHPAD) - sentry_target_sources_cwd(sentry - backends/sentry_backend_crashpad.cpp - ) + if(IOS) + sentry_target_sources_cwd(sentry + backends/sentry_backend_crashpad_ios.cpp + ) + else() + sentry_target_sources_cwd(sentry + backends/sentry_backend_crashpad.cpp + ) + endif() elseif(SENTRY_BACKEND_BREAKPAD) target_compile_definitions(sentry PRIVATE SENTRY_BACKEND_BREAKPAD) sentry_target_sources_cwd(sentry diff --git a/src/backends/sentry_backend_crashpad_ios.cpp b/src/backends/sentry_backend_crashpad_ios.cpp new file mode 100644 index 000000000..70f0cb465 --- /dev/null +++ b/src/backends/sentry_backend_crashpad_ios.cpp @@ -0,0 +1,49 @@ +extern "C" { +#include "sentry_boot.h" + +#include "sentry_alloc.h" +#include "sentry_backend.h" +#include "sentry_core.h" +} + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#pragma GCC diagnostic ignored "-Wfour-char-constants" + +#include "client/crashpad_client.h" + +#pragma GCC diagnostic pop + +extern "C" { + +static int +sentry__crashpad_backend_startup( + sentry_backend_t *UNUSED(backend), const sentry_options_t *UNUSED(options)) +{ + SENTRY_TRACE("starting crashpad inprocess handler"); + + crashpad::CrashpadClient client; + client.StartCrashpadInProcessHandler(); + + return 0; +} + +sentry_backend_t * +sentry__backend_new(void) +{ + sentry_backend_t *backend = SENTRY_MAKE(sentry_backend_t); + if (!backend) { + return NULL; + } + memset(backend, 0, sizeof(sentry_backend_t)); + + backend->startup_func = sentry__crashpad_backend_startup; + backend->can_capture_after_shutdown = true; + + return backend; +} +} diff --git a/src/path/sentry_path_unix.c b/src/path/sentry_path_unix.c index 745fd0fe7..18061869e 100644 --- a/src/path/sentry_path_unix.c +++ b/src/path/sentry_path_unix.c @@ -191,8 +191,8 @@ sentry__path_filename_matches(const sentry_path_t *path, const char *filename) bool sentry__path_ends_with(const sentry_path_t *path, const char *suffix) { - int pathlen = strlen(path->path); - int suffixlen = strlen(suffix); + size_t pathlen = strlen(path->path); + size_t suffixlen = strlen(suffix); if (suffixlen > pathlen) { return false; } diff --git a/src/sentry_core.c b/src/sentry_core.c index fc58bf158..43a7c12bd 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -264,7 +264,8 @@ sentry_user_consent_get(void) { sentry_user_consent_t rv = SENTRY_USER_CONSENT_UNKNOWN; SENTRY_WITH_OPTIONS (options) { - rv = sentry__atomic_fetch((long *)&options->user_consent); + rv = (sentry_user_consent_t)sentry__atomic_fetch( + (long *)&options->user_consent); } return rv; } diff --git a/src/sentry_utils.c b/src/sentry_utils.c index d7cf03964..844ccc5a9 100644 --- a/src/sentry_utils.c +++ b/src/sentry_utils.c @@ -136,7 +136,7 @@ sentry__url_parse(sentry_url_t *url_out, const char *url) SKIP_WHILE_NOT(tmp, '/'); aux_buf = sentry__string_clonen(ptr, tmp - ptr); char *end; - url_out->port = strtol(aux_buf, &end, 10); + url_out->port = (int)strtol(aux_buf, &end, 10); if (end != aux_buf + strlen(aux_buf)) { goto error; } @@ -434,7 +434,7 @@ sentry__iso8601_to_msec(const char *iso) // forwards to `stdtod`, but it does not define `vsnprintf_l` sadly. This means // if Android ever adds locale support in NDK we will have to revisit this code // to ensure the C locale is also used there. -#ifndef SENTRY_PLATFORM_ANDROID +#if !defined(SENTRY_PLATFORM_ANDROID) && !defined(SENTRY_PLATFORM_IOS) static sentry__locale_t c_locale() { @@ -457,7 +457,7 @@ sentry__strtod_c(const char *ptr, char **endptr) { #ifdef SENTRY_PLATFORM_WINDOWS return _strtod_l(ptr, endptr, c_locale()); -#elif defined(SENTRY_PLATFORM_ANDROID) +#elif defined(SENTRY_PLATFORM_ANDROID) || defined(SENTRY_PLATFORM_IOS) return strtod(ptr, endptr); #else return strtod_l(ptr, endptr, c_locale()); @@ -473,7 +473,7 @@ sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...) int rv; #ifdef SENTRY_PLATFORM_WINDOWS rv = _vsnprintf_l(buf, buf_size, fmt, c_locale(), args); -#elif defined(SENTRY_PLATFORM_ANDROID) +#elif defined(SENTRY_PLATFORM_ANDROID) || defined(SENTRY_PLATFORM_IOS) rv = vsnprintf(buf, buf_size, fmt, args); #elif defined(SENTRY_PLATFORM_MACOS) rv = vsnprintf_l(buf, buf_size, c_locale(), fmt, args); diff --git a/src/unwinder/sentry_unwinder_libbacktrace.c b/src/unwinder/sentry_unwinder_libbacktrace.c index 01f97707c..a9e2460d8 100644 --- a/src/unwinder/sentry_unwinder_libbacktrace.c +++ b/src/unwinder/sentry_unwinder_libbacktrace.c @@ -13,12 +13,12 @@ sentry__unwind_stack_libbacktrace( if (addr) { #if defined(SENTRY_PLATFORM_MACOS) && __has_builtin(__builtin_available) if (__builtin_available(macOS 10.14, *)) - return backtrace_from_fp(addr, ptrs, max_frames); + return (size_t)backtrace_from_fp(addr, ptrs, (int)max_frames); #endif return 0; } else if (uctx) { return 0; } else { - return backtrace(ptrs, max_frames); + return (size_t)backtrace(ptrs, (int)max_frames); } }