c_josie_overlay

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

EAPI=8

ROCM_VERSION=10.1

inherit cmake rocm

DESCRIPTION="LLM inference server for AMD GPUs"
HOMEPAGE="https://codeberg.org/StillDeadcode/radiance"
SRC_URI="https://codeberg.org/StillDeadcode/radiance/archive/v${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/radiance"

LICENSE="Apache-2.0 MIT LFM-1.0"
SLOT="0"
KEYWORDS="~amd64"

IUSE="ffmpeg test"
REQUIRED_USE="${ROCM_REQUIRED_USE}"
RESTRICT="!test? ( test )"

DEPEND="
	dev-util/hip:0/${ROCM_VERSION}
	ffmpeg? ( media-video/ffmpeg:= )
"
BDEPEND="dev-util/hipcc:0/${ROCM_VERSION}"
RDEPEND="
	${DEPEND}
	net-misc/curl
	app-misc/jq
"

DOCS=( README.md )

PATCHES=(
	# clang 24 makes __bf16/__fp16 distinct storage-only types; the WMMA/fdot2
	# builtins now demand short/_Float16 vector operands.
	"${FILESDIR}/${PN}-1.9.0-clang-24-vector-types.patch"
)

src_configure() {
	# radiance's CMake locates hipcc itself and drives it as the device compiler.
	# Do not call rocm_use_hipcc: forcing CC/CXX=hipcc compiles host code for amdgcn.
	local mycmakeargs=(
		-DRAD_WITH_HIP=ON
		-DRAD_GPU_TARGETS="$(get_amdgpu_flags)"
		-DRAD_WITH_FFMPEG=$(usex ffmpeg ON OFF)
		-DRAD_BUILD_TESTS=$(usex test ON OFF)
	)
	cmake_src_configure
}

src_test() {
	# host-only suite: gpu tests need a card, oot rebuilds every plugin
	local myctestargs=( -LE 'gpu|oot' )
	cmake_src_test
}