diff --git a/meson.build b/meson.build new file mode 100644 index 00000000000..40c31f1d9ac --- /dev/null +++ b/meson.build @@ -0,0 +1,304 @@ +# +# Old configure.ac +# + +project( + 'nix', + 'cpp', + default_options : [ + 'cpp_std=c++14', + #'localstatedir=/nix/var', + ], +) + +sed = find_program('sed') + +conf_data = configuration_data() + +system = get_option('with-system') +if system == '' + system = host_machine.cpu() + '-' + host_machine.system() +endif +conf_data.set_quoted('SYSTEM', system, description : 'platform identifier (`cpu-os\')') + +# State should be stored in /nix/var, unless the user overrides it explicitly. +if get_option('normal-var') + nixstatedir = '/nix/var' +else + nixstatedir = get_option('localstatedir') +endif + +global_libs = [] +# Solaris-specific stuff. +if host_machine.cpu() == 'sunos' + global_libs += [ + dependency('socket'), + dependency('nsl'), + ] +endif + +# Use 64-bit file system calls so that we can support files > 2 GiB. + +# Note vs configure.ac: Meson always does large file support. + +# Check for pubsetbuf. +want_pubsetbuf = get_option('have-pubsetbuf') +if want_pubsetbuf.disabled() + have_pubsetbuf = false +else + have_pubsetbuf = meson.get_compiler('cpp').compiles( + ''' + #include + using namespace std; + static char buf[1024]; + void func() { + cerr.rdbuf()->pubsetbuf(buf, sizeof(buf)); + } + ''', + name : 'pubsetbuf' + ) + if want_pubsetbuf.enabled() and not have_pubsetbuf + error('you required the `pubsetbuf` function, but we do not have it.') + endif +endif +if have_pubsetbuf + conf_data.set('HAVE_PUBSETBUF', 1, description : 'Whether pubsetbuf is available.') +endif + +foreach f : [ + 'statvfs', + 'pipe2', + # Check for lutimes, optionally used for changing the mtime of symlinks. + 'lutimes', +] + if meson.get_compiler('cpp').has_function(f) + conf_data.set('HAVE_' + f.to_upper(), 1) + endif +endforeach + +# Check whether the store optimiser can optimise symlinks. +want_link_symlink = get_option('can-link-symlink') +if want_link_symlink.disabled() + can_link_symlink = true +else + link_text_script = ''' + ln -s bla tmp_link; + ln tmp_link tmp_link2 2> /dev/null; + rm -f tmp_link tmp_link2 + ''' + can_link_symlink = run_command('sh', '-c', link_text_script).returncode() == 0 + if want_link_symlink.enabled() and not can_link_symlink + error('you required that we hard link symlinks, but we cannot.') + endif +endif +if can_link_symlink + conf_data.set('CAN_LINK_SYMLINK', 1, description : 'Whether link() works on symlinks.') +endif + +# Check for . +meson.get_compiler('cpp').check_header('locale') + +foreach prog : [ + 'bash', + 'patch', + 'sed', + 'tar', + 'bzip2', + 'gzip', + 'xz', + 'cat', + 'tr', +] + find_program(prog) +endforeach + +false_ = find_program('false') +foreach prog : [ + 'xmllint', + 'xsltproc', + 'flex', + 'bison', +] + find_program(prog, required: false) +endforeach + +find_program('dot', required: false) +lsof = find_program('lsof', required: false) + +conf_data.set_quoted('coreutils', get_option('with-coreutils-bin')) +storedir = get_option('with-store-dir') + +# Special case +pthread = dependency('threads') + +# Look for OpenSSL, a required dependency. +openssl = [ + dependency('openssl'), + dependency('libcrypto'), +] + +# Look for libbz2, a required dependency. +bz2 = meson.get_compiler('cpp').find_library('bz2') + +# Look for SQLite, a required dependency. +sqlite3 = dependency('sqlite3', version : '>= 3.6.19') + +# Look for libcurl, a required dependency. +libcurl = dependency('libcurl') + +# Look for editline, a required dependency. +editline = dependency('libeditline') + +# Look for libsodium, an optional dependency. +libsodium = dependency('sodium', required : false) +if libsodium.found() + conf_data.set('HAVE_SODIUM', 1, description : 'Whether to use libsodium for cryptography.') +endif + +# Look for libbrotli{enc,dec}. +libbrotli = [ + dependency('libbrotlienc'), + dependency('libbrotlidec'), +] + +# Look for liblzma, a required dependency. +liblzma = dependency('liblzma') +if meson.get_compiler('cpp').has_function('lzma_stream_encoder_mt', dependencies : liblzma) + conf_data.set('HAVE_LSMA_MT', 1, description : 'xz multithreaded compression support') +endif + +# Look for libseccomp, required for Linux sandboxing. +want_seccomp = get_option('enable-seccomp-sandboxing') +if want_seccomp.disabled() or (want_seccomp.auto() and host_machine.system() != 'linux') + seccomp = dependency('', required : false) +else # enabled or auto on linux + seccomp = dependency('libseccomp') + if want_seccomp.enabled() and not seccomp.found() + error('you required `libseccomp`, but we do not have it.') + endif +endif +if seccomp.found() + conf_data.set('HAVE_SECCOMP', 1, description : 'Whether seccomp is available and should be used for sandboxing.') +endif + +# Look for aws-cpp-sdk-s3. +want_s3 = get_option('enable-s3') +if want_s3.disabled() + enable_s3 = false +else + enable_s3 = meson.get_compiler('cpp').check_header('aws/s3/S3Client.h') +endif +if enable_s3 + conf_data.set('ENABLE_S3', 1, description : 'Whether to enable S3 support via aws-sdk-cpp.') +endif + +if enable_s3 + aws_version = meson.get_compiler('cpp').get_define( + 'AWS_SDK_VERSION_STRING', + prefix : '#include ' + ).strip('"').split('.') + conf_data.set('AWS_VERSION_MAJOR', aws_version[0], description : 'Major version of aws-sdk-cpp.') + conf_data.set('AWS_VERSION_MINOR', aws_version[1], description : 'Minor version of aws-sdk-cpp.') +endif + +# Whether to use the Boehm garbage collector. +want_gc = get_option('enable-gc') +if want_gc.disabled() + bdw_gc = false +else + bdw_gc = dependency('bdw-gc', required : false) + if want_gc.enabled() and not bdw_gc.found() + error('you required garbage collection, but we do not have the library to support it.') + endif +endif +if libsodium.found() + conf_data.set('HAVE_BOEHMGC', 1, description : 'Whether to use the Boehm garbage collector.') +endif + +# documentation generation switch +conf_data.set('doc_generate', not get_option('disable-doc-gen')) + + +foreach f : [ + # Setuid installations. + 'setresuid', + 'setreuid', + 'lchown', + # Nice to have, but not essential. + 'strsignal', + 'posix_fallocate', + 'sysconf', +] + if meson.get_compiler('cpp').has_function(f) + conf_data.set('HAVE_' + f.to_upper(), 1) + endif +endforeach + +# This is needed if bzip2 is a static library, and the Nix libraries +# are dynamic. +if bz2.found() and host_machine.system() == 'darwin' + add_project_link_arguments('-all_load') +endif + +# Do we have GNU tar? +tar_script = ''' + if @t0@ --version 2> /dev/null | grep -q GNU && tar cvf /dev/null --warning=no-timestamp ./config.log > /dev/null +'''.format(find_program('tar').path()) +tar_flags = '' +if run_command('sh', '-c', link_text_script).returncode() == 0 + tar_flags += '--warning=no-timestamp' +endif +conf_data.set_quoted('tarFlags', tar_flags) + +sandbox_shell = get_option('with-sandbox-shell') + +# +# Extra Configure +# + +boost_context = dependency('boost', modules : ['context']) + +# Done by default by autoconf +conf_data.set_quoted('PACKAGE_VERSION', meson.project_version()) + +if enable_s3 + aws_cpp_sdk_transfer = meson.get_compiler('cpp').find_library('aws-cpp-sdk-transfer') + aws_cpp_sdk_s3 = meson.get_compiler('cpp').find_library('aws-cpp-sdk-s3') + aws_cpp_sdk_core = meson.get_compiler('cpp').find_library('aws-cpp-sdk-core') +else + aws_cpp_sdk_transfer = dependency('', required : false) + aws_cpp_sdk_s3 = dependency('', required : false) + aws_cpp_sdk_core = dependency('', required : false) +endif + +# +# original Configure.ac, but much go last +# + +configure_file( + output : 'config.h', + configuration : conf_data +) + +# +# Old Makefile +# + +global_subdirs = include_directories([ + '.', + 'src', + 'src/libutil', + 'src/libstore', + 'src/libmain', + 'src/libexpr', + 'src/nix', +]) + +add_project_arguments('-g', '-Wall', '-include', 'config.h', language : 'cpp') + +subdir('src/libutil') +subdir('src/libstore') +subdir('src/libmain') +subdir('src/libexpr') +subdir('src/nix') +subdir('src/resolve-system-dependencies') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000000..51c6d137187 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,68 @@ +# +# Original +# + +option( + 'with-system', + type : 'string', + description : ''' + The identifier for the type of machine this build of Nix will try to perform builds for. + Typically a two-component config like that produced by `uname`. + ''', +) +option( + 'normal-var', + type : 'boolean', + value : 'true', + description : 'Whether to use `/nix/var` or the user-overridable `localstatedir`.' +) + +option( + 'with-coreutils-bin', + type : 'string', + description : 'path of cat, mkdir, etc.' +) + +option( + 'with-store-dir', + type : 'string', + value : '/nix/store', + description : 'path of the Nix store (defaults to /nix/store)' +) + +option( + 'enable-seccomp-sandboxing', + type : 'feature', + description : ''' + Don't build support for seccomp sandboxing (only recommended if your arch doesn't support libseccomp yet! + ''', +) + +option( + 'enable-gc', + type : 'feature', + description : ''' + enable garbage collection in the Nix expression evaluator (requires Boehm GC) [default=no] + ''', +) + +option( + 'disable-doc-gen', + type : 'boolean', + value : false, + description : 'disable documentation generation', +) + +option( + 'with-sandbox-shell', + type : 'string', + description : 'path of a statically-linked shell to use as /bin/sh in sandboxes', +) + +# +# New for declarative config +# + +option('have-pubsetbuf', type : 'feature') +option('can-link-symlink', type : 'feature') +option('enable-s3', type : 'feature') diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build new file mode 100644 index 00000000000..74c6289505f --- /dev/null +++ b/src/libexpr/meson.build @@ -0,0 +1,51 @@ +flex = find_program('flex') +bison = find_program('bison') + +parser_tab_cchh = custom_target( + 'parser_tab.[cchh]', + output : ['parser-tab.cc', 'parser-tab.hh'], + input : 'parser.y', + command : [bison, '-v', '-o', '@OUTPUT0@', '@INPUT@', '-d'] +) + +lexer_tab_cchh = custom_target( + 'lexer_tab.[cchh]', + output : ['lexer-tab.cc', 'lexer-tab.hh'], + input : 'lexer.l', + command : [ + flex, + '--outfile', '@OUTPUT0@', + '--header-file=@OUTPUT1@', + '@INPUT@' + ] +) + +libexpr = library( + 'libnixexpr', + [ + 'attr-path.cc', + 'attr-set.cc', + 'common-eval-args.cc', + 'eval.cc', + 'get-drvs.cc', + 'json-to-value.cc', + 'names.cc', + 'nixexpr.cc', + 'primops.cc', + 'value-to-json.cc', + 'value-to-xml.cc', + + lexer_tab_cchh, + parser_tab_cchh, + ], + install : true, + include_directories : global_subdirs, + dependencies : [ + global_libs, + ], + link_with : [ + libstore, + libutil, + ], + link_args : host_machine.system() == 'freebsd' ? ['-ldl'] : [] +) diff --git a/src/libmain/meson.build b/src/libmain/meson.build new file mode 100644 index 00000000000..23ee0129274 --- /dev/null +++ b/src/libmain/meson.build @@ -0,0 +1,19 @@ +libmain = library( + 'libnixmain', + [ + 'common-args.cc', + 'shared.cc', + 'stack.cc', + ], + install : true, + include_directories : global_subdirs, + dependencies : [ + global_libs, + + openssl, + ], + link_with : [ + libstore, + libutil, + ], +) diff --git a/src/libstore/meson.build b/src/libstore/meson.build new file mode 100644 index 00000000000..4d9ceb05fc1 --- /dev/null +++ b/src/libstore/meson.build @@ -0,0 +1,87 @@ +# TODO fix `@OUTPUT@` substitution so we don't need to do this workaround +sql_header_script = ''' + echo 'R"foo(' >> "$1" + cat @INPUT@ >> "$1" + echo ')foo"' >> "$1" +''' + +sql_header = custom_target( + 'schema.sql.gen.hh', + output : 'schema.sql.gen.hh', + input : 'schema.sql', + command : ['sh', '-c', sql_header_script, 'sh', '@OUTPUT@'] +) + +libstore = library( + 'libnixstore', + [ + 'binary-cache-store.cc', + 'build.cc', + 'crypto.cc', + 'derivations.cc', + 'download.cc', + 'export-import.cc', + 'gc.cc', + 'globals.cc', + 'http-binary-cache-store.cc', + 'legacy-ssh-store.cc', + 'local-binary-cache-store.cc', + 'local-fs-store.cc', + 'local-store.cc', + 'machines.cc', + 'misc.cc', + 'nar-accessor.cc', + 'nar-info.cc', + 'nar-info-disk-cache.cc', + 'optimise-store.cc', + 'parsed-derivations.cc', + 'pathlocks.cc', + 'profiles.cc', + 'references.cc', + 'remote-fs-accessor.cc', + 'remote-store.cc', + 's3-binary-cache-store.cc', + 'sqlite.cc', + 'ssh.cc', + 'ssh-store.cc', + 'store-api.cc', + + 'builtins/buildenv.cc', + 'builtins/fetchurl.cc', + + sql_header, + ], + install : true, + include_directories : global_subdirs, + dependencies : [ + global_libs, + + sqlite3, + bz2, + libcurl, + libsodium, + pthread, + + aws_cpp_sdk_transfer, + aws_cpp_sdk_s3, + aws_cpp_sdk_core, + seccomp, + ], + link_with : [ + libutil, + ], + cpp_args : [ + '-DNIX_PREFIX="@0@"'.format(get_option('prefix')), + '-DNIX_STORE_DIR="@0@"'.format(storedir), + '-DNIX_DATA_DIR="@0@"'.format(get_option('datadir')), + '-DNIX_STATE_DIR="@0@/nix"'.format(nixstatedir), + '-DNIX_LOG_DIR="@0@/log/nix"'.format(nixstatedir), + '-DNIX_CONF_DIR="@0@/nix"'.format(get_option('sysconfdir')), + '-DNIX_LIBEXEC_DIR="@0@"'.format(get_option('libexecdir')), + '-DNIX_BIN_DIR="@0@"'.format(get_option('bindir')), + '-DNIX_MAN_DIR="@0@"'.format(get_option('mandir')), + '-DSANDBOX_SHELL="@0@"'.format(sandbox_shell), + '-DLSOF="@0@"'.format(lsof), + ], + link_args : host_machine.system() == 'freebsd' ? ['-ldl'] : [] +) diff --git a/src/libutil/meson.build b/src/libutil/meson.build new file mode 100644 index 00000000000..2ca0f13b987 --- /dev/null +++ b/src/libutil/meson.build @@ -0,0 +1,29 @@ +libutil = library( + 'libnixutil', + [ + 'affinity.cc', + 'archive.cc', + 'args.cc', + 'compression.cc', + 'config.cc', + 'hash.cc', + 'json.cc', + 'logging.cc', + 'serialise.cc', + 'thread-pool.cc', + 'util.cc', + 'xml-writer.cc', + ], + install : true, + include_directories : global_subdirs, + dependencies : [ + global_libs, + + liblzma, + bz2, + pthread, + openssl, + libbrotli, + boost_context, + ], +) diff --git a/src/nix/meson.build b/src/nix/meson.build new file mode 100644 index 00000000000..29aa4a8ee66 --- /dev/null +++ b/src/nix/meson.build @@ -0,0 +1,85 @@ +nix = executable( + 'nix', + [ + 'add-to-store.cc', + 'build.cc', + 'cat.cc', + 'command.cc', + 'copy.cc', + 'doctor.cc', + 'dump-path.cc', + 'edit.cc', + 'eval.cc', + 'hash.cc', + 'installables.cc', + 'legacy.cc', + 'log.cc', + 'ls.cc', + 'main.cc', + 'optimise-store.cc', + 'path-info.cc', + 'ping-store.cc', + 'progress-bar.cc', + 'repl.cc', + 'run.cc', + 'search.cc', + 'show-config.cc', + 'show-derivation.cc', + 'sigs.cc', + 'upgrade-nix.cc', + 'verify.cc', + 'why-depends.cc', + + '../build-remote/build-remote.cc', + + '../nix-build/nix-build.cc', + '../nix-channel/nix-channel.cc', + '../nix-collect-garbage/nix-collect-garbage.cc', + '../nix-copy-closure/nix-copy-closure.cc', + '../nix-daemon/nix-daemon.cc', + '../nix-env/nix-env.cc', + '../nix-env/user-env.cc', + '../nix-instantiate/nix-instantiate.cc', + '../nix-prefetch-url/nix-prefetch-url.cc', + '../nix-store/dotgraph.cc', + '../nix-store/graphml.cc', + '../nix-store/nix-store.cc', + ], + include_directories : global_subdirs, + dependencies : [ + global_libs, + + pthread, + libsodium, + editline, + ], + link_with : [ + libexpr, + libmain, + libstore, + libutil, + ], +) + +foreach name : [ + 'nix-build', + 'nix-channel', + 'nix-collect-garbage', + 'nix-copy-closure', + 'nix-daemon', + 'nix-env', + 'nix-hash', + 'nix-instantiate', + 'nix-prefetch-url', + 'nix-shell', + 'nix-store', +] + custom_target( + name, + output : name, + input : nix, + command : ['ln', '-s', '@INPUT@', '@OUTPUT@'], + install : true, + install_dir : get_option('bindir') + ) +endforeach diff --git a/src/resolve-system-dependencies/meson.build b/src/resolve-system-dependencies/meson.build new file mode 100644 index 00000000000..a64073fcc01 --- /dev/null +++ b/src/resolve-system-dependencies/meson.build @@ -0,0 +1,10 @@ +if host_machine.system() == 'darwin' + executable( + 'resolve-system-dependencies', + [ + 'resolve-system-dependencies.cc' + ], + install : true, + install_dir : get_option('libexecdir'), + ) +endif