summaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-05-05 12:16:20 +0100
committerSimon McVittie <smcv@collabora.com>2022-02-18 10:42:55 +0000
commit19279812409265b2bb86edf465d47c529ed9226d (patch)
tree18c076e6f65c553e5aafe15c138de545124da0e9 /meson.build
parent43c2d32d7f03ce502c248ff6575c1ce5e205ecd5 (diff)
downloadbubblewrap-19279812409265b2bb86edf465d47c529ed9226d.tar.gz
Add a Meson build system
This allows bwrap to be built as a subproject in larger Meson projects. When built as a subproject, we install into the --libexecdir and require a program prefix to be specified: for example, Flatpak would use program_prefix=flatpak- to get /usr/libexec/flatpak-bwrap. Verified to be backwards-compatible as far as Meson 0.49.0 (Debian 9 backports). Loosely based on previous work by Jussi Pakkanen (see #133). Differences between the Autotools and Meson builds: The Meson build requires a version of libcap that has pkg-config metadata (introduced in libcap 2.23, in 2013). The Meson build has no equivalent of --with-priv-mode=setuid. On distributions like Debian <= 10 and RHEL <= 7 that require a setuid bwrap executable, the sysadmin or distribution packaging will need to set the correct permissions on the bwrap executable; Debian already did this via packaging rather than the upstream build system. The Meson build supports being used as a subproject, and there is CI for this. It automatically disables shell completions and man pages, moves the bubblewrap executable to ${libexecdir}, and renames the bubblewrap executable according to a program_prefix option that the caller must specify (for example, Flatpak would use -Dprogram_prefix=flatpak- to get /usr/libexec/flatpak-bwrap). See the tests/use-as-subproject/ directory for an example. Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build147
1 files changed, 147 insertions, 0 deletions
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..159ab2b
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,147 @@
+project(
+ 'bubblewrap',
+ 'c',
+ version : '0.5.0',
+ meson_version : '>=0.49.0',
+ default_options : [
+ 'warning_level=2',
+ ],
+)
+
+cc = meson.get_compiler('c')
+add_project_arguments('-D_GNU_SOURCE', language : 'c')
+
+# Keep this in sync with ostree, except remove -Wall (part of Meson
+# warning_level 2) and -Werror=declaration-after-statement
+add_project_arguments(
+ cc.get_supported_arguments([
+ '-Werror=shadow',
+ '-Werror=empty-body',
+ '-Werror=strict-prototypes',
+ '-Werror=missing-prototypes',
+ '-Werror=implicit-function-declaration',
+ '-Werror=pointer-arith',
+ '-Werror=init-self',
+ '-Werror=missing-declarations',
+ '-Werror=return-type',
+ '-Werror=overflow',
+ '-Werror=int-conversion',
+ '-Werror=parenthesis',
+ '-Werror=incompatible-pointer-types',
+ '-Werror=misleading-indentation',
+ '-Werror=missing-include-dirs',
+ '-Werror=aggregate-return',
+
+ # Extra warnings specific to bubblewrap
+ '-Werror=switch-default',
+ '-Wswitch-enum',
+
+ # Meson warning_level=2 would do this, but we are not fully
+ # signedness-safe yet
+ '-Wno-sign-compare',
+ '-Wno-error=sign-compare',
+
+ # Deliberately not warning about these, ability to zero-initialize
+ # a struct is a feature
+ '-Wno-missing-field-initializers',
+ '-Wno-error=missing-field-initializers',
+ ]),
+ language : 'c',
+)
+
+if (
+ cc.has_argument('-Werror=format=2')
+ and cc.has_argument('-Werror=format-security')
+ and cc.has_argument('-Werror=format-nonliteral')
+)
+ add_project_arguments([
+ '-Werror=format=2',
+ '-Werror=format-security',
+ '-Werror=format-nonliteral',
+ ], language : 'c')
+endif
+
+sh = find_program('sh', required : true)
+bash = find_program('bash', required : false)
+
+libcap_dep = dependency('libcap', required : true)
+
+selinux_dep = dependency(
+ 'libselinux',
+ version : '>=2.1.9',
+ # if disabled, Meson will behave as though libselinux was not found
+ required : get_option('selinux'),
+)
+
+cdata = configuration_data()
+cdata.set_quoted(
+ 'PACKAGE_STRING',
+ '@0@ @1@'.format(meson.project_name(), meson.project_version()),
+)
+
+if selinux_dep.found()
+ cdata.set('HAVE_SELINUX', 1)
+ if selinux_dep.version().version_compare('>=2.3')
+ cdata.set('HAVE_SELINUX_2_3', 1)
+ endif
+endif
+
+if get_option('require_userns')
+ cdata.set('ENABLE_REQUIRE_USERNS', 1)
+endif
+
+configure_file(
+ output : 'config.h',
+ configuration : cdata,
+)
+
+if meson.is_subproject()
+ bwrapdir = get_option('libexecdir')
+
+ if get_option('program_prefix') == ''
+ error('program_prefix option must be set when bwrap is a subproject')
+ endif
+else
+ bwrapdir = get_option('bindir')
+endif
+
+bwrap = executable(
+ get_option('program_prefix') + 'bwrap',
+ [
+ 'bubblewrap.c',
+ 'bind-mount.c',
+ 'network.c',
+ 'utils.c',
+ ],
+ install : true,
+ install_dir : bwrapdir,
+ dependencies : [selinux_dep, libcap_dep],
+)
+
+xsltproc = find_program('xsltproc', required : get_option('man'))
+
+if xsltproc.found() and not meson.is_subproject()
+ custom_target(
+ 'bwrap.1',
+ output : 'bwrap.1',
+ input : 'bwrap.xml',
+ command : [
+ xsltproc,
+ '--nonet',
+ '--stringparam', 'man.output.quietly', '1',
+ '--stringparam', 'funcsynopsis.style', 'ansi',
+ '--stringparam', 'man.th.extra1.suppress', '1',
+ '--stringparam', 'man.authors.section.enabled', '0',
+ '--stringparam', 'man.copyright.section.enabled', '0',
+ '-o', '@OUTPUT@',
+ 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
+ '@INPUT@',
+ ],
+ install : true,
+ install_dir : get_option('mandir') / 'man1',
+ )
+endif
+
+if not meson.is_subproject()
+ subdir('completions')
+endif