Skip to content

Commit

Permalink
Nix & Meson: init for v2-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Aug 27, 2023
1 parent 3adac24 commit e372863
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 139 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 29 additions & 133 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,138 +1,34 @@
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 <sys/timerfd.h>') or
not cc.has_function('signalfd', prefix: '#include <sys/signalfd.h>'))
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
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
],)

# 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
sdbus = dependency(get_option('sd-bus-provider'))
error('Could not configure current C++ compiler (' + cpp_compiler.get_id() + ' ' + cpp_compiler.version() + ') with required C++ standard (C++23)')
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,
],
include_directories: [inc],
install: true,
install_dir: get_option('libexecdir'),
)

conf_data = configuration_data()
conf_data.set('libexecdir',
join_paths(get_option('prefix'), get_option('libexecdir')))
conf_data.set('systemd_service', '')

systemd = dependency('systemd', required: get_option('systemd'))

if systemd.found()
systemd_service_file = 'xdg-desktop-portal-hyprland.service'
user_unit_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir',
pkgconfig_define: ['prefix', get_option('prefix')])
conf_data.set('systemd_service', 'SystemdService=' + systemd_service_file)

configure_file(
configuration: conf_data,
input: 'contrib/systemd/' + systemd_service_file + '.in',
output: '@BASENAME@',
install_dir: user_unit_dir,
)
endif

configure_file(
configuration: conf_data,
input: 'org.freedesktop.impl.portal.desktop.hyprland.service.in',
output: '@BASENAME@',
install_dir: join_paths(get_option('datadir'), 'dbus-1', 'services'),
)

install_data(
'hyprland.portal',
install_dir: join_paths(get_option('datadir'), 'xdg-desktop-portal', 'portals'),
)
add_project_arguments(cpp_compiler.get_supported_arguments([
'-Wall',
'-Wextra',
'-Wno-pointer-arith',
'-Wno-unused-parameter',
'-Wno-unused-value',
'-Wno-missing-field-initializers',
'-Wno-narrowing',
]), language: 'cpp')

wayland_protos = dependency('wayland-protocols', version: '>=1.24')
49 changes: 49 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
lib,
stdenv,
makeWrapper,
meson,
ninja,
pkg-config,
wayland-protocols,
wayland-scanner,
hyprland-share-picker,
grim,
slurp,
hyprland-protocols,
wayland,
version ? "git",
}:
stdenv.mkDerivation {
pname = "xdg-desktop-portal-hyprland";
inherit version;

src = ../.;

strictDeps = true;
depsBuildBuild = [pkg-config];
nativeBuildInputs = [
meson
ninja
pkg-config
wayland-scanner
makeWrapper
];
buildInputs = [
hyprland-protocols
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;
};
}
34 changes: 34 additions & 0 deletions nix/hyprland-share-picker.nix
Original file line number Diff line number Diff line change
@@ -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]}
'';
}
28 changes: 28 additions & 0 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
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
]);
xdg-desktop-portal-hyprland = final: prev: {
xdg-desktop-portal-hyprland = final.callPackage ./default.nix {
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;};
};
}
3 changes: 0 additions & 3 deletions protocols/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
wl_protocol_dir = wayland_protos.get_variable('pkgdatadir')
hl_protocol_dir = hyprland_protos.get_variable('pkgdatadir')

wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
Expand All @@ -12,8 +11,6 @@ else
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',
Expand Down
18 changes: 18 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
globber = run_command('find', '.', '-name', '*.cpp', check: true)
src = globber.stdout().strip().split('\n')

executable('xdg-desktop-portal-hyprland', src,
dependencies: [
dependency('wayland-client'),
dependency('wayland-protocols'),
dependency('cairo'),
dependency('libjpeg')
dependency('pango'),
dependency('pangocairo')
dependency('sdbus'),
dependency('threads'),
hyprland_protos,
],
install: true,
install_dir: get_option('libexecdir')
)

0 comments on commit e372863

Please sign in to comment.