From 70024929af52422877b1f5c63c212460b47d3a47 Mon Sep 17 00:00:00 2001 From: wargio Date: Sat, 24 Feb 2024 23:55:19 +0800 Subject: [PATCH] Build cutter native jsdec --- dist/CMakeLists.txt | 11 +++++++++-- dist/bundle_jsdec.ps1 | 24 +++++++++++++++++------- scripts/jsdec.sh | 16 ++++++++++------ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt index 2fe5b671..489bf8f1 100644 --- a/dist/CMakeLists.txt +++ b/dist/CMakeLists.txt @@ -24,7 +24,9 @@ if(WIN32) 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_jsdec.ps1\" \"\${CMAKE_INSTALL_PREFIX}\" + execute_process(COMMAND powershell \"${CMAKE_CURRENT_SOURCE_DIR}/bundle_jsdec.ps1\" + \"\${CMAKE_INSTALL_PREFIX}\" + \"-DCUTTER_INSTALL_PLUGDIR=plugins/native\" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) @@ -124,9 +126,14 @@ endif() if(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS AND (NOT WIN32)) if (CUTTER_PACKAGE_JSDEC) + if(APPLE) + set (JSDEC_PLUGIN_OPTIONS "-DCUTTER_INSTALL_PLUGDIR=plugins/native") + else() + set (JSDEC_PLUGIN_OPTIONS "") + endif() install(CODE " execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/jsdec.sh\" - --pkg-config-path=\${CMAKE_INSTALL_PREFIX}/lib/pkgconfig --prefix=\${CMAKE_INSTALL_PREFIX} + \"\${CMAKE_INSTALL_PREFIX}\" \"${JSDEC_PLUGIN_OPTIONS}\" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) diff --git a/dist/bundle_jsdec.ps1 b/dist/bundle_jsdec.ps1 index 64466a7c..df7328be 100644 --- a/dist/bundle_jsdec.ps1 +++ b/dist/bundle_jsdec.ps1 @@ -2,16 +2,26 @@ $dist = $args[0] $python = Split-Path((Get-Command python.exe).Path) if (-not (Test-Path -Path 'jsdec' -PathType Container)) { - git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch "v0.7.0" + git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch "dev" } cd jsdec -& meson.exe --buildtype=release --prefix="$dist" build -ninja -C build install +$jsdecdir = (Get-Item .).FullName + +& meson.exe setup --buildtype=release -Dbuild_type=cutter "$jsdecdir\build_lib" +ninja -C "$jsdecdir\build_lib" + +# cmake is silly and expects .lib but meson generates the static lib as .a +Copy-Item "$jsdecdir\build_lib\libjsdec.a" -Destination "$jsdecdir\build_lib\jsdec.lib" + +mkdir build_plugin +cd build_plugin +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DJSDEC_BUILD_DIR="$jsdecdir\build_lib" -DCMAKE_INSTALL_PREFIX="$dist" $cmake_opts "$jsdecdir\cutter-plugin" +ninja install + $ErrorActionPreference = 'Stop' -$pathdll = "$dist\lib\rizin\plugins\core_pdd.dll" +$pathdll = "$dist\share\rizin\cutter\plugins\native\jsdec_cutter.dll" if(![System.IO.File]::Exists($pathdll)) { - type build\meson-logs\meson-log.txt - ls "$dist\lib\rizin\plugins\" + echo "files: $dist\share\rizin\cutter\plugins\native\" + ls "$dist\share\rizin\cutter\plugins\native\" throw (New-Object System.IO.FileNotFoundException("File not found: $pathdll", $pathdll)) } -Remove-Item -Recurse -Force "$dist\lib\rizin\plugins\core_pdd.lib" diff --git a/scripts/jsdec.sh b/scripts/jsdec.sh index c084133c..ed81a112 100755 --- a/scripts/jsdec.sh +++ b/scripts/jsdec.sh @@ -1,20 +1,24 @@ #!/bin/bash set -e +INSTALL_PREFIX="$1" +EXTRA_CMAKE_OPTS="$2" SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") cd "$SCRIPTPATH/.." if [ ! -d jsdec ]; then - git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch "v0.7.0" + git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch "dev" fi cd jsdec -if [ -d build ]; then - rm -rf build +if [ -d build_lib ]; then + rm -rf build_lib fi -meson --buildtype=release "$@" build -ninja -C build -ninja -C build install +meson setup --buildtype=release --pkg-config-path="$INSTALL_PREFIX/lib/pkgconfig" -Dbuild_type=cutter build_lib +ninja -C build_lib +mkdir build_plugin && cd build_plugin +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DJSDEC_BUILD_DIR="../build_lib" -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $EXTRA_CMAKE_OPTS ../cutter-plugin +ninja install