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:

Agent.ai Challenge image

Congrats to the Agent.ai Challenge Winners 🏆

The wait is over! We are excited to announce the winners of the Agent.ai Challenge.

From meal planners to fundraising automators to comprehensive stock analysts, our team of judges hung out with a lot of agents and had a lot to deliberate over. There were so many creative and innovative submissions, it is always so difficult to select our winners.

Read more →

Top comments (0)

The discussion has been locked. New comments can't be added.
👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay