portage-overlay

personal portage ebuild repository
git clone anongit@rnpnr.xyz:portage-overlay.git
Log | Files | Refs | Feed | README

mesa-24.3.1.ebuild (13530B)


      1 # Copyright 1999-2024 Gentoo Authors
      2 # Distributed under the terms of the GNU General Public License v2
      3 
      4 EAPI=8
      5 
      6 LLVM_COMPAT=( {15..19} )
      7 LLVM_OPTIONAL=1
      8 CARGO_OPTIONAL=1
      9 PYTHON_COMPAT=( python3_{10..13} )
     10 
     11 inherit flag-o-matic llvm-r1 meson-multilib python-any-r1 linux-info rust-toolchain
     12 
     13 MY_P="${P/_/-}"
     14 
     15 CRATES="
     16 	syn@2.0.68
     17 	proc-macro2@1.0.86
     18 	quote@1.0.33
     19 	unicode-ident@1.0.12
     20 	paste@1.0.14
     21 "
     22 
     23 RUST_MIN_VER="1.74.1"
     24 RUST_OPTIONAL=1
     25 
     26 inherit cargo
     27 
     28 DESCRIPTION="OpenGL-like graphic library for Linux"
     29 HOMEPAGE="https://www.mesa3d.org/ https://mesa.freedesktop.org/"
     30 
     31 if [[ ${PV} == 9999 ]]; then
     32 	EGIT_REPO_URI="https://gitlab.freedesktop.org/mesa/mesa.git"
     33 	inherit git-r3
     34 else
     35 	SRC_URI="
     36 		https://archive.mesa3d.org/${MY_P}.tar.xz
     37 	"
     38 	KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-solaris"
     39 fi
     40 
     41 # This should be {CARGO_CRATE_URIS//.crate/.tar.gz} to correspond to the wrap files,
     42 # but there are "stale" distfiles on the mirrors with the wrong names.
     43 # export MESON_PACKAGE_CACHE_DIR="${DISTDIR}"
     44 SRC_URI+="
     45 	${CARGO_CRATE_URIS}
     46 "
     47 
     48 S="${WORKDIR}/${MY_P}"
     49 EGIT_CHECKOUT_DIR=${S}
     50 
     51 LICENSE="MIT SGI-B-2.0"
     52 SLOT="0"
     53 
     54 RADEON_CARDS="r300 r600 radeon radeonsi"
     55 VIDEO_CARDS="${RADEON_CARDS}
     56 	d3d12 freedreno intel lavapipe lima nouveau nvk panfrost v3d vc4 virgl
     57 	vivante vmware zink"
     58 for card in ${VIDEO_CARDS}; do
     59 	IUSE_VIDEO_CARDS+=" video_cards_${card}"
     60 done
     61 
     62 IUSE="${IUSE_VIDEO_CARDS}
     63 	cpu_flags_x86_sse2 d3d9 debug +llvm
     64 	lm-sensors opencl +opengl osmesa +proprietary-codecs selinux
     65 	test unwind vaapi valgrind vdpau vulkan
     66 	wayland +X xa +zstd"
     67 RESTRICT="!test? ( test )"
     68 REQUIRED_USE="
     69 	d3d9? (
     70 		|| (
     71 			video_cards_freedreno
     72 			video_cards_intel
     73 			video_cards_nouveau
     74 			video_cards_panfrost
     75 			video_cards_r300
     76 			video_cards_r600
     77 			video_cards_radeonsi
     78 			video_cards_vmware
     79 			video_cards_zink
     80 		)
     81 	)
     82 	llvm? ( ${LLVM_REQUIRED_USE} )
     83 	video_cards_lavapipe? ( llvm vulkan )
     84 	video_cards_radeon? ( x86? ( llvm ) amd64? ( llvm ) )
     85 	video_cards_r300?   ( x86? ( llvm ) amd64? ( llvm ) )
     86 	video_cards_zink? ( vulkan opengl )
     87 	video_cards_nvk? ( vulkan video_cards_nouveau )
     88 	vdpau? ( X )
     89 	xa? ( X )
     90 "
     91 
     92 LIBDRM_DEPSTRING=">=x11-libs/libdrm-2.4.121"
     93 RDEPEND="
     94 	>=dev-libs/expat-2.1.0-r3[${MULTILIB_USEDEP}]
     95 	>=media-libs/libglvnd-1.3.2[X?,${MULTILIB_USEDEP}]
     96 	>=sys-libs/zlib-1.2.9[${MULTILIB_USEDEP}]
     97 	unwind? ( sys-libs/libunwind[${MULTILIB_USEDEP}] )
     98 	llvm? (
     99 		$(llvm_gen_dep "
    100 			llvm-core/llvm:\${LLVM_SLOT}[llvm_targets_AMDGPU(+),${MULTILIB_USEDEP}]
    101 			opencl? (
    102 				dev-util/spirv-llvm-translator:\${LLVM_SLOT}
    103 				llvm-core/clang:\${LLVM_SLOT}[llvm_targets_AMDGPU(+),${MULTILIB_USEDEP}]
    104 			)
    105 		")
    106 		video_cards_r600? (
    107 			virtual/libelf:0=[${MULTILIB_USEDEP}]
    108 		)
    109 		video_cards_radeon? (
    110 			virtual/libelf:0=[${MULTILIB_USEDEP}]
    111 		)
    112 	)
    113 	lm-sensors? ( sys-apps/lm-sensors:=[${MULTILIB_USEDEP}] )
    114 	opencl? (
    115 		>=virtual/opencl-3
    116 		llvm-core/libclc[spirv(-)]
    117 		>=dev-util/spirv-tools-1.3.231.0
    118 		virtual/libelf:0=
    119 	)
    120 	vaapi? (
    121 		>=media-libs/libva-1.7.3:=[${MULTILIB_USEDEP}]
    122 	)
    123 	vdpau? ( >=x11-libs/libvdpau-1.5:=[${MULTILIB_USEDEP}] )
    124 	video_cards_radeonsi? ( virtual/libelf:0=[${MULTILIB_USEDEP}] )
    125 	video_cards_zink? ( media-libs/vulkan-loader:=[${MULTILIB_USEDEP}] )
    126 	selinux? ( sys-libs/libselinux[${MULTILIB_USEDEP}] )
    127 	wayland? ( >=dev-libs/wayland-1.18.0[${MULTILIB_USEDEP}] )
    128 	${LIBDRM_DEPSTRING}[video_cards_freedreno?,video_cards_intel?,video_cards_nouveau?,video_cards_vc4?,video_cards_vivante?,video_cards_vmware?,${MULTILIB_USEDEP}]
    129 	X? (
    130 		>=x11-libs/libX11-1.6.2[${MULTILIB_USEDEP}]
    131 		>=x11-libs/libxshmfence-1.1[${MULTILIB_USEDEP}]
    132 		>=x11-libs/libXext-1.3.2[${MULTILIB_USEDEP}]
    133 		>=x11-libs/libXxf86vm-1.1.3[${MULTILIB_USEDEP}]
    134 		>=x11-libs/libxcb-1.17:=[${MULTILIB_USEDEP}]
    135 		x11-libs/libXfixes[${MULTILIB_USEDEP}]
    136 		x11-libs/xcb-util-keysyms[${MULTILIB_USEDEP}]
    137 	)
    138 	zstd? ( app-arch/zstd:=[${MULTILIB_USEDEP}] )
    139 "
    140 for card in ${RADEON_CARDS}; do
    141 	RDEPEND="${RDEPEND}
    142 		video_cards_${card}? ( ${LIBDRM_DEPSTRING}[video_cards_radeon] )
    143 	"
    144 done
    145 RDEPEND="${RDEPEND}
    146 	video_cards_radeonsi? ( ${LIBDRM_DEPSTRING}[video_cards_amdgpu] )
    147 "
    148 
    149 DEPEND="${RDEPEND}
    150 	video_cards_d3d12? ( >=dev-util/directx-headers-1.614.1[${MULTILIB_USEDEP}] )
    151 	valgrind? ( dev-debug/valgrind )
    152 	wayland? ( >=dev-libs/wayland-protocols-1.38 )
    153 	X? (
    154 		x11-libs/libXrandr[${MULTILIB_USEDEP}]
    155 		x11-base/xorg-proto
    156 	)
    157 "
    158 BDEPEND="
    159 	${PYTHON_DEPS}
    160 	opencl? (
    161 		${RUST_DEPEND}
    162 		>=dev-util/bindgen-0.58.0
    163 	)
    164 	>=dev-build/meson-1.4.1
    165 	app-alternatives/yacc
    166 	app-alternatives/lex
    167 	virtual/pkgconfig
    168 	$(python_gen_any_dep "
    169 		>=dev-python/mako-0.8.0[\${PYTHON_USEDEP}]
    170 		dev-python/packaging[\${PYTHON_USEDEP}]
    171 		dev-python/pyyaml[\${PYTHON_USEDEP}]
    172 	")
    173 	video_cards_intel? (
    174 		~dev-util/intel_clc-${PV}
    175 		llvm-core/libclc[spirv(-)]
    176 		$(python_gen_any_dep "dev-python/ply[\${PYTHON_USEDEP}]")
    177 	)
    178 	vulkan? (
    179 		dev-util/glslang
    180 		video_cards_nvk? (
    181 			>=dev-util/bindgen-0.68.1
    182 			>=dev-util/cbindgen-0.26.0
    183 			${RUST_DEPEND}
    184 		)
    185 	)
    186 	wayland? ( dev-util/wayland-scanner )
    187 "
    188 
    189 QA_WX_LOAD="
    190 x86? (
    191 	usr/lib/libglapi.so.0.0.0
    192 	usr/lib/libOSMesa.so.8.0.0
    193 	usr/lib/libGLX_mesa.so.0.0.0
    194 )"
    195 
    196 src_unpack() {
    197 	if [[ ${PV} == 9999 ]]; then
    198 		git-r3_src_unpack
    199 	else
    200 		unpack ${MY_P}.tar.xz
    201 	fi
    202 
    203 	# We need this because we cannot tell meson to use DISTDIR yet
    204 	pushd "${DISTDIR}" >/dev/null || die
    205 	mkdir -p "${S}"/subprojects/packagecache || die
    206 	local i
    207 	for i in *.crate; do
    208 		ln -s "${PWD}/${i}" "${S}/subprojects/packagecache/${i/.crate/}.tar.gz" || die
    209 	done
    210 	popd >/dev/null || die
    211 }
    212 
    213 pkg_pretend() {
    214 	if use vulkan; then
    215 		if ! use video_cards_d3d12 &&
    216 		   ! use video_cards_freedreno &&
    217 		   ! use video_cards_intel &&
    218 		   ! use video_cards_lavapipe &&
    219 		   ! use video_cards_nouveau &&
    220 		   ! use video_cards_nvk &&
    221 		   ! use video_cards_panfrost &&
    222 		   ! use video_cards_radeonsi &&
    223 		   ! use video_cards_v3d &&
    224 		   ! use video_cards_virgl; then
    225 			ewarn "Ignoring USE=vulkan     since VIDEO_CARDS does not contain d3d12, freedreno, intel, lavapipe, nouveau, nvk, panfrost, radeonsi, v3d, or virgl"
    226 		fi
    227 	fi
    228 
    229 	# VA
    230 	if use vaapi; then
    231 		if ! use video_cards_d3d12 &&
    232 		   ! use video_cards_nouveau &&
    233 		   ! use video_cards_r600 &&
    234 		   ! use video_cards_radeonsi &&
    235 		   ! use video_cards_virgl; then
    236 			ewarn "Ignoring USE=vaapi      since VIDEO_CARDS does not contain d3d12, nouveau, r600, radeonsi, or virgl"
    237 		fi
    238 	fi
    239 
    240 	if use vdpau; then
    241 		if ! use video_cards_d3d12 &&
    242 		   ! use video_cards_nouveau &&
    243 		   ! use video_cards_r600 &&
    244 		   ! use video_cards_radeonsi &&
    245 		   ! use video_cards_virgl; then
    246 			ewarn "Ignoring USE=vdpau      since VIDEO_CARDS does not contain d3d12, nouveau, r600, radeonsi, or virgl"
    247 		fi
    248 	fi
    249 
    250 	if use xa; then
    251 		if ! use video_cards_freedreno &&
    252 		   ! use video_cards_intel &&
    253 		   ! use video_cards_nouveau &&
    254 		   ! use video_cards_vmware; then
    255 			ewarn "Ignoring USE=xa         since VIDEO_CARDS does not contain freedreno, intel, nouveau, or vmware"
    256 		fi
    257 	fi
    258 
    259 	if ! use llvm; then
    260 		use opencl     && ewarn "Ignoring USE=opencl     since USE does not contain llvm"
    261 	fi
    262 
    263 	if use osmesa && ! use llvm; then
    264 		ewarn "OSMesa will be slow without enabling USE=llvm"
    265 	fi
    266 }
    267 
    268 python_check_deps() {
    269 	python_has_version -b ">=dev-python/mako-0.8.0[${PYTHON_USEDEP}]" &&
    270 	python_has_version -b "dev-python/packaging[${PYTHON_USEDEP}]" &&
    271 	python_has_version -b "dev-python/pyyaml[${PYTHON_USEDEP}]" || return 1
    272 	if use llvm && use vulkan && use video_cards_intel && use amd64; then
    273 		python_has_version -b "dev-python/ply[${PYTHON_USEDEP}]" || return 1
    274 	fi
    275 }
    276 
    277 pkg_setup() {
    278 	# warning message for bug 459306
    279 	if use llvm && has_version llvm-core/llvm[!debug=]; then
    280 		ewarn "Mismatch between debug USE flags in media-libs/mesa and llvm-core/llvm"
    281 		ewarn "detected! This can cause problems. For details, see bug 459306."
    282 	fi
    283 
    284 	if use video_cards_intel ||
    285 	   use video_cards_radeonsi; then
    286 		if kernel_is -ge 5 11 3; then
    287 			CONFIG_CHECK="~KCMP"
    288 		elif kernel_is -ge 5 11; then
    289 			CONFIG_CHECK="~CHECKPOINT_RESTORE"
    290 		elif kernel_is -ge 5 10 20; then
    291 			CONFIG_CHECK="~KCMP"
    292 		else
    293 			CONFIG_CHECK="~CHECKPOINT_RESTORE"
    294 		fi
    295 		linux-info_pkg_setup
    296 	fi
    297 
    298 	use llvm && llvm-r1_pkg_setup
    299 	python-any-r1_pkg_setup
    300 
    301 	if use opencl || (use vulkan && use video_cards_nvk); then
    302 		rust_pkg_setup
    303 	fi
    304 }
    305 
    306 src_prepare() {
    307 	default
    308 	sed -i -e "/^PLATFORM_SYMBOLS/a '__gentoo_check_ldflags__'," \
    309 		bin/symbols-check.py || die # bug #830728
    310 }
    311 
    312 multilib_src_configure() {
    313 	local emesonargs=()
    314 
    315 	# bug #932591 and https://gitlab.freedesktop.org/mesa/mesa/-/issues/11140
    316 	filter-lto
    317 
    318 	local platforms
    319 	use X && platforms+="x11"
    320 	use wayland && platforms+=",wayland"
    321 	emesonargs+=(-Dplatforms=${platforms#,})
    322 
    323 	if use video_cards_freedreno ||
    324 	   use video_cards_intel || # crocus i915 iris
    325 	   use video_cards_nouveau ||
    326 	   use video_cards_panfrost ||
    327 	   use video_cards_r300 ||
    328 	   use video_cards_r600 ||
    329 	   use video_cards_radeonsi ||
    330 	   use video_cards_vmware || # svga
    331 	   use video_cards_zink; then
    332 		emesonargs+=($(meson_use d3d9 gallium-nine))
    333 	else
    334 		emesonargs+=(-Dgallium-nine=false)
    335 	fi
    336 
    337 	if use video_cards_d3d12 ||
    338 	   use video_cards_nouveau ||
    339 	   use video_cards_r600 ||
    340 	   use video_cards_radeonsi ||
    341 	   use video_cards_virgl; then
    342 		emesonargs+=($(meson_feature vaapi gallium-va))
    343 		use vaapi && emesonargs+=( -Dva-libs-path="${EPREFIX}"/usr/$(get_libdir)/va/drivers )
    344 	else
    345 		emesonargs+=(-Dgallium-va=disabled)
    346 	fi
    347 
    348 	if use video_cards_d3d12; then
    349 		emesonargs+=($(meson_feature vaapi gallium-d3d12-video))
    350 	fi
    351 
    352 	if use video_cards_d3d12 ||
    353 	   use video_cards_nouveau ||
    354 	   use video_cards_r600 ||
    355 	   use video_cards_radeonsi ||
    356 	   use video_cards_virgl; then
    357 		emesonargs+=($(meson_feature vdpau gallium-vdpau))
    358 	else
    359 		emesonargs+=(-Dgallium-vdpau=disabled)
    360 	fi
    361 
    362 	if use video_cards_freedreno ||
    363 	   use video_cards_intel ||
    364 	   use video_cards_nouveau ||
    365 	   use video_cards_vmware; then
    366 		emesonargs+=($(meson_feature xa gallium-xa))
    367 	else
    368 		emesonargs+=(-Dgallium-xa=disabled)
    369 	fi
    370 
    371 	gallium_enable !llvm softpipe
    372 	gallium_enable llvm llvmpipe
    373 	gallium_enable video_cards_d3d12 d3d12
    374 	gallium_enable video_cards_freedreno freedreno
    375 	gallium_enable video_cards_intel crocus i915 iris
    376 	gallium_enable video_cards_lima lima
    377 	gallium_enable video_cards_nouveau nouveau
    378 	gallium_enable video_cards_panfrost panfrost
    379 	gallium_enable video_cards_v3d v3d
    380 	gallium_enable video_cards_vc4 vc4
    381 	gallium_enable video_cards_virgl virgl
    382 	gallium_enable video_cards_vivante etnaviv
    383 	gallium_enable video_cards_vmware svga
    384 	gallium_enable video_cards_zink zink
    385 
    386 	gallium_enable video_cards_r300 r300
    387 	gallium_enable video_cards_r600 r600
    388 	gallium_enable video_cards_radeonsi radeonsi
    389 	if ! use video_cards_r300 &&
    390 	   ! use video_cards_r600; then
    391 		gallium_enable video_cards_radeon r300 r600
    392 	fi
    393 
    394 	if use llvm && use opencl; then
    395 		PKG_CONFIG_PATH="$(get_llvm_prefix)/$(get_libdir)/pkgconfig"
    396 		# See https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/docs/rusticl.rst
    397 		emesonargs+=(
    398 			$(meson_native_true gallium-rusticl)
    399 			-Drust_std=2021
    400 		)
    401 	fi
    402 
    403 	if use vulkan; then
    404 		vulkan_enable video_cards_d3d12 microsoft-experimental
    405 		vulkan_enable video_cards_freedreno freedreno
    406 		vulkan_enable video_cards_intel intel intel_hasvk
    407 		vulkan_enable video_cards_lavapipe swrast
    408 		vulkan_enable video_cards_panfrost panfrost
    409 		vulkan_enable video_cards_radeonsi amd
    410 		vulkan_enable video_cards_v3d broadcom
    411 		vulkan_enable video_cards_vc4 broadcom
    412 		vulkan_enable video_cards_virgl virtio
    413 		if use video_cards_nvk; then
    414 			vulkan_enable video_cards_nvk nouveau
    415 			if ! multilib_is_native_abi; then
    416 				echo -e "[binaries]\nrust = ['rustc', '--target=$(rust_abi $CBUILD)']" > "${T}/rust_fix.ini"
    417 				emesonargs+=(
    418 					--native-file "${T}"/rust_fix.ini
    419 				)
    420 			fi
    421 		fi
    422 
    423 		emesonargs+=(-Dvulkan-layers=device-select,overlay)
    424 	fi
    425 
    426 	driver_list() {
    427 		local drivers="$(sort -u <<< "${1// /$'\n'}")"
    428 		echo "${drivers//$'\n'/,}"
    429 	}
    430 
    431 	if use opengl && use X; then
    432 		emesonargs+=(-Dglx=dri)
    433 	else
    434 		emesonargs+=(-Dglx=disabled)
    435 	fi
    436 
    437 	if [[ "${ABI}" == amd64 ]]; then
    438 		emesonargs+=($(meson_feature video_cards_intel intel-rt))
    439 	fi
    440 
    441 	use debug && EMESON_BUILDTYPE=debug
    442 
    443 	emesonargs+=(
    444 		$(meson_use test build-tests)
    445 		-Dshared-glapi=enabled
    446 		-Dexpat=enabled
    447 		$(meson_use opengl)
    448 		$(meson_feature opengl gbm)
    449 		$(meson_feature opengl gles1)
    450 		$(meson_feature opengl gles2)
    451 		$(meson_feature opengl glvnd)
    452 		$(meson_feature opengl egl)
    453 		$(meson_feature llvm)
    454 		$(meson_feature lm-sensors lmsensors)
    455 		$(meson_use osmesa)
    456 		$(meson_use selinux)
    457 		$(meson_feature unwind libunwind)
    458 		$(meson_feature zstd)
    459 		$(meson_use cpu_flags_x86_sse2 sse2)
    460 		-Dintel-clc=$(usex video_cards_intel system auto)
    461 		-Dvalgrind=$(usex valgrind auto disabled)
    462 		-Dvideo-codecs=$(usex proprietary-codecs "all" "all_free")
    463 		-Dgallium-drivers=$(driver_list "${GALLIUM_DRIVERS[*]}")
    464 		-Dvulkan-drivers=$(driver_list "${VULKAN_DRIVERS[*]}")
    465 		-Db_ndebug=$(usex debug false true)
    466 	)
    467 	meson_src_configure
    468 
    469 	if ! multilib_is_native_abi && use video_cards_nvk; then
    470 		sed -i -E '{N; s/(rule rust_COMPILER_FOR_BUILD\n command = rustc) --target=[a-zA-Z0-9=:-]+ (.*) -C link-arg=-m[[:digit:]]+/\1 \2/g}' build.ninja || die
    471 	fi
    472 }
    473 
    474 multilib_src_test() {
    475 	meson_src_test -t 100
    476 }
    477 
    478 # $1 - VIDEO_CARDS flag (check skipped for "--")
    479 # other args - names of DRI drivers to enable
    480 gallium_enable() {
    481 	if [[ $1 == -- ]] || use $1; then
    482 		shift
    483 		GALLIUM_DRIVERS+=("$@")
    484 	fi
    485 }
    486 
    487 vulkan_enable() {
    488 	if [[ $1 == -- ]] || use $1; then
    489 		shift
    490 		VULKAN_DRIVERS+=("$@")
    491 	fi
    492 }