From 54e701bb6a2ac29f6bc996cb40f430f3fc759224 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Mon, 19 Aug 2024 18:47:33 +0200 Subject: [PATCH] [crashpad,vcpkg-ci-crashpad] Fixes, Android, test port (#40519) --- ports/crashpad/crashpadConfig.cmake.in | 56 ++++++++++------ ports/crashpad/ndk-toolchain.diff | 22 ++++++ ports/crashpad/portfile.cmake | 67 ++++++++++--------- ports/crashpad/vcpkg.json | 10 ++- .../vcpkg-ci-crashpad/portfile.cmake | 4 ++ .../vcpkg-ci-crashpad/project/CMakeLists.txt | 9 +++ .../vcpkg-ci-crashpad/project/main.cpp | 7 ++ .../test_ports/vcpkg-ci-crashpad/vcpkg.json | 12 ++++ versions/baseline.json | 2 +- versions/c-/crashpad.json | 5 ++ 10 files changed, 137 insertions(+), 57 deletions(-) create mode 100644 ports/crashpad/ndk-toolchain.diff create mode 100644 scripts/test_ports/vcpkg-ci-crashpad/portfile.cmake create mode 100644 scripts/test_ports/vcpkg-ci-crashpad/project/CMakeLists.txt create mode 100644 scripts/test_ports/vcpkg-ci-crashpad/project/main.cpp create mode 100644 scripts/test_ports/vcpkg-ci-crashpad/vcpkg.json diff --git a/ports/crashpad/crashpadConfig.cmake.in b/ports/crashpad/crashpadConfig.cmake.in index aab0500d0a..120247a1b1 100644 --- a/ports/crashpad/crashpadConfig.cmake.in +++ b/ports/crashpad/crashpadConfig.cmake.in @@ -6,26 +6,42 @@ if(_IMPORT_PREFIX STREQUAL "/") set(_IMPORT_PREFIX "") endif() -add_library(crashpad INTERFACE) -add_library(crashpad::crashpad ALIAS crashpad) +include(CMakeFindDependencyMacro) +find_dependency(ZLIB) -set(CRASHPAD_LIBRARIES common client util base) +if(NOT TARGET crashpad::crashpad) + add_library(crashpad::crashpad INTERFACE IMPORTED) + target_include_directories(crashpad::crashpad INTERFACE "${_IMPORT_PREFIX}/include/crashpad") -if(WIN32) - target_compile_definitions(crashpad INTERFACE NOMINMAX) -elseif(APPLE) - list(APPEND CRASHPAD_LIBRARIES ApplicationServices - CoreFoundation Foundation IOKit Security bsm mig_output) + set(_libs client common util base) + if(APPLE) + list(APPEND _libs mig_output) + endif() + include(SelectLibraryConfigurations) + foreach(_lib IN LISTS _libs) + find_library(CRASHPAD_${_lib}_LIBRARY_RELEASE NAMES ${_lib} PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib" NO_DEFAULT_PATH) + find_library(CRASHPAD_${_lib}_LIBRARY_DEBUG NAMES ${_lib} PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib" NO_DEFAULT_PATH) + select_library_configurations(CRASHPAD_${_lib}) + target_link_libraries(crashpad::crashpad INTERFACE ${CRASHPAD_${_lib}_LIBRARIES}) + endforeach() + + if(WIN32) + target_compile_definitions(crashpad::crashpad INTERFACE NOMINMAX) + elseif(APPLE) + foreach(_lib IN ITEMS ApplicationServices CoreFoundation Foundation IOKit Security bsm) + find_library(CRASHPAD_${_lib}_LIBRARY NAMES ${_lib}) + target_link_libraries(crashpad::crashpad INTERFACE ${CRASHPAD_${_lib}_LIBRARY}) + endforeach() + elseif(ANDROID) + target_link_libraries(crashpad::crashpad INTERFACE log) + endif() + + target_link_libraries(crashpad::crashpad INTERFACE ZLIB::ZLIB) + + if(NOT TARGET crashpad) + add_library(crashpad ALIAS crashpad::crashpad) + endif() + + unset(_lib) + unset(_libs) endif() - -foreach(LIB_NAME ${CRASHPAD_LIBRARIES}) - find_library(_LIB ${LIB_NAME}) - target_link_libraries(crashpad INTERFACE ${_LIB}) - unset(_LIB CACHE) -endforeach() - -find_package(ZLIB REQUIRED) -target_link_libraries(crashpad INTERFACE ZLIB::ZLIB) - -target_include_directories(crashpad - INTERFACE ${_IMPORT_PREFIX}/include/crashpad) diff --git a/ports/crashpad/ndk-toolchain.diff b/ports/crashpad/ndk-toolchain.diff new file mode 100644 index 0000000000..1b16dfa488 --- /dev/null +++ b/ports/crashpad/ndk-toolchain.diff @@ -0,0 +1,22 @@ +diff --git a/build/config/BUILD.gn b/build/config/BUILD.gn +index 0802be8..dd77285 100644 +--- a/build/config/BUILD.gn ++++ b/build/config/BUILD.gn +@@ -425,7 +425,7 @@ toolchain("gcc_like_toolchain") { + ]) + + if (target_cpu == "arm") { +- tool_prefix = "arm-linux-androideabi" ++ # unused + } else if (target_cpu == "arm64") { + tool_prefix = "aarch64-linux-android" + } else if (target_cpu == "x86") { +@@ -446,7 +446,7 @@ toolchain("gcc_like_toolchain") { + cxx = ndk_bin_dir + clang_prefix + "-clang++" + asm = cxx + ld = cxx +- ar = ndk_bin_dir + tool_prefix + "-ar" ++ ar = ndk_bin_dir + "llvm-ar" + } else { + cc = "clang" + cxx = "clang++" diff --git a/ports/crashpad/portfile.cmake b/ports/crashpad/portfile.cmake index f7ac1d7237..305dedffd3 100644 --- a/ports/crashpad/portfile.cmake +++ b/ports/crashpad/portfile.cmake @@ -11,39 +11,26 @@ vcpkg_from_git( vcpkg_find_acquire_program(PYTHON3) vcpkg_replace_string("${SOURCE_PATH}/.gn" "script_executable = \"python3\"" "script_executable = \"${PYTHON3}\"") -function(checkout_in_path PATH URL REF) - if(EXISTS "${PATH}") - return() - endif() - - vcpkg_from_git( - OUT_SOURCE_PATH DEP_SOURCE_PATH - URL "${URL}" - REF "${REF}" - ) - file(RENAME "${DEP_SOURCE_PATH}" "${PATH}") - file(REMOVE_RECURSE "${DEP_SOURCE_PATH}") -endfunction() - # mini_chromium contains the toolchains and build configuration -checkout_in_path( - "${SOURCE_PATH}/third_party/mini_chromium/mini_chromium" - "https://chromium.googlesource.com/chromium/mini_chromium" - "dce72d97d1c2e9beb5e206c6a05a702269794ca3" -) -vcpkg_apply_patches( - SOURCE_PATH "${SOURCE_PATH}/third_party/mini_chromium/mini_chromium" - PATCHES - "fix-std-20.patch" -) - -if(VCPKG_TARGET_IS_LINUX) - # fetch lss - checkout_in_path( - "${SOURCE_PATH}/third_party/lss/lss" - https://chromium.googlesource.com/linux-syscall-support - 9719c1e1e676814c456b55f5f070eabad6709d31 +if(NOT EXISTS "${SOURCE_PATH}/third_party/mini_chromium/mini_chromium/BUILD.gn") + vcpkg_from_git(OUT_SOURCE_PATH mini_chromium + URL "https://chromium.googlesource.com/chromium/mini_chromium" + REF dce72d97d1c2e9beb5e206c6a05a702269794ca3 + PATCHES + fix-std-20.patch + ndk-toolchain.diff ) + file(REMOVE_RECURSE "${SOURCE_PATH}/third_party/mini_chromium/mini_chromium") + file(RENAME "${mini_chromium}" "${SOURCE_PATH}/third_party/mini_chromium/mini_chromium") +endif() + +if(NOT EXISTS "${SOURCE_PATH}/third_party/lss/lss/BUILD.gn" AND (VCPKG_TARGET_IS_ANDROID OR VCPKG_TARGET_IS_LINUX)) + vcpkg_from_git(OUT_SOURCE_PATH lss + URL https://chromium.googlesource.com/linux-syscall-support + REF 9719c1e1e676814c456b55f5f070eabad6709d31 + ) + file(REMOVE_RECURSE "${SOURCE_PATH}/third_party/lss/lss") + file(RENAME "${lss}" "${SOURCE_PATH}/third_party/lss/lss") endif() function(replace_gn_dependency INPUT_FILE OUTPUT_FILE LIBRARY_NAMES) @@ -77,10 +64,24 @@ replace_gn_dependency( "z;zlib;zlibd" ) +set(OPTIONS "target_cpu=\"${VCPKG_TARGET_ARCHITECTURE}\"") set(OPTIONS_DBG "is_debug=true") set(OPTIONS_REL "") -if(CMAKE_HOST_WIN32) +if(VCPKG_TARGET_IS_ANDROID) + vcpkg_cmake_get_vars(cmake_vars_file) + include("${cmake_vars_file}") + string(APPEND OPTIONS " target_os=\"android\" android_ndk_root=\"${VCPKG_DETECTED_CMAKE_ANDROID_NDK}\"") + +elseif(VCPKG_TARGET_IS_LINUX) + string(APPEND OPTIONS " target_os=\"linux\"") + +elseif(VCPKG_TARGET_IS_OSX) + string(APPEND OPTIONS " target_os=\"mac\"") + +elseif(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + string(APPEND OPTIONS " target_os=\"win\"") + # Load toolchains vcpkg_cmake_get_vars(cmake_vars_file) include("${cmake_vars_file}") @@ -108,7 +109,7 @@ endif() vcpkg_gn_configure( SOURCE_PATH "${SOURCE_PATH}" - OPTIONS " target_cpu=\"${VCPKG_TARGET_ARCHITECTURE}\" " + OPTIONS "${OPTIONS}" OPTIONS_DEBUG "${OPTIONS_DBG}" OPTIONS_RELEASE "${OPTIONS_REL}" ) diff --git a/ports/crashpad/vcpkg.json b/ports/crashpad/vcpkg.json index e574520afb..13297044f1 100644 --- a/ports/crashpad/vcpkg.json +++ b/ports/crashpad/vcpkg.json @@ -1,16 +1,20 @@ { "name": "crashpad", "version-date": "2024-04-11", - "port-version": 1, + "port-version": 2, "description": [ "Crashpad is a crash-reporting system.", "Crashpad is a library for capturing, storing and transmitting postmortem crash reports from a client to an upstream collection server. Crashpad aims to make it possible for clients to capture process state at the time of crash with the best possible fidelity and coverage, with the minimum of fuss." ], "homepage": "https://chromium.googlesource.com/crashpad/crashpad/+/master/README.md", "license": "Apache-2.0", - "supports": "linux | osx | (windows & !uwp)", + "supports": "android | linux | osx | (windows & !uwp)", "dependencies": [ - "curl", + { + "name": "curl", + "default-features": false, + "platform": "linux" + }, { "name": "vcpkg-cmake-get-vars", "host": true diff --git a/scripts/test_ports/vcpkg-ci-crashpad/portfile.cmake b/scripts/test_ports/vcpkg-ci-crashpad/portfile.cmake new file mode 100644 index 0000000000..bc785962c8 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-crashpad/portfile.cmake @@ -0,0 +1,4 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_cmake_configure(SOURCE_PATH "${CURRENT_PORT_DIR}/project") +vcpkg_cmake_build() diff --git a/scripts/test_ports/vcpkg-ci-crashpad/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-crashpad/project/CMakeLists.txt new file mode 100644 index 0000000000..b24d994354 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-crashpad/project/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.29) +project(crashpad-test CXX) + +set(CMAKE_CXX_STANDARD 11) + +add_executable(main main.cpp) + +find_package(crashpad CONFIG REQUIRED) +target_link_libraries(main PRIVATE crashpad::crashpad) diff --git a/scripts/test_ports/vcpkg-ci-crashpad/project/main.cpp b/scripts/test_ports/vcpkg-ci-crashpad/project/main.cpp new file mode 100644 index 0000000000..f450f9ef07 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-crashpad/project/main.cpp @@ -0,0 +1,7 @@ +#include "client/crashpad_client.h" + +int main() +{ + auto *client = new crashpad::CrashpadClient(); + return 0; +} diff --git a/scripts/test_ports/vcpkg-ci-crashpad/vcpkg.json b/scripts/test_ports/vcpkg-ci-crashpad/vcpkg.json new file mode 100644 index 0000000000..1903999e8b --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-crashpad/vcpkg.json @@ -0,0 +1,12 @@ +{ + "name": "vcpkg-ci-crashpad", + "version-string": "ci", + "description": "Validates crashpad", + "dependencies": [ + "crashpad", + { + "name": "vcpkg-cmake", + "host": true + } + ] +} diff --git a/versions/baseline.json b/versions/baseline.json index d857f76404..6e27e52f8b 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -2014,7 +2014,7 @@ }, "crashpad": { "baseline": "2024-04-11", - "port-version": 1 + "port-version": 2 }, "crashrpt": { "baseline": "1.4.3", diff --git a/versions/c-/crashpad.json b/versions/c-/crashpad.json index 678f9e4c71..15deb5e6be 100644 --- a/versions/c-/crashpad.json +++ b/versions/c-/crashpad.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "a8c3dac7327cb12c8f1885797a7d63ed99b6963c", + "version-date": "2024-04-11", + "port-version": 2 + }, { "git-tree": "43c2573b9400b543b26e7c9fbb091bdfefa51b79", "version-date": "2024-04-11",