From 111db8b38fd8350d92d72fa17fd3d9e8ef5a0e09 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Thu, 18 Apr 2024 16:15:24 -0600 Subject: meson: correctly embed sandbox shell when asked Change-Id: I2f6c0d42245204a516d2e424eea26a6391e975ad --- meson.build | 10 ++++++++++ meson.options | 4 ++-- package.nix | 1 + src/libstore/meson.build | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 0c0bfb8f0..2128ec6e2 100644 --- a/meson.build +++ b/meson.build @@ -284,6 +284,16 @@ endif # Used to workaround https://github.com/mesonbuild/meson/issues/2320 in src/nix/meson.build. installcmd = find_program('install') +enable_embedded_sandbox_shell = get_option('enable-embedded-sandbox-shell') +if enable_embedded_sandbox_shell + # This one goes in config.h + # The path to busybox is passed as a -D flag when compiling libstore. + # Idk why, ask the old buildsystem. + configdata += { + 'HAVE_EMBEDDED_SANDBOX_SHELL': 1, + } +endif + sandbox_shell = get_option('sandbox-shell') # Consider it required if we're on Linux and the user explicitly specified a non-default value. sandbox_shell_required = sandbox_shell != 'busybox' and host_machine.system() == 'linux' diff --git a/meson.options b/meson.options index 48ac63bc7..6b13fa8a0 100644 --- a/meson.options +++ b/meson.options @@ -7,8 +7,8 @@ option('enable-build', type : 'boolean', value : true, option('gc', type : 'feature', description : 'enable garbage collection in the Nix expression evaluator (requires Boehm GC)', ) -# TODO(Qyriad): is this feature maintained? -option('embedded-sandbox-shell', type : 'feature', + +option('enable-embedded-sandbox-shell', type : 'boolean', value : false, description : 'include the sandbox shell in the Nix binary', ) diff --git a/package.nix b/package.nix index aab98c0ae..9a2e08038 100644 --- a/package.nix +++ b/package.nix @@ -182,6 +182,7 @@ stdenv.mkDerivation (finalAttrs: { lib.optionals (buildWithMeson && stdenv.hostPlatform.isLinux) [ "-Dsandbox-shell=${lib.getBin busybox-sandbox-shell}/bin/busybox" ] + ++ lib.optional stdenv.hostPlatform.isStatic "-Denable-embedded-sandbox-shell=true" ++ lib.optional (finalAttrs.dontBuild) "-Denable-build=false" # mesonConfigurePhase automatically passes -Dauto_features=enabled, # so we must explicitly enable or disable features that we are not passing diff --git a/src/libstore/meson.build b/src/libstore/meson.build index fbf818825..e1c6c267a 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -10,6 +10,24 @@ foreach header : [ 'schema.sql', 'ca-specific-schema.sql' ] ) endforeach +if enable_embedded_sandbox_shell + hexdump = find_program('hexdump', required : true) + embedded_sandbox_shell_gen = custom_target( + 'embedded-sandbox-shell.gen.hh', + command : [ + hexdump, + '-v', + '-e', + '1/1 "0x%x," "\n"' + ], + input : busybox.full_path(), + output : 'embedded-sandbox-shell.gen.hh', + capture : true, + feed : true, + ) + libstore_generated_headers += embedded_sandbox_shell_gen +endif + libstore_sources = files( 'binary-cache-store.cc', 'build-result.cc', -- cgit v1.2.3