Meson パッケージガイドライン

提供: ArchWiki
2022年2月17日 (木) 18:20時点におけるKgx (トーク | 投稿記録)による版 (→‎Using meson binary directly: 翻訳)
ナビゲーションに移動 検索に移動

Meson 公式サイトより。

Meson はオープンソースのビルドシステムで、非常に高速で、さらに重要なことに、可能な限りユーザーフレンドリーであることを意図しています。

Python で書かれた Meson は、マルチプラットフォームのサポート、複数のプログラミング言語のサポート、クロスコンパイルなどを特徴としています。

Meson はソフトウェアを直接ビルドするのではなく、バックエンドのビルドシステムをセットアップします。一般的には ninja と共に使われますが、他のビルドシステムを使うこともできます。一般的には、GNU ビルドシステム を置き換えるために使われます。

このドキュメントは Meson を使うソフトウェアのための PKGBUILD を書くための標準ガイドラインを扱っています。

Usage

必要条件

mesonPKGBUILDmakedepends の配列に含まれなければなりません。

build()

設定とビルドは通常 meson バイナリを使う ですが、Arch Linux arch-meson ラッパースクリプトを使う ことによっても行うことができます。

mesonarch-meson コマンドはどちらも optionssource directorybuild directory を使用法のシンタックスに含んでいます。

  • オプション:少なくとも --prefix /usr を含める必要がありますが、その他のオプションは meson configure --help で確認してください。また ソフトウェア固有の構築オプション も確認してください。
  • ソースディレクトリ (または "sourcedir"): ソフトウェアのソースコードが格納されている場所です。例えば ., $pkgname または $pkgname-$pkgver などです。
  • 一般的には build または _build という名前ですが、任意で指定できます。
ノート: ソースディレクトリがビルドディレクトリの前に meson に渡される場合と、その逆の場合がありますが、Meson はどちらがどちらかを知っていて適切に環境をセットアップするので問題ありません。

meson バイナリを直接使用する場合

Arch Linux のパッケージはファイルを /usr/local にインストールしてはいけないため、--prefix=/usr は常に meson のバイナリに渡す必要があります、これは Arch パッケージガイドライン#パッケージエチケット に従っています。--buildtype=plain 組み込みのオプションは、あなたが何をしているかを知っていれば、他の値を設定することができます。

Using arch-meson wrapper script

arch-meson is a wrapper script included in meson package which has the advantage of setting some of Meson built-in options that would probably be used in an Arch package, saving packager's time and code in the PKGBUILD. Quoting the description written in arch-meson, it is a "Highly opinionated wrapper for Arch Linux packaging".

Example:

build() {
  arch-meson source build
  meson compile -C build
}

Setting software-specific build options

While Meson has some built-in build options (e.g. --prefix), the software being packaged could have other build options which the packager should consider. Valid software-specific build options are normally found in a file named meson_options.txt (if present) and in meson.build. Look for option(settings) in these files, then read the settings.

To use a software-specific build option, use the notation -D key=value, where key is the build option name set in the project and value is a valid value, like e.g. true.

For instance, gtranslator has the following build options:

meson_options.txt
option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')

So, to build its documentation, one must run Meson appending -D gtk_doc=true build option, resulting in a command line like e.g.

arch-meson $pkgname-$pkgver build -Dgtk_doc=true

check()

If the software being packaged provides test suite, consider running it in the PKGBUILD's check() function. This can be accomplished with meson test command.

Example:

check() {
  meson test -C build
}

where build is the same build directory name used in the above #build() step.

ヒント:
  • ninja test -C build could be directly used instead.
  • The --print-errorlogs parameter can be added to meson test in order to report the output produced by the failing tests along with other useful information as the environmental variables.

See meson test --help and Unit tests in Meson docs for more info.

package()

Packaging normally requires running only meson install, but check if another installation command is required (e.g. an uncommon license). Use the same build directory as above and set the --destdir flag:

package() {
  meson install -C build --destdir "$pkgdir"
}
ノート: Appending DESTDIR="$pkgdir" is also a valid alternative to --destdir.[1]
ヒント: ninja install -C build could be directly used instead.

Template

To sum up the above instructions and to provide a single copy-and-paste point, see the template below:

makedepends=(meson)

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build
}

package() {
  meson install -C build --destdir "$pkgdir"
}

Example packages

This is a small list of packages that use Meson. See other packages in the list "Required by" in meson.

See also