From de6abe347a682b6d8ccebf95ebb97e5b4fabb09c Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 13 May 2026 15:56:34 +0200 Subject: [PATCH] Add meson build --- .github/workflows/ci.yml | 29 +++++++++++++++ .gitignore | 3 +- README.md | 11 ++++++ meson.build | 76 ++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 13 +++++++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 meson.build create mode 100644 meson_options.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e83801..fa28c2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,35 @@ jobs: - name: Build plugin run: make plugin + meson: + name: Meson (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Install Meson + run: | + python3 -m pip install --user meson ninja + echo "$(python3 -m site --user-base)/bin" >> "$GITHUB_PATH" + + - name: Install radare2 + id: r2 + uses: radareorg/github-actions@v1 + + - name: Configure + run: meson setup build + + - name: Build + run: meson compile -C build + + - name: Test + run: meson test -C build --print-errorlogs + debian: name: Build Debian package runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index bbd1eff..a71a6c8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ # Build artifacts *.o /r2unity +/build/ +/builddir/ /src/r2/*.dylib /src/r2/*.so /src/r2/*.dll @@ -19,4 +21,3 @@ # Third-party reference checkouts (radare2, il2cpp dumper, etc.) /third_party/ - diff --git a/README.md b/README.md index 936b692..1b5647f 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,14 @@ make plugin make user-install ``` +Or with Meson: + +```sh +meson setup build +meson compile -C build +meson install -C build +``` + Most users can install it through r2pm: ```sh @@ -40,6 +48,9 @@ r2pm -ci r2unity `make` builds the CLI. `make plugin` builds `core_r2unity` and `bin_r2unity`. `make user-install` installs both the CLI and plugins for the current user. +Meson builds the CLI by default, matching `make`. Use `-Dplugins=enabled` to +build the radare2 plugins too, or `-Dr2_plugindir=/path/to/plugins` to override +the plugin install directory. ## CLI diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..1bc6950 --- /dev/null +++ b/meson.build @@ -0,0 +1,76 @@ +project( + 'r2unity', + 'c', + version: '0.0.0', + default_options: [ + 'c_std=c99', + 'warning_level=2', + 'buildtype=debugoptimized', + ], +) + +r_util_dep = dependency('r_util') + +lib_inc = include_directories('src/lib') +lib_sources = files( + 'src/lib/elf.c', + 'src/lib/lib.c', + 'src/lib/macho.c', + 'src/lib/paths.c', + 'src/lib/pe.c', +) + +r2unity = executable( + 'r2unity', + files('src/main.c') + lib_sources, + include_directories: lib_inc, + dependencies: r_util_dep, + install: true, +) + +test('r2unity-help', r2unity, args: ['-h']) + +plugins_opt = get_option('plugins') +r_core_dep = dependency('r_core', required: plugins_opt) +r_bin_dep = dependency('r_bin', required: plugins_opt) +build_plugins = plugins_opt.enabled() or ( + plugins_opt.auto() and r_core_dep.found() and r_bin_dep.found() +) + +if build_plugins + r2_plugindir = get_option('r2_plugindir') + if r2_plugindir == '' + r2 = find_program('r2', required: false) + if r2.found() + r2_user_plugins = run_command(r2, '-H', 'R2_USER_PLUGINS', check: false) + if r2_user_plugins.returncode() == 0 + r2_plugindir = r2_user_plugins.stdout().strip() + endif + endif + endif + + if r2_plugindir == '' + r2_plugindir = join_paths(get_option('libdir'), 'radare2', 'plugins') + warning('r2 was not found; installing plugins under ' + r2_plugindir) + endif + + shared_library( + 'core_r2unity', + files('src/r2/core_r2unity.c') + lib_sources, + include_directories: lib_inc, + dependencies: r_core_dep, + name_prefix: '', + install: true, + install_dir: r2_plugindir, + ) + + shared_library( + 'bin_r2unity', + files('src/r2/bin_r2unity.c') + lib_sources, + include_directories: lib_inc, + dependencies: r_bin_dep, + name_prefix: '', + install: true, + install_dir: r2_plugindir, + ) +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..f3b37d2 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,13 @@ +option( + 'plugins', + type: 'feature', + value: 'disabled', + description: 'Build the radare2 core and bin plugins', +) + +option( + 'r2_plugindir', + type: 'string', + value: '', + description: 'Plugin install directory; when empty, Meson uses `r2 -H R2_USER_PLUGINS` if available', +)