mesa-9999.ebuild 14 KB

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