mesa-9999.ebuild 14 KB

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