From 505975aa0512fc6bbd8657c2aaa8a669b8a2c5a7 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 27 Aug 2023 23:39:45 +0300 Subject: [PATCH] Nix & Meson: init for v2-rewrite --- .gitignore | 1 + flake.lock | 6 +- flake.nix | 1 + meson.build | 137 +++++++++------------------------- meson_options.txt | 1 - nix/default.nix | 64 ++++++++++++++++ nix/hyprland-share-picker.nix | 34 +++++++++ nix/overlays.nix | 41 ++++++++++ protocols/meson.build | 20 +++-- src/meson.build | 21 ++++++ 10 files changed, 213 insertions(+), 113 deletions(-) create mode 100644 nix/default.nix create mode 100644 nix/hyprland-share-picker.nix create mode 100644 nix/overlays.nix create mode 100644 src/meson.build diff --git a/.gitignore b/.gitignore index fa7bf3e..e2d84e4 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ dkms.conf build/ build-*/ +.cache .vscode/ hyprland-share-picker/build/ diff --git a/flake.lock b/flake.lock index adc6ef7..6e6f314 100644 --- a/flake.lock +++ b/flake.lock @@ -25,11 +25,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1683014792, - "narHash": "sha256-6Va9iVtmmsw4raBc3QKvQT2KT/NGRWlvUlJj46zN8B8=", + "lastModified": 1693844670, + "narHash": "sha256-t69F2nBB8DNQUWHD809oJZJVE+23XBrth4QZuVd6IE0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1a411f23ba299db155a5b45d5e145b85a7aafc42", + "rev": "3c15feef7770eb5500a4b8792623e2d6f598c9c1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c94fcd1..d8baf14 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,7 @@ inputs.hyprland-protocols.overlays.default self.overlays.xdg-desktop-portal-hyprland self.overlays.hyprland-share-picker + self.overlays.package-overrides ]; }); in { diff --git a/meson.build b/meson.build index 147c97f..589c4cd 100644 --- a/meson.build +++ b/meson.build @@ -1,111 +1,38 @@ -project( - 'xdg-desktop-portal-hyprland', - 'c', - version: '0.5.0', +project('xdg-desktop-portal-hyprland', 'cpp', 'c', + version: '2.0.0', license: 'MIT', - meson_version: '>=0.58.0', - default_options: ['c_std=c11', 'warning_level=2', 'werror=false'], -) - -cc = meson.get_compiler('c') - -add_project_arguments(cc.get_supported_arguments([ - '-Wno-missing-braces', - '-Wno-missing-field-initializers', - '-Wno-unused-parameter', - '-D_POSIX_C_SOURCE=200809L', - '-D_GNU_SOURCE', -]), language: 'c') - -prefix = get_option('prefix') -sysconfdir = get_option('sysconfdir') -add_project_arguments('-DSYSCONFDIR="@0@"'.format(join_paths(prefix, sysconfdir)), language : 'c') - -inc = include_directories('include') - -rt = cc.find_library('rt') -pipewire = dependency('libpipewire-0.3', version: '>= 0.3.62') -hyprland_protos = dependency('hyprland-protocols', version: '>=0.2', fallback: 'hyprland-protocols') -wayland_client = dependency('wayland-client') -wayland_protos = dependency('wayland-protocols', version: '>=1.24') -iniparser = dependency('inih') -gbm = dependency('gbm') -drm = dependency('libdrm') -uuid = dependency('uuid') - -epoll = dependency('', required: false) -if (not cc.has_function('timerfd_create', prefix: '#include ') or - not cc.has_function('signalfd', prefix: '#include ')) - epoll = dependency('epoll-shim') -endif - -if get_option('sd-bus-provider') == 'auto' - assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto') - sdbus = dependency('libsystemd', - required: false, - not_found_message: 'libsystemd not found, trying libelogind', - ) - if not sdbus.found() - sdbus = dependency('libelogind', - required: false, - not_found_message: 'libelogind not found, trying basu', - ) - endif - if not sdbus.found() - sdbus = dependency('basu', - required: false, - ) - endif - if not sdbus.found() - error('Neither libsystemd, nor libelogind, nor basu was found') - endif -else - sdbus = dependency(get_option('sd-bus-provider')) -endif -add_project_arguments('-DHAVE_' + sdbus.name().to_upper() + '=1', language: 'c') - -subdir('protocols') - -xdpw_files = files([ - 'src/core/main.c', - 'src/core/logger.c', - 'src/core/config.c', - 'src/core/request.c', - 'src/core/session.c', - 'src/core/timer.c', - 'src/core/timespec_util.c', - 'src/core/utils.c', - 'src/screenshot/screenshot.c', - 'src/screencast/screencast.c', - 'src/screencast/screencast_common.c', - 'src/screencast/wlr_screencast.c', - 'src/screencast/pipewire_screencast.c', - 'src/screencast/fps_limit.c', - 'src/globalshortcuts/global_shortcuts.c' -]) - -executable( - 'xdg-desktop-portal-hyprland', - [xdpw_files, wl_proto_files], - dependencies: [ - wayland_client, - sdbus, - pipewire, - rt, - iniparser, - gbm, - drm, - epoll, - uuid, + meson_version: '>=0.63.0', + default_options: [ + 'warning_level=2', + 'optimization=3', + 'buildtype=release', + 'debug=false', + # 'cpp_std=c++23' # not yet supported by meson, as of version 0.63.0 ], - include_directories: [inc], - install: true, - install_dir: get_option('libexecdir'), ) +# clang v14.0.6 uses C++2b instead of C++23, so we've gotta account for that +# replace the following with a project default option once meson gets support for C++23 +cpp_compiler = meson.get_compiler('cpp') +if cpp_compiler.has_argument('-std=c++23') + add_global_arguments('-std=c++23', language: 'cpp') +elif cpp_compiler.has_argument('-std=c++2b') + add_global_arguments('-std=c++2b', language: 'cpp') +else + error('Could not configure current C++ compiler (' + cpp_compiler.get_id() + ' ' + cpp_compiler.version() + ') with required C++ standard (C++23)') +endif + +add_project_arguments(cpp_compiler.get_supported_arguments([ + '-Wno-missing-field-initializers', + '-Wno-narrowing', + '-Wno-pointer-arith', + '-Wno-unused-parameter', + '-Wno-unused-value', + '-fpermissive' +]), language: 'cpp') + conf_data = configuration_data() -conf_data.set('libexecdir', - join_paths(get_option('prefix'), get_option('libexecdir'))) +conf_data.set('libexecdir', join_paths(get_option('prefix'), get_option('libexecdir'))) conf_data.set('systemd_service', '') systemd = dependency('systemd', required: get_option('systemd')) @@ -136,3 +63,7 @@ install_data( install_dir: join_paths(get_option('datadir'), 'xdg-desktop-portal', 'portals'), ) +inc = include_directories('.', 'protocols') + +subdir('protocols') +subdir('src') diff --git a/meson_options.txt b/meson_options.txt index d7ae3ab..5303abc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1 @@ -option('sd-bus-provider', type: 'combo', choices: ['auto', 'libsystemd', 'libelogind', 'basu'], value: 'auto', description: 'Provider of the sd-bus library') option('systemd', type: 'feature', value: 'auto', description: 'Install systemd user service unit') diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..763bc10 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,64 @@ +{ + lib, + stdenv, + makeWrapper, + meson, + ninja, + pkg-config, + cairo, + hyprland-share-picker, + libdrm, + libjpeg, + mesa, + pango, + pipewire, + sdbus-cpp, + systemd, + wayland-protocols, + wayland-scanner, + grim, + slurp, + hyprland-protocols, + wayland, + version ? "git", +}: +stdenv.mkDerivation { + pname = "xdg-desktop-portal-hyprland"; + inherit version; + + src = ../.; + + nativeBuildInputs = [ + meson + ninja + pkg-config + wayland-scanner + makeWrapper + ]; + + buildInputs = [ + cairo + hyprland-protocols + libdrm + libjpeg + mesa + pango + pipewire + sdbus-cpp + systemd + wayland + wayland-protocols + ]; + + postInstall = '' + wrapProgram $out/libexec/xdg-desktop-portal-hyprland --prefix PATH ":" ${lib.makeBinPath [hyprland-share-picker grim slurp]} + ''; + + meta = with lib; { + homepage = "https://github.com/hyprwm/xdg-desktop-portal-hyprland"; + description = "xdg-desktop-portal backend for Hyprland"; + maintainers = with maintainers; [fufexan]; + platforms = platforms.linux; + license = licenses.mit; + }; +} diff --git a/nix/hyprland-share-picker.nix b/nix/hyprland-share-picker.nix new file mode 100644 index 0000000..6632beb --- /dev/null +++ b/nix/hyprland-share-picker.nix @@ -0,0 +1,34 @@ +{ + stdenv, + lib, + cmake, + qtbase, + makeShellWrapper, + wrapQtAppsHook, + hyprland, + slurp, + version ? "git", + ... +}: +stdenv.mkDerivation { + pname = "hyprland-share-picker"; + inherit version; + src = ../hyprland-share-picker; + + nativeBuildInputs = [ + cmake + wrapQtAppsHook + makeShellWrapper + ]; + buildInputs = [ + qtbase + ]; + + dontWrapQtApps = true; + + postInstall = '' + wrapProgramShell $out/bin/hyprland-share-picker \ + "''${qtWrapperArgs[@]}" \ + --prefix PATH ":" ${lib.makeBinPath [slurp hyprland]} + ''; +} diff --git a/nix/overlays.nix b/nix/overlays.nix new file mode 100644 index 0000000..1eae17d --- /dev/null +++ b/nix/overlays.nix @@ -0,0 +1,41 @@ +{ + self, + inputs, + lib, +}: let + mkJoinedOverlays = overlays: final: prev: + lib.foldl' (attrs: overlay: attrs // (overlay final prev)) {} overlays; + mkDate = longDate: (lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]); + version = "0.pre" + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty"); +in { + default = mkJoinedOverlays (with self.overlays; [ + xdg-desktop-portal-hyprland + hyprland-share-picker + package-overrides + ]); + xdg-desktop-portal-hyprland = final: prev: { + xdg-desktop-portal-hyprland = final.callPackage ./default.nix { + stdenv = prev.gcc13Stdenv; + inherit (final) hyprland-protocols hyprland-share-picker; + inherit version; + }; + }; + hyprland-share-picker = final: prev: { + hyprland-share-picker = final.libsForQt5.callPackage ./hyprland-share-picker.nix {inherit version;}; + }; + package-overrides = final: prev: { + sdbus-cpp = prev.sdbus-cpp.overrideAttrs (self: super: { + version = "1.3.0"; + src = prev.fetchFromGitHub { + repo = "sdbus-cpp"; + owner = "Kistler-Group"; + rev = "v${self.version}"; + hash = "sha256-S/8/I2wmWukpP+RGPxKbuO44wIExzeYZL49IO+KOqg4="; + }; + }); + }; +} diff --git a/protocols/meson.build b/protocols/meson.build index cda43b8..2547daf 100644 --- a/protocols/meson.build +++ b/protocols/meson.build @@ -1,3 +1,13 @@ +wayland_protos = dependency('wayland-protocols', + version: '>=1.31', + default_options: ['tests=false'], +) + +hyprland_protos = dependency('hyprland-protocols', + version: '>=0.2', + fallback: 'hyprland-protocols', +) + wl_protocol_dir = wayland_protos.get_variable('pkgdatadir') hl_protocol_dir = hyprland_protos.get_variable('pkgdatadir') @@ -10,14 +20,12 @@ if wayland_scanner_dep.found() else wayland_scanner = find_program('wayland-scanner', native: true) endif - client_protocols = [ - wl_protocol_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml', - wl_protocol_dir / 'unstable/xdg-output/xdg-output-unstable-v1.xml', - hl_protocol_dir / 'protocols/hyprland-toplevel-export-v1.xml', - hl_protocol_dir / 'protocols/hyprland-global-shortcuts-v1.xml', 'wlr-screencopy-unstable-v1.xml', 'wlr-foreign-toplevel-management-unstable-v1.xml', + hl_protocol_dir / 'protocols/hyprland-toplevel-export-v1.xml', + hl_protocol_dir / 'protocols/hyprland-global-shortcuts-v1.xml', + wl_protocol_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml', ] wl_proto_files = [] @@ -33,7 +41,7 @@ foreach xml: client_protocols client_header = custom_target( xml.underscorify() + '_client_h', input: xml, - output: '@BASENAME@-client-protocol.h', + output: '@BASENAME@-protocol.h', command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'], ) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..ec0fd1d --- /dev/null +++ b/src/meson.build @@ -0,0 +1,21 @@ +globber = run_command('find', '.', '-name', '*.cpp', check: true) +src = globber.stdout().strip().split('\n') + +executable('xdg-desktop-portal-hyprland', + [src, wl_proto_files], + dependencies: [ + dependency('cairo'), + dependency('gbm'), + dependency('libdrm'), + dependency('libjpeg'), + dependency('libpipewire-0.3'), + dependency('pango'), + dependency('pangocairo'), + dependency('sdbus-c++'), + dependency('threads'), + dependency('wayland-client'), + ], + include_directories: inc, + install: true, + install_dir: get_option('libexecdir') +)