radareorg / r2ghidra

Native Ghidra Decompiler for r2
https://www.radare.org/
GNU Lesser General Public License v3.0
340 stars 43 forks source link

meson build system does not install any files for distro packaging #93

Closed anthraxx closed 2 years ago

anthraxx commented 2 years ago

It seems that the meson build system is lacking some instructions. Its not installing a single file:

Expected files:

==> Starting package()...
ninja: Entering directory `build'
[0/1] /usr/bin/meson install --no-rebuild
Nothing to install.

its called like this:

meson setup   --prefix        /usr \
  --libexecdir    lib \
  --sbindir       bin \
  --buildtype     plain \
  --auto-features enabled \
  --wrap-mode     nodownload \
  -D              b_lto=true \
  -D              b_pie=true \
  build
ninja -C build --verbose
DESTDIR="${pkgdir}" ninja --verbose -C build install

Expected installed files:

${pkgdir}/usr/
${pkgdir}/usr/lib/
${pkgdir}/usr/lib/radare2/
${pkgdir}/usr/lib/radare2/5.6.6/
${pkgdir}/usr/lib/radare2/5.6.6/anal_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/asm_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/core_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.cspec
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.ldefs
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.pspec
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.sla
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/...
trufae commented 2 years ago

Fixed in b827e93c7c266306793d0cee1773e62ad3a2aa9f

trufae commented 2 years ago

the sleigh files are shipped in a separate zip in the release page. you can build them, but only with make for now

anthraxx commented 2 years ago

@trufae great thanks. Do you have any pointer how one could build/distribute sleigh files themselves? Its important for us to be able to build them ourselves.

I think right now I figured it like this:

make -C ghidra sleigh-build
export R2_LIBR_PLUGINS=$(r2 -H R2_LIBR_PLUGINS)
DESTDIR="${pkgdir}" make -C ghidra install
trufae commented 2 years ago

yep. thats how you build it if you think it's worth to have the instructions in the readme they can be added. it will be good to be able to build it with meson too, but i dont see it as a prioriy right now

anthraxx commented 2 years ago

@trufae Sounds good enough for now, thank you! Compared the results to the provided zip and they seem to match. Good enough for now. If its ever moved over to meson please make us somehow aware :D

trufae commented 2 years ago

Yeah the sleigh files are portable. You can generate them once and use them on different systems. The zip in the release page is generated by the ci.

i'll open a ticket to make that part meson friendly when i get bored :)

btw i have a patch installing the sleighc compiler, not sure if you want to package this bonary too. Or maybe in a separate package because that may allow users to build their own custom processors

anthraxx commented 2 years ago

@trufae nice, good to hear. I've done some first meson adjustments for iaito but wanted to check in on some translations related topics. Can i reach you somewhere or should we discuss that on a bug ticket at iaito?

trufae commented 2 years ago

Sure, use mail, telegram or discord

milahu commented 1 year ago

workaround for meson in https://github.com/NixOS/nixpkgs/pull/213388 using xargs to run sleighc in parallel (using a sparse checkout of ghidra, 6 of 240 MB)

{
  # workround for https://github.com/radareorg/r2ghidra/issues/93
  # https://github.com/radareorg/r2ghidra/blob/master/ghidra/Makefile
  postBuild = ''
    GHIDRA_SLEIGH_HOME=../ghidra/src/Processors
    cp -v ../ghidra-processors.txt.default ../ghidra-processors.txt
    echo "Compiling processor files"
    ./sleighc -a $GHIDRA_SLEIGH_HOME/DATA
    cat ../ghidra-processors.txt | sed "s|^|$GHIDRA_SLEIGH_HOME/|" | xargs -n1 -P$NIX_BUILD_CORES ./sleighc -a 2>/dev/null
  '';

  # TODO use radare2.abiVersion https://github.com/radareorg/radare2/pull/20545
  postInstall = ''
    echo "Installing processor files to $out/lib/radare2/${radare2.version}/r2ghidra_sleigh"
    mkdir $out/lib/radare2/${radare2.version}/r2ghidra_sleigh
    for a in DATA $(cat ../ghidra-processors.txt); do
      for b in $GHIDRA_SLEIGH_HOME/$a/*/*/*.{cspec,ldefs,pspec,sla}; do
        cp $b $out/lib/radare2/${radare2.version}/r2ghidra_sleigh
      done
    done
  '';

for reference ...

https://mesonbuild.com/Custom-build-targets.html

https://github.com/radareorg/r2ghidra/blob/0799403b8ae3c2a09a176f1312825619912185e3/ghidra/Makefile#L1-L14

https://github.com/radareorg/r2ghidra/blob/a1495c523a315a6adf475fe58a6ca8125f36e7e6/ghidra/deps.mk#L111-L131

https://github.com/radareorg/r2ghidra/blob/0799403b8ae3c2a09a176f1312825619912185e3/Makefile#L22-L23