# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.15.1

EAPI=8

#declare -A GIT_CRATES=(
#	[hyprland-macros]='https://github.com/hyprland-community/hyprland-rs;2d11487cf4c1f333db9df6b6f291b96cc6daf1f7;hyprland-rs-%commit%/hyprland-macros'
#	[hyprland]='https://github.com/hyprland-community/hyprland-rs;2d11487cf4c1f333db9df6b6f291b96cc6daf1f7;hyprland-rs-%commit%'
#	[iced_layershell]='https://github.com/MalpenZibo/iced_layershell;e224d160e1e1b4236722b6ff3f9110faa0b3a263;iced_layershell-%commit%'
#	[softbuffer]='https://github.com/MalpenZibo/softbuffer;8791db4844f58036bd25934f8133e11c31877933;softbuffer-%commit%'
#)

LLVM_COMPAT=( 22 )
RUST_MIN_VER="1.95.0"
RUST_NEEDS_LLVM=1

inherit cargo llvm-r1 systemd git-r3

DESCRIPTION="A ready to go Wayland status bar for Hyprland and Niri"
HOMEPAGE="https://malpenzibo.github.io/ashell/"
EGIT_REPO_URI="https://github.com/MalpenZibo/ashell.git"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD-2 BSD CC0-1.0
	CDLA-Permissive-2.0 GPL-3+ ISC MIT MPL-2.0 Unicode-3.0 ZLIB
"
SLOT="0"
KEYWORDS=""

RDEPEND="
	dev-libs/wayland-protocols
	media-fonts/symbols-nerd-font
	media-libs/libpulse
	media-video/pipewire:=
	sys-apps/dbus
	x11-libs/libxkbcommon
"
# libclang is required for bindgen
BDEPEND="
	$(llvm_gen_dep 'llvm-core/clang:${LLVM_SLOT}')
"

pkg_setup() {
	llvm-r1_pkg_setup
	rust_pkg_setup
}

src_unpack() {
	git-r3_src_unpack
	cargo_live_src_unpack
}

src_prepare() {
	default

	# cargo always tries to fetch `patch.crates-io` git entries
	local SOFTBUFFER_COMMIT=8791db4844f58036bd25934f8133e11c31877933
	local SOFTBUFFER_GIT="softbuffer = { git = \"https://github.com/MalpenZibo/softbuffer\", branch = \"wayland-argb\""
	local SOFTBUFFER_PATH="softbuffer = \\{ path = \"${WORKDIR}/cargo_home/gentoo/softbuffer\""
	local SOFTBUFFER_SRC="https://github.com/MalpenZibo/softbuffer"

	sed -e "s#${SOFTBUFFER_GIT}#${SOFTBUFFER_PATH}#" \
		-i "${S}/Cargo.toml" || die "Cargo.toml --frozen workaround failed"

	sed -e "\#${SOFTBUFFER_SRC}#d" \
		-i "${S}/Cargo.lock" || die "Cargo.lock --frozen workaround failed"
}

src_configure() {
	cargo_src_configure --frozen
}

src_install() {
	# default invokes `make install` which invokes `sudo cp`
	# therefore explicitly invoke cargo_src_install
	cargo_src_install
	einstalldocs
	systemd_douserunit "${FILESDIR}/ashell.service"
}

pkg_postinst() {
	systemd_is_booted && elog "This port provides the systemd user service unit ashell.service."
}