DEV Community

Euber Alexandre Barbosa
Euber Alexandre Barbosa

Posted on

Meson: Usando um projeto git sem meson.build como dependência

Eventualmente você vai achar um projeto bacana que não usa meson.build e o mantenedor demora anos para aceitar PR, se algum dia for.

Ou mesmo seu projeto está em contrato para sempre adicionar a LICENSE em todas as builds e o mantenedor se recusa.

Para resolver esse pepino você pode adicionar aos seus subprojects/*.wrap git patches.

Por exemplo, no meu projeto - onur - por ser uma pequena ferramenta CLI prefiro usar o ht do grande Hoyt ao invés do enorme GNOME glib, mas este projeto git não tem uma meson.build.

Uma simples wrap-git para esse projeto, que sequer tem tags também, seria usando o master:

./subprojects/ht.wrap

[wrap-git]
directory=ht
url=https://github.com/benhoyt/ht
revision=master
depth=1
Enter fullscreen mode Exit fullscreen mode

Primeiro vamos pegar todos subprojetos meson subprojects download, e adicionar a meson.build na raiz deste:

./subprojects/ht

cat <<EOF | tee -a ./subprojects/ht/meson.build
project('ht', 'c', version: '1.0')

ht_sources = [
    'ht.c',
    'ht.h',
]

ht_lib = static_library('ht', ht_sources)

ht_dep = declare_dependency(
    include_directories: include_directories('.'),
    link_with: ht_lib)
EOF

cat ./subprojects/ht/meson.build
Enter fullscreen mode Exit fullscreen mode

e criar o patch com:

mkdir -pv subprojects/{packagecache,packagefiles}
git -C ./subprojects/ht add meson.build
git -C ./subprojects/ht diff --cached > ./subprojects/packagefiles/ht-meson.patch
cat ./subprojects/packagefiles/ht-meson.patch
Enter fullscreen mode Exit fullscreen mode

uma vez com o patch devemos apontar sua presença ao ht.wrap:

echo "diff_files = ht-meson.patch" >> ./subprojects/ht.wrap
cat ./subprojects/ht.wrap
Enter fullscreen mode Exit fullscreen mode

Pronto, vamos aplicar o patch:

meson subprojects purge --confirm
meson subprojects download
Enter fullscreen mode Exit fullscreen mode

e compilar o projeto para confirmar:

CC=gcc meson setup ./build --wipe -D b_sanitize=none -D buildtype=release
meson compile -C ./build
Enter fullscreen mode Exit fullscreen mode

O executável vai aparecer em ./build como esperado.

Valeu!

Recomendação para leitura:

Informações gerais:

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The discussion has been locked. New comments can't be added.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay