Skip to content

Commit

Permalink
Build cutter native jsdec
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Feb 25, 2024
1 parent 2106551 commit 7002492
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
11 changes: 9 additions & 2 deletions dist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 17 additions & 7 deletions dist/bundle_jsdec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 10 additions & 6 deletions scripts/jsdec.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7002492

Please sign in to comment.