forked from containers/bubblewrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 containers#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>
- Loading branch information
1 parent
9d7d985
commit 28f5dfc
Showing
14 changed files
with
408 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
bash_completion_dir = get_option('bash_completion_dir') | ||
|
||
if bash_completion_dir == '' | ||
bash_completion = dependency( | ||
'bash-completion', | ||
version : '>=2.0', | ||
required : false, | ||
) | ||
|
||
if bash_completion.found() | ||
if meson.version().version_compare('>=0.51.0') | ||
bash_completion_dir = bash_completion.get_variable( | ||
default_value: '', | ||
pkgconfig: 'completionsdir', | ||
pkgconfig_define: [ | ||
'prefix', get_option('prefix'), | ||
'datadir', get_option('prefix') / get_option('datadir'), | ||
], | ||
) | ||
else | ||
bash_completion_dir = bash_completion.get_pkgconfig_variable( | ||
'completionsdir', | ||
default: '', | ||
define_variable: [ | ||
'prefix', get_option('prefix'), | ||
'datadir', get_option('prefix') / get_option('datadir'), | ||
], | ||
) | ||
endif | ||
endif | ||
endif | ||
|
||
if bash_completion_dir == '' | ||
bash_completion_dir = get_option('datadir') / 'bash-completion' / 'completions' | ||
endif | ||
|
||
install_data('bwrap', install_dir : bash_completion_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if get_option('bash_completion').enabled() | ||
subdir('bash') | ||
endif | ||
|
||
if get_option('zsh_completion').enabled() | ||
subdir('zsh') | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
zsh_completion_dir = get_option('zsh_completion_dir') | ||
|
||
if zsh_completion_dir == '' | ||
zsh_completion_dir = get_option('datadir') / 'zsh' / 'site-functions' | ||
endif | ||
|
||
install_data('_bwrap', install_dir : zsh_completion_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
option( | ||
'bash_completion', | ||
type : 'feature', | ||
description : 'install bash completion script', | ||
value : 'enabled', | ||
) | ||
option( | ||
'bash_completion_dir', | ||
type : 'string', | ||
description : 'install bash completion script in this directory', | ||
value : '', | ||
) | ||
option( | ||
'man', | ||
type : 'feature', | ||
description : 'generate man pages', | ||
value : 'auto', | ||
) | ||
option( | ||
'program_prefix', | ||
type : 'string', | ||
description : 'Prepend string to bwrap executable name, for use with subprojects', | ||
) | ||
option( | ||
'require_userns', | ||
type : 'boolean', | ||
description : 'require user namespaces by default when installed setuid', | ||
value : 'false', | ||
) | ||
option( | ||
'selinux', | ||
type : 'feature', | ||
description : 'enable optional SELINUX support', | ||
value : 'auto', | ||
) | ||
option( | ||
'zsh_completion', | ||
type : 'feature', | ||
description : 'install zsh completion script', | ||
value : 'enabled', | ||
) | ||
option( | ||
'zsh_completion_dir', | ||
type : 'string', | ||
description : 'install zsh completion script in this directory', | ||
value : '', | ||
) |
Oops, something went wrong.