From 78dcba4c260c9f01e2381c70066661a2b3924ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 26 Nov 2020 17:51:20 +0100 Subject: [PATCH] More Rizin Updating in CMake and use it in AppVeyor (#5) --- .appveyor.yml | 78 +++++++-------- meson.py | 102 -------------------- scripts/appveyor_r2ghidra.sh | 11 --- scripts/appveyor_rz-ghidra.sh | 11 +++ prepare_r2.bat => scripts/prepare_rizin.bat | 13 ++- scripts/{r2ghidra.sh => rz-ghidra.sh} | 11 ++- src/CMakeLists.txt | 12 ++- src/cmake/BundledRizin.cmake | 4 +- src/cmake/Packaging.cmake | 22 ++--- 9 files changed, 81 insertions(+), 183 deletions(-) delete mode 100644 meson.py delete mode 100755 scripts/appveyor_r2ghidra.sh create mode 100755 scripts/appveyor_rz-ghidra.sh rename prepare_r2.bat => scripts/prepare_rizin.bat (52%) rename scripts/{r2ghidra.sh => rz-ghidra.sh} (55%) diff --git a/.appveyor.yml b/.appveyor.yml index 11a36279..9d55a59d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,63 +10,55 @@ configuration: environment: NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-win.zip VSVARSALLPATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat' - QTPATH: 'cutter-deps\qt' - USE_APPVEYOR_QT: 'false' - matrix: - # Build: qmake vs2017 x86 shared - #- ARCH: x86 - # PYTHON: 'C:\Python36' - # QMAKE: 1 - # DEPLOY: true - # QTPATH: 'C:\Qt\5.12\msvc2017' - # USE_APPVEYOR_QT: true - # Build: qmake vs2017 x64 shared - - ARCH: x64 - PYTHON: 'C:\Python36-x64' - QMAKE: 1 - DEPLOY: true - # Build: meson ninja x64 static - - ARCH: x64 - PYTHON: 'C:\Python36-x64' - MESON: 1 - BACKEND: ninja - DEPLOY: false + ARCH: x64 + PYTHON: 'C:\Python36-x64' + PACKAGE_NAME: cutter-git-x64.Windows install: + - ps: $fileContent = "-----BEGIN RSA PRIVATE KEY-----`n" + - ps: $fileContent += $env:priv_key.Replace(' ', "`n") + - ps: $fileContent += "`n-----END RSA PRIVATE KEY-----`n" + - ps: Set-Content $env:userprofile\.ssh\id_rsa $fileContent + # -- - ps: $env:path = ($env:path -split ";").Where({!($_ -like "*Microsoft SQL Server*")}) -join ";" - cmd: C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER && scripts/fetch_deps.sh" - - cmd: set "CUTTER_DEPS_DIR=%APPVEYOR_BUILD_FOLDER%\cutter-deps" + - cmd: set "CUTTER_DEPS=%APPVEYOR_BUILD_FOLDER%\cutter-deps" - cmd: set "PATH=%CD%;%PYTHON%;%PATH%" - cmd: call "%VSVARSALLPATH%" %ARCH% - - cmd: if "%USE_APPVEYOR_QT%" == "false" ( set "QTPATH=%APPVEYOR_BUILD_FOLDER%\%QTPATH%" ) - - cmd: set "PATH=%QTPATH%\bin;%PYTHON%\Scripts\;%PATH%" + - cmd: set "PATH=%CUTTER_DEPS%\qt\bin;%PYTHON%\Scripts\;%PATH%" - cmd: echo %PATH% - - cmd: python -m pip install meson==0.52 - - cmd: where meson.exe - - cmd: powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; wget %NINJA_URL% -OutFile ninja.zip; Expand-Archive .\ninja.zip -DestinationPath ." + - cmd: python -m pip install meson ninja + - ps: choco install winflexbison3 # Artifacts - - cmd: set "ARTIFACT_NAME=Cutter-v1.12.0-%ARCH%.Windows" - - cmd: if defined MESON ( set "ARTIFACT_PATH=dist_%ARCH%" ) else ( set "ARTIFACT_PATH=build_%ARCH%\cutter" ) + - cmd: set "ARTIFACT_NAME=%PACKAGE_NAME%.zip" + - cmd: set "ARTIFACT_PATH=build\%ARTIFACT_NAME%" before_build: - - cmd: git submodule update --init + - cmd: git submodule update --init --recursive - scripts\prepare_breakpad.bat # Build config build_script: - - cmd: if defined QMAKE ( call prepare_r2.bat ) - - cmd: if defined QMAKE ( C:\msys64\usr\bin\bash -lc "export PATH=\"/c/msys64/usr/bin:$PATH\" && cd \"$APPVEYOR_BUILD_FOLDER\" && scripts/appveyor_r2ghidra.sh" ) - - cmd: if defined QMAKE ( call build.bat CUTTER_APPVEYOR_R2DEC=true CUTTER_R2GHIDRA_STATIC=true R2GHIDRA_SOURCE="%APPVEYOR_BUILD_FOLDER%/r2ghidra" R2GHIDRA_INSTALL_PATH="%APPVEYOR_BUILD_FOLDER%/r2_dist/lib/plugins" CUTTER_ENABLE_CRASH_REPORTS=true CUTTER_ENABLE_PYTHON=true CUTTER_ENABLE_PYTHON_BINDINGS=true CUTTER_DEPS_DIR="%CUTTER_DEPS_DIR%" ) - - cmd: if defined MESON ( python meson.py --release --dist=%ARTIFACT_PATH% --backend=%BACKEND% --python ) - -after_build: - - cmd: if defined QMAKE ( set "PATH=%CD%\r2_dist\bin;%PATH%" && powershell scripts\bundle_r2dec.ps1 "%CD%\%ARTIFACT_PATH%" ) - #- cmd: if defined QMAKE ( C:\msys64\usr\bin\bash -lc "export PATH=\"/c/msys64/usr/bin:$PATH\" && cd \"$APPVEYOR_BUILD_FOLDER\" && scripts/appveyor_r2ghidra.sh" ) - #- cmd: powershell scripts\bundle_openssl.ps1 %ARCH% "%CD%\%ARTIFACT_PATH%" - - cmd: powershell scripts\bundle_python.ps1 %ARCH% "%CD%\%ARTIFACT_PATH%" - - cmd: xcopy "%CUTTER_DEPS_DIR%\pyside\lib\site-packages" "%ARTIFACT_PATH%\python36\site-packages" /e /i /h - - cmd: copy "%CUTTER_DEPS_DIR%\pyside\bin\shiboken2.abi3.dll" "%ARTIFACT_PATH%\" - - cmd: copy "%CUTTER_DEPS_DIR%\pyside\bin\pyside2.abi3.dll" "%ARTIFACT_PATH%\" + - cmd: | + mkdir build + cd build + set PACKAGE_NAME=cutter-git-x64.Windows + - cmd: "cmake + -DCMAKE_BUILD_TYPE=Release + -DCUTTER_USE_BUNDLED_RIZIN=ON + -DCUTTER_ENABLE_PYTHON=ON + -DCUTTER_ENABLE_PYTHON_BINDINGS=ON + -DCUTTER_PACKAGE_DEPENDENCIES=ON + -DCUTTER_PACKAGE_R2GHIDRA=ON + -DCUTTER_PACKAGE_R2DEC=OFF + -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON + -DCUTTER_ENABLE_CRASH_REPORTS=ON + -DCMAKE_PREFIX_PATH=%CUTTER_DEPS%\\pyside + -DCPACK_PACKAGE_FILE_NAME=%PACKAGE_NAME% + -G Ninja + ../src" + - cmd: cmake --build . --config Release + - cmd: cmake --build . --config Release --target package # Tests test: off diff --git a/meson.py b/meson.py deleted file mode 100644 index e158c945..00000000 --- a/meson.py +++ /dev/null @@ -1,102 +0,0 @@ -import argparse -import importlib.util -import logging -import os -import subprocess -import sys - -ROOT = None -log = None -r2_meson_mod = None - -def import_r2_meson_mod(): - """Import radare2/sys/meson.py""" - global r2_meson_mod - folder = os.path.dirname(__file__) - r2_meson_path = os.path.join(folder, 'radare2', 'sys', 'meson.py') - r2_meson_spec = importlib.util.spec_from_file_location('meson', r2_meson_path) - r2_meson_mod = importlib.util.module_from_spec(r2_meson_spec) - r2_meson_spec.loader.exec_module(r2_meson_mod) - -def set_global_vars(): - global log - global ROOT - - ROOT = os.path.abspath(os.path.dirname(__file__)) - - logging.basicConfig(format='[%(name)s][%(levelname)s]: %(message)s', - level=logging.DEBUG) - log = logging.getLogger('cutter-meson') - log.debug('ROOT: %s', ROOT) - - r2_meson_mod.set_global_variables() - -def win_dist(args): - os.makedirs(args.dist) - r2_meson_mod.copy(os.path.join(args.dir, 'Cutter.exe'), args.dist) - log.debug('Deploying Qt5') - subprocess.call(['windeployqt', '--release', os.path.join(args.dist, 'Cutter.exe')]) - log.debug('Deploying libr2') - r2_meson_mod.PATH_FMT.update(r2_meson_mod.R2_PATH) - r2_meson_mod.meson('install', options=[['-C', '{}'.format(args.dir)], '--no-rebuild']) - -def build(args): - cutter_builddir = os.path.join(ROOT, args.dir) - if not os.path.exists(cutter_builddir): - defines = ['-Denable_python=%s' % str(args.python).lower(), - '-Denable_python_bindings=%s' % str(args.python_bindings).lower()] - if os.name == 'nt': - defines.append('-Dradare2:r2_incdir=radare2/include') - defines.append('-Dradare2:r2_libdir=radare2/lib') - defines.append('-Dradare2:r2_datdir=radare2/share') - defines.append('-Dc_args=-D_UNICODE -DUNICODE') - r2_meson_mod.meson('setup', rootdir=os.path.join(ROOT, 'src'), builddir=args.dir, - prefix=os.path.abspath(args.dist), backend=args.backend, - release=args.release, shared=False, options=defines) - if not args.nobuild: - log.info('Building cutter') - if args.backend == 'ninja': - r2_meson_mod.ninja(cutter_builddir) - else: - project = os.path.join(cutter_builddir, 'Cutter.sln') - r2_meson_mod.msbuild(project, '/m') - -def main(): - set_global_vars() - - parser = argparse.ArgumentParser(description='Meson script for Cutter') - parser.add_argument('--backend', choices=r2_meson_mod.BACKENDS, - default='ninja', help='Choose build backend') - parser.add_argument('--dir', default='build', - help='Destination build directory') - parser.add_argument('--python', action='store_true', - help='Enable Python support') - parser.add_argument('--python-bindings', action='store_true', - help='Enable Python Bindings') - parser.add_argument('--release', action='store_true', - help='Set the build as Release (remove debug info)') - parser.add_argument('--nobuild', action='store_true', - help='Only run meson and do not build.') - if os.name == 'nt': - parser.add_argument('--dist', help='dist directory') - args = parser.parse_args() - - if os.name == 'nt' and not args.dist: - args.dist = args.dir - args.dist = os.path.abspath(args.dist) - args.dir = os.path.abspath(args.dir) - - if hasattr(args, 'dist') and args.dist and os.path.exists(args.dist): - log.error('%s already exists', args.dist) - sys.exit(1) - - log.debug('Arguments: %s', args) - - build(args) - - if os.name == 'nt' and hasattr(args, 'dist') and args.dist: - win_dist(args) - -import_r2_meson_mod() -if __name__ == '__main__': - main() diff --git a/scripts/appveyor_r2ghidra.sh b/scripts/appveyor_r2ghidra.sh deleted file mode 100755 index 463619b2..00000000 --- a/scripts/appveyor_r2ghidra.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -eu - -scripts/r2ghidra.sh \ - -DCMAKE_C_COMPILER=cl \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_PREFIX_PATH="$APPVEYOR_BUILD_FOLDER/r2_dist;$APPVEYOR_BUILD_FOLDER/r2_dist/include/libr;$APPVEYOR_BUILD_FOLDER/r2_dist/include/libr/sdb" \ - -DCMAKE_INSTALL_PREFIX="$APPVEYOR_BUILD_FOLDER/r2_dist" \ - -DRADARE2_INSTALL_PLUGDIR="$APPVEYOR_BUILD_FOLDER/r2_dist/lib/plugins" \ - -DBUILD_SLEIGH_PLUGIN=OFF \ No newline at end of file diff --git a/scripts/appveyor_rz-ghidra.sh b/scripts/appveyor_rz-ghidra.sh new file mode 100755 index 00000000..d5eff641 --- /dev/null +++ b/scripts/appveyor_rz-ghidra.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -eu + +scripts/rz-ghidra.sh \ + -DCMAKE_C_COMPILER=cl \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH="$APPVEYOR_BUILD_FOLDER/rz_dist;$APPVEYOR_BUILD_FOLDER/rz_dist/include/librz;$APPVEYOR_BUILD_FOLDER/rz_dist/include/librz/sdb" \ + -DCMAKE_INSTALL_PREFIX="$APPVEYOR_BUILD_FOLDER/rz_dist" \ + -DRIZIN_INSTALL_PLUGDIR="$APPVEYOR_BUILD_FOLDER/rz_dist/lib/plugins" \ + -DBUILD_SLEIGH_PLUGIN=OFF diff --git a/prepare_r2.bat b/scripts/prepare_rizin.bat similarity index 52% rename from prepare_r2.bat rename to scripts/prepare_rizin.bat index 770834c8..21eb572f 100644 --- a/prepare_r2.bat +++ b/scripts/prepare_rizin.bat @@ -10,13 +10,12 @@ IF !ERRORLEVEL! NEQ 0 ( ) SET "PATH=%CD%;%PATH%" -SET "R2DIST=r2_dist" +SET "RZDIST=rz_dist" -ECHO Building radare2 (%PLATFORM%) -CD radare2 +ECHO Building Rizin (%PLATFORM%) +CD rizin git clean -xfd -RMDIR /S /Q ..\%R2DIST% -rem python sys\meson.py --release --shared --install --prefix=%CD%\..\%R2DIST% --options "r2_datdir=radare2/share" "r2_libdir=radare2/lib" #"c_args=-D_UNICODE -DUNICODE" -meson.exe r2_builddir --buildtype=release --prefix=%CD%\..\%R2DIST% || EXIT /B 1 -ninja -C r2_builddir install || EXIT /B 1 +RMDIR /S /Q ..\%RZDIST% +meson.exe rz_builddir --buildtype=release --prefix=%CD%\..\%RZDIST% || EXIT /B 1 +ninja -C rz_builddir install || EXIT /B 1 IF !ERRORLEVEL! NEQ 0 EXIT /B 1 diff --git a/scripts/r2ghidra.sh b/scripts/rz-ghidra.sh similarity index 55% rename from scripts/r2ghidra.sh rename to scripts/rz-ghidra.sh index 2b11657d..81a5a334 100755 --- a/scripts/r2ghidra.sh +++ b/scripts/rz-ghidra.sh @@ -6,14 +6,17 @@ SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") cd "$SCRIPTPATH/.." -if [[ ! -d r2ghidra ]]; then +if [[ ! -d rz-ghidra ]]; then # remove depth, branch and uncomment lines bellow to use specifc commit - git clone --recurse-submodules https://github.com/radareorg/r2ghidra.git --depth 1 --branch master || exit 1 - #pushd r2ghidra + + git clone --recurse-submodules git@github.com:rizinorg/rz-ghidra.git --depth 1 --branch master || exit 1 + # git clone --recurse-submodules https://github.com/rizinorg/rz-ghidra.git --depth 1 --branch master || exit 1 + + #pushd rz-ghidra #git checkout --recurse-submodules 5e845f4b50e8559bd51af03b22b6586e8cc5c35c #popd fi -cd r2ghidra || exit 1 +cd rz-ghidra || exit 1 mkdir build && cd build || exit 1 cmake -G Ninja "$@" .. || exit 1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7bb9784e..967fd818 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,7 +23,7 @@ set(SHIBOKEN_EXTRA_OPTIONS "" CACHE STRING "Extra options for shiboken generator set(CUTTER_EXTRA_PLUGIN_DIRS "" CACHE STRING "List of addition plugin locations") option(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS "Enable downloading of dependencies. Setting to OFF doesn't affect any downloads done by r2 build." OFF) option(CUTTER_PACKAGE_DEPENDENCIES "During install step include the third party dependencies." OFF) -option(CUTTER_PACKAGE_R2GHIDRA "Compile and install r2ghidra during install step." OFF) +option(CUTTER_PACKAGE_RZ_GHIDRA "Compile and install rz-ghidra during install step." OFF) option(CUTTER_PACKAGE_R2DEC "Compile and install r2dec during install step." OFF) OPTION(CUTTER_QT6 "Use QT6" OFF) @@ -231,8 +231,14 @@ if(CUTTER_ENABLE_PYTHON) if (WIN32) # On windows some of the Python STABLE API functions are in seperate library # which isn't added by CMake. - get_filename_component(_PYTHON_LIB_DIR ${PYTHON_LIBRARIES} DIRECTORY) - target_link_directories(Cutter PRIVATE ${_PYTHON_LIB_DIR}) + foreach(_PYTHON_LIBRARY ${PYTHON_LIBRARIES}) + # Skip extra "optimized" and "debug" values that are only meant for passing to target_link_libraries() + if((NOT _PYTHON_LIBRARY STREQUAL "optimized") AND (NOT _PYTHON_LIBRARY STREQUAL "debug")) + get_filename_component(_PYTHON_LIB_DIR ${_PYTHON_LIBRARY} DIRECTORY) + message(STATUS "Add extra library dir for Python: ${_PYTHON_LIB_DIR}") + target_link_directories(Cutter PRIVATE ${_PYTHON_LIB_DIR}) + endif() + endforeach() endif() target_link_libraries(Cutter PRIVATE ${PYTHON_LIBRARIES}) if(CUTTER_ENABLE_PYTHON_BINDINGS) diff --git a/src/cmake/BundledRizin.cmake b/src/cmake/BundledRizin.cmake index 18e3a6bc..f06044da 100644 --- a/src/cmake/BundledRizin.cmake +++ b/src/cmake/BundledRizin.cmake @@ -8,7 +8,7 @@ if(WIN32) set(RIZIN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/$") endif() set(RIZIN_INSTALL_BINPATH ".") - set(MESON_OPTIONS "--prefix=${RIZIN_INSTALL_DIR}" "--bindir=${RIZIN_INSTALL_BINPATH}" "-Dr2_incdir=include/librz") + set(MESON_OPTIONS "--prefix=${RIZIN_INSTALL_DIR}" "--bindir=${RIZIN_INSTALL_BINPATH}" "-Drz_incdir=include/librz") else() set(RIZIN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/Rizin-prefix") set(MESON_OPTIONS "--prefix=${RIZIN_INSTALL_DIR}" --libdir=lib) @@ -46,7 +46,7 @@ set (R2_LIBS rz_core rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg rz_reg rz_search rz_syscall rz_socket rz_magic rz_crypto) set (R2_EXTRA_LIBS rz_main) -set (R2_BIN r2agent rabin2 rizin radiff2 rafind2 ragg2 rahash2 rarun2 rasm2 rax2) +set (R2_BIN rz-agent rz-bin rizin rz-diff rz-find rz-gg rz-hash rz-run rz-asm rz-ax) target_link_libraries(Rizin INTERFACE ${R2_LIBS}) diff --git a/src/cmake/Packaging.cmake b/src/cmake/Packaging.cmake index b9725e02..cca090d3 100644 --- a/src/cmake/Packaging.cmake +++ b/src/cmake/Packaging.cmake @@ -13,14 +13,14 @@ if(WIN32) endif() install(SCRIPT cmake/WindowsBundleQt.cmake) endif() - if (CUTTER_PACKAGE_R2GHIDRA) + if (CUTTER_PACKAGE_RZ_GHIDRA) if (CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) # Currently using external project only for downloading source # It neeeds to link against compiled cutter so for now build it using custom install script. - # That way r2ghidra build process is the same as with any other external plugin built against + # That way rz-ghidra build process is the same as with any other external plugin built against # installed Cutter. - ExternalProject_Add(R2Ghidra - GIT_REPOSITORY https://github.com/radareorg/r2ghidra.git + ExternalProject_Add(rz-ghidra + GIT_REPOSITORY git@github.com:rizinorg/rz-ghidra GIT_TAG master CONFIGURE_COMMAND "" BUILD_COMMAND "" @@ -29,27 +29,27 @@ if(WIN32) endif() install(CODE " execute_process( - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/R2Ghidra-prefix/src/R2Ghidra-build + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/rz-ghidra-prefix/src/rz-ghidra-build RESULT_VARIABLE SCRIPT_RESULT COMMAND \${CMAKE_COMMAND} - ../R2Ghidra - -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=\"\${CMAKE_INSTALL_PREFIX}\;\${CMAKE_INSTALL_PREFIX}/include/libr\;\${CMAKE_INSTALL_PREFIX}/include/libr/sdb\" + ../rz-ghidra + -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=\"\${CMAKE_INSTALL_PREFIX}\;\${CMAKE_INSTALL_PREFIX}/include/librz\;\${CMAKE_INSTALL_PREFIX}/include/librz/sdb\" -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} - -DRADARE2_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/lib/plugins + -DRIZIN_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/lib/plugins -DCUTTER_INSTALL_PLUGDIR=plugins/native -DBUILD_CUTTER_PLUGIN=ON -DBUILD_SLEIGH_PLUGIN=OFF -G Ninja ) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to configure r2ghidra\") + message(FATAL_ERROR \"Failed to configure rz-ghidra\") endif() - execute_process(WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/R2Ghidra-prefix/src/R2Ghidra-build + execute_process(WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/rz-ghidra-prefix/src/rz-ghidra-build RESULT_VARIABLE SCRIPT_RESULT COMMAND \${CMAKE_COMMAND} --build . --target install ) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to install r2ghidra plugin\") + message(FATAL_ERROR \"Failed to install rz-ghidra plugin\") endif() ") endif()