From 297b9bb192381c2fb98826d1549dc14cc9531e9c Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Sat, 15 Jan 2022 21:02:01 +0100 Subject: [PATCH] Enable support for building rz-libswift on cutter (#2841) --- .github/workflows/ccpp.yml | 3 +++ CMakeLists.txt | 1 + dist/CMakeLists.txt | 23 +++++++++++++++++++++++ dist/bundle_rz_libswift.ps1 | 16 ++++++++++++++++ scripts/rz-libswift.sh | 19 +++++++++++++++++++ src/menus/DecompilerContextMenu.cpp | 2 +- 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 dist/bundle_rz_libswift.ps1 create mode 100755 scripts/rz-libswift.sh diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 789e1def..e567c6b9 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -121,6 +121,7 @@ jobs: -DCUTTER_ENABLE_PACKAGING=ON \ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON \ -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ + -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON \ -DCMAKE_INSTALL_PREFIX=appdir/usr \ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ .. @@ -187,6 +188,7 @@ jobs: -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON \ -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ -DCUTTER_PACKAGE_JSDEC=ON \ + -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON \ -DCPACK_PACKAGE_FILE_NAME="$PACKAGE_NAME" \ -DCMAKE_FRAMEWORK_PATH="$BREAKPAD_FRAMEWORK_DIR" \ -DCPACK_BUNDLE_APPLE_CERT_APP="-" \ @@ -224,6 +226,7 @@ jobs: -DCUTTER_ENABLE_PACKAGING=ON ^ -DCUTTER_PACKAGE_DEPENDENCIES=ON ^ -DCUTTER_PACKAGE_RZ_GHIDRA=ON ^ + -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON ^ -DCUTTER_PACKAGE_JSDEC=ON ^ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON ^ -DCUTTER_ENABLE_CRASH_REPORTS=ON ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index 92b49af4..9c0f30b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS "Enable downloading of dependencies. S option(CUTTER_ENABLE_PACKAGING "Enable building platform-specific packages for distributing" OFF) option(CUTTER_PACKAGE_DEPENDENCIES "During install step include the third party dependencies." OFF) option(CUTTER_PACKAGE_RZ_GHIDRA "Compile and install rz-ghidra during install step." OFF) +option(CUTTER_PACKAGE_RZ_LIBSWIFT, "Compile and install rz-libswift demangler during the install step." OFF) option(CUTTER_PACKAGE_JSDEC "Compile and install jsdec during install step." OFF) OPTION(CUTTER_QT6 "Use QT6" OFF) diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt index cf57cc66..6ce64463 100644 --- a/dist/CMakeLists.txt +++ b/dist/CMakeLists.txt @@ -32,6 +32,18 @@ if(WIN32) endif() ") endif() + if (CUTTER_PACKAGE_RZ_LIBSWIFT AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + install(CODE " + set(ENV{RZ_PREFIX} \"\${CMAKE_INSTALL_PREFIX}\") + set(ENV{PATH} \"\${CMAKE_INSTALL_PREFIX};\$ENV{PATH}\") + execute_process(COMMAND powershell \"${CMAKE_CURRENT_SOURCE_DIR}/bundle_rz_libswift.ps1\" \"\${CMAKE_INSTALL_PREFIX}\" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE SCRIPT_RESULT) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to package rz-libswift\") + endif() + ") + endif() endif() ################################################ @@ -93,6 +105,17 @@ if(APPLE) ") endif() + if (CUTTER_PACKAGE_RZ_LIBSWIFT AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + install(CODE " + execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/rz-libswift.sh\" --pkg-config-path=\${CMAKE_INSTALL_PREFIX}/lib/pkgconfig --prefix=\${CMAKE_INSTALL_PREFIX} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE SCRIPT_RESULT) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to package rz-libswift\") + endif() + ") + endif() + endif() ################################################ diff --git a/dist/bundle_rz_libswift.ps1 b/dist/bundle_rz_libswift.ps1 new file mode 100644 index 00000000..12928c93 --- /dev/null +++ b/dist/bundle_rz_libswift.ps1 @@ -0,0 +1,16 @@ +$dist = $args[0] +$python = Split-Path((Get-Command python.exe).Path) + +if (-not (Test-Path -Path 'libswift' -PathType Container)) { + git clone https://github.com/rizinorg/rz-libswift.git --depth 1 libswift +} +cd libswift +& meson.exe --buildtype=release --prefix=$dist build +ninja -C build install +$pathdll = "$dist/lib/plugins/swift.dll" +if(![System.IO.File]::Exists($pathdll)) { + type build/meson-logs/meson-log.txt + ls "$dist/lib/plugins/" + throw (New-Object System.IO.FileNotFoundException("File not found: $pathdll", $pathdll)) +} +Remove-Item -Recurse -Force $dist/lib/plugins/libswift.lib diff --git a/scripts/rz-libswift.sh b/scripts/rz-libswift.sh new file mode 100755 index 00000000..0772cb4c --- /dev/null +++ b/scripts/rz-libswift.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") + +cd "$SCRIPTPATH/.." + +if [[ ! -d libswift ]]; then + git clone https://github.com/rizinorg/rz-libswift.git --depth 1 libswift +fi + +cd libswift +rm -rf build || sleep 0 +mkdir build && cd build +meson --buildtype=release "$@" .. +ninja +ninja install + diff --git a/src/menus/DecompilerContextMenu.cpp b/src/menus/DecompilerContextMenu.cpp index e0e1baff..d36cf0b7 100644 --- a/src/menus/DecompilerContextMenu.cpp +++ b/src/menus/DecompilerContextMenu.cpp @@ -564,7 +564,7 @@ void DecompilerContextMenu::updateTargetMenuActions() RzCoreLocked core = Core()->core(); if (isReference()) { QString name; - QMenu *menu; + QMenu *menu = nullptr; if (annotationHere->type == RZ_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE || annotationHere->type == RZ_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE) { menu = mainWindow->createShowInMenu(this, annotationHere->reference.offset,