project( 'ahfail', ['c', 'rust'], version: '0.10.0', meson_version: '>=1.3.0', default_options: ['warning_level=3', 'c_std=c11'] ) ahfail_inc = include_directories('include') cc = meson.get_compiler('c') m_dep = cc.find_library('m', required : false) gtk_dep = dependency('gtk+-3.0') gstplayer_dep = dependency('gstreamer-player-1.0') gnome = import('gnome') resources = gnome.compile_resources( 'ahfail-resources', 'assets/ahfail.gresource.xml', source_dir: 'assets', c_name: 'ahfail' ) # All Rust artefacts come from ONE cargo invocation with one target directory. # Four separate builds with four target directories compiled the whole GTK and # GStreamer binding stack four times over (about an hour for a package build). # # -Dupdate_check=false (distro packages) builds without the ahfail-ui feature # `update-check`, so the binaries never ask Gitea for new releases and the HTTP # client is not compiled in at all. cargo_features = get_option('update_check') ? '' : '--no-default-features' # The ahfail command is the Linux locker (Wayland/X11 + its own PAM service). # macOS keeps the PAM hook and is built without it until it has been tested there. is_linux = host_machine.system() == 'linux' cargo_pkgs = '-p ahfail-gtklock -p ahfail-pam -p ahfail-display' + (is_linux ? ' -p ahfail' : '') cargo_outputs = ['libahfail_module.a', 'libahfail_pam.so', 'ahfail-display'] + (is_linux ? ['ahfail'] : []) cargo_install_dirs = [false, get_option('libdir') / 'ahfail', get_option('libdir') / 'ahfail'] + (is_linux ? [get_option('bindir')] : []) cargo_copy = (' && cp "@OUTDIR@/target/release/libahfail_module.a" "@OUTPUT0@"' + ' && cp "@OUTDIR@/target/release/libahfail_pam.so" "@OUTPUT1@"' + ' && cp "@OUTDIR@/target/release/ahfail-display" "@OUTPUT2@"' + (is_linux ? ' && cp "@OUTDIR@/target/release/ahfail" "@OUTPUT3@"' : '')) cargo_all = custom_target( 'ahfail-cargo-build', input: ['Cargo.toml', 'Cargo.lock'], output: cargo_outputs, command: [ 'sh', '-c', # The PAM module's build.rs needs the absolute libdir to know where # ahfail-display is installed; get_option('libdir') alone is relative. 'AHFAIL_LIBDIR=' + get_option('prefix') / get_option('libdir') + ' cargo build --release --locked' + ' ' + cargo_pkgs + ' ' + cargo_features + ' --target-dir "@OUTDIR@/target"' + cargo_copy ], build_by_default: true, build_always_stale: true, # cargo decides what is out of date, not meson install: true, # module archive: linked below, not installed; PAM module + display binary: # libdir/ahfail; the ahfail command: bindir. install_dir: cargo_install_dirs, install_mode: 'rwxr-xr-x' ) cargo_target = cargo_all[0] pam_cargo = cargo_all[1] # The locker's own PAM service. Shipped as its own file, like swaylock and # gtklock do, so no other package's PAM configuration is ever touched. if is_linux install_data('data/pam.d/ahfail', install_dir: get_option('sysconfdir') / 'pam.d', install_mode: 'rw-r--r--' ) endif libahfail = shared_library( 'ahfail-module', resources, link_args: ['-Wl,--whole-archive', meson.current_build_dir() / 'libahfail_module.a', '-Wl,--no-whole-archive'], link_depends: cargo_target, include_directories: ahfail_inc, dependencies: [gtk_dep, gstplayer_dep, m_dep], install: true, install_dir: get_option('libdir') / 'gtklock', name_prefix: '' ) smoke = executable( 'module_smoke_test', 'tests/module_test.c', include_directories: ahfail_inc, link_with: libahfail, dependencies: [gtk_dep, gstplayer_dep] ) test('module symbols', smoke) # PAM module smoke test: dlopen libahfail_pam.so and verify pam_sm_authenticate is exported. pam_smoke = executable( 'pam_smoke_test', 'tests/pam_smoke_test.c', dependencies: [cc.find_library('dl', required: true)] ) test('pam symbols', pam_smoke, args: [meson.current_build_dir() / 'libahfail_pam.so'], depends: pam_cargo)