You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

454 lines
13 KiB

  1. # Copyright 1999-2021 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="7"
  4. # Patch version
  5. FIREFOX_PATCHSET="firefox-78esr-patches-17.tar.xz"
  6. SPIDERMONKEY_PATCHSET="spidermonkey-78-patches-04.tar.xz"
  7. LLVM_MAX_SLOT=12
  8. PYTHON_COMPAT=( python3_{7..9} )
  9. WANT_AUTOCONF="2.1"
  10. inherit autotools check-reqs flag-o-matic llvm multiprocessing prefix python-any-r1 toolchain-funcs
  11. MY_PN="mozjs"
  12. MY_PV="${PV/_pre*}" # Handle Gentoo pre-releases
  13. MY_MAJOR=$(ver_cut 1)
  14. MOZ_ESR=yes
  15. MOZ_PV=${PV}
  16. MOZ_PV_SUFFIX=
  17. if [[ ${PV} =~ (_(alpha|beta|rc).*)$ ]] ; then
  18. MOZ_PV_SUFFIX=${BASH_REMATCH[1]}
  19. # Convert the ebuild version to the upstream Mozilla version
  20. MOZ_PV="${MOZ_PV/_alpha/a}" # Handle alpha for SRC_URI
  21. MOZ_PV="${MOZ_PV/_beta/b}" # Handle beta for SRC_URI
  22. MOZ_PV="${MOZ_PV%%_rc*}" # Handle rc for SRC_URI
  23. fi
  24. if [[ -n ${MOZ_ESR} ]] ; then
  25. # ESR releases have slightly different version numbers
  26. MOZ_PV="${MOZ_PV}esr"
  27. fi
  28. MOZ_PN="firefox"
  29. MOZ_P="${MOZ_PN}-${MOZ_PV}"
  30. MOZ_PV_DISTFILES="${MOZ_PV}${MOZ_PV_SUFFIX}"
  31. MOZ_P_DISTFILES="${MOZ_PN}-${MOZ_PV_DISTFILES}"
  32. MOZ_SRC_BASE_URI="https://archive.mozilla.org/pub/${MOZ_PN}/releases/${MOZ_PV}"
  33. if [[ ${PV} == *_rc* ]] ; then
  34. MOZ_SRC_BASE_URI="https://archive.mozilla.org/pub/${MOZ_PN}/candidates/${MOZ_PV}-candidates/build${PV##*_rc}"
  35. fi
  36. PATCH_URIS=(
  37. https://dev.gentoo.org/~{whissi,polynomial-c,axs}/mozilla/patchsets/${FIREFOX_PATCHSET}
  38. https://dev.gentoo.org/~{whissi,polynomial-c,axs}/mozilla/patchsets/${SPIDERMONKEY_PATCHSET}
  39. )
  40. SRC_URI="${MOZ_SRC_BASE_URI}/source/${MOZ_P}.source.tar.xz -> ${MOZ_P_DISTFILES}.source.tar.xz
  41. ${PATCH_URIS[@]}"
  42. DESCRIPTION="SpiderMonkey is Mozilla's JavaScript engine written in C and C++"
  43. HOMEPAGE="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey"
  44. KEYWORDS="amd64 arm ~arm64 ~mips ~ppc64 ~riscv ~s390 x86"
  45. SLOT="78"
  46. LICENSE="MPL-2.0"
  47. IUSE="clang cpu_flags_arm_neon debug +jit lto test"
  48. RESTRICT="!test? ( test )"
  49. BDEPEND="${PYTHON_DEPS}
  50. >=virtual/rust-1.41.0
  51. virtual/pkgconfig
  52. || (
  53. (
  54. sys-devel/llvm:12
  55. clang? (
  56. sys-devel/clang:12
  57. lto? ( =sys-devel/lld-12* )
  58. )
  59. )
  60. (
  61. sys-devel/llvm:11
  62. clang? (
  63. sys-devel/clang:11
  64. lto? ( =sys-devel/lld-11* )
  65. )
  66. )
  67. (
  68. sys-devel/llvm:10
  69. clang? (
  70. sys-devel/clang:10
  71. lto? ( =sys-devel/lld-10* )
  72. )
  73. )
  74. )
  75. lto? (
  76. !clang? ( sys-devel/binutils[gold] )
  77. )"
  78. CDEPEND=">=dev-libs/icu-67.1:=
  79. >=dev-libs/nspr-4.25
  80. sys-libs/readline:0=
  81. >=sys-libs/zlib-1.2.3"
  82. DEPEND="${CDEPEND}
  83. test? (
  84. $(python_gen_any_dep 'dev-python/six[${PYTHON_USEDEP}]')
  85. )"
  86. RDEPEND="${CDEPEND}"
  87. S="${WORKDIR}/firefox-${MY_PV}/js/src"
  88. llvm_check_deps() {
  89. if ! has_version -b "sys-devel/llvm:${LLVM_SLOT}" ; then
  90. einfo "sys-devel/llvm:${LLVM_SLOT} is missing! Cannot use LLVM slot ${LLVM_SLOT} ..." >&2
  91. return 1
  92. fi
  93. if use clang ; then
  94. if ! has_version -b "sys-devel/clang:${LLVM_SLOT}" ; then
  95. einfo "sys-devel/clang:${LLVM_SLOT} is missing! Cannot use LLVM slot ${LLVM_SLOT} ..." >&2
  96. return 1
  97. fi
  98. if use lto ; then
  99. if ! has_version -b "=sys-devel/lld-${LLVM_SLOT}*" ; then
  100. einfo "=sys-devel/lld-${LLVM_SLOT}* is missing! Cannot use LLVM slot ${LLVM_SLOT} ..." >&2
  101. return 1
  102. fi
  103. fi
  104. fi
  105. einfo "Using LLVM slot ${LLVM_SLOT} to build" >&2
  106. }
  107. python_check_deps() {
  108. if use test ; then
  109. has_version "dev-python/six[${PYTHON_USEDEP}]"
  110. fi
  111. }
  112. pkg_pretend() {
  113. if use test ; then
  114. CHECKREQS_DISK_BUILD="7600M"
  115. else
  116. CHECKREQS_DISK_BUILD="6400M"
  117. fi
  118. check-reqs_pkg_pretend
  119. }
  120. pkg_setup() {
  121. if [[ ${MERGE_TYPE} != binary ]] ; then
  122. if use test ; then
  123. CHECKREQS_DISK_BUILD="7600M"
  124. else
  125. CHECKREQS_DISK_BUILD="6400M"
  126. fi
  127. check-reqs_pkg_setup
  128. llvm_pkg_setup
  129. if use clang && use lto ; then
  130. local version_lld=$(ld.lld --version 2>/dev/null | awk '{ print $2 }')
  131. [[ -n ${version_lld} ]] && version_lld=$(ver_cut 1 "${version_lld}")
  132. [[ -z ${version_lld} ]] && die "Failed to read ld.lld version!"
  133. # temp fix for https://bugs.gentoo.org/768543
  134. # we can assume that rust 1.{49,50}.0 always uses llvm 11
  135. local version_rust=$(rustc -Vv 2>/dev/null | grep -F -- 'release:' | awk '{ print $2 }')
  136. [[ -n ${version_rust} ]] && version_rust=$(ver_cut 1-2 "${version_rust}")
  137. [[ -z ${version_rust} ]] && die "Failed to read version from rustc!"
  138. if ver_test "${version_rust}" -ge "1.49" && ver_test "${version_rust}" -le "1.50" ; then
  139. local version_llvm_rust="11"
  140. else
  141. local version_llvm_rust=$(rustc -Vv 2>/dev/null | grep -F -- 'LLVM version:' | awk '{ print $3 }')
  142. [[ -n ${version_llvm_rust} ]] && version_llvm_rust=$(ver_cut 1 "${version_llvm_rust}")
  143. [[ -z ${version_llvm_rust} ]] && die "Failed to read used LLVM version from rustc!"
  144. fi
  145. if ver_test "${version_lld}" -ne "${version_llvm_rust}" ; then
  146. eerror "Rust is using LLVM version ${version_llvm_rust} but ld.lld version belongs to LLVM version ${version_lld}."
  147. eerror "You will be unable to link ${CATEGORY}/${PN}. To proceed you have the following options:"
  148. eerror " - Manually switch rust version using 'eselect rust' to match used LLVM version"
  149. eerror " - Switch to dev-lang/rust[system-llvm] which will guarantee matching version"
  150. eerror " - Build ${CATEGORY}/${PN} without USE=lto"
  151. die "LLVM version used by Rust (${version_llvm_rust}) does not match with ld.lld version (${version_lld})!"
  152. fi
  153. fi
  154. python-any-r1_pkg_setup
  155. # Build system is using /proc/self/oom_score_adj, bug #604394
  156. addpredict /proc/self/oom_score_adj
  157. if ! mountpoint -q /dev/shm ; then
  158. # If /dev/shm is not available, configure is known to fail with
  159. # a traceback report referencing /usr/lib/pythonN.N/multiprocessing/synchronize.py
  160. ewarn "/dev/shm is not mounted -- expect build failures!"
  161. fi
  162. # Ensure we use C locale when building, bug #746215
  163. export LC_ALL=C
  164. fi
  165. }
  166. src_prepare() {
  167. pushd ../.. &>/dev/null || die
  168. use lto && rm -v "${WORKDIR}"/firefox-patches/*-LTO-Only-enable-LTO-*.patch
  169. eapply "${WORKDIR}"/firefox-patches
  170. eapply "${WORKDIR}"/spidermonkey-patches
  171. default
  172. # Make LTO respect MAKEOPTS
  173. sed -i \
  174. -e "s/multiprocessing.cpu_count()/$(makeopts_jobs)/" \
  175. build/moz.configure/lto-pgo.configure \
  176. || die "sed failed to set num_cores"
  177. # sed-in toolchain prefix
  178. sed -i \
  179. -e "s/objdump/${CHOST}-objdump/" \
  180. python/mozbuild/mozbuild/configure/check_debug_ranges.py \
  181. || die "sed failed to set toolchain prefix"
  182. # use prefix shell in wrapper linker scripts, bug #789660
  183. hprefixify "${S}"/../../build/cargo-{,host-}linker
  184. einfo "Removing pre-built binaries ..."
  185. find third_party -type f \( -name '*.so' -o -name '*.o' \) -print -delete || die
  186. MOZJS_BUILDDIR="${WORKDIR}/build"
  187. mkdir "${MOZJS_BUILDDIR}" || die
  188. popd &>/dev/null || die
  189. eautoconf
  190. }
  191. src_configure() {
  192. # Show flags set at the beginning
  193. einfo "Current CFLAGS: ${CFLAGS}"
  194. einfo "Current CXXFLAGS: ${CXXFLAGS}"
  195. einfo "Current LDFLAGS: ${LDFLAGS}"
  196. einfo "Current RUSTFLAGS: ${RUSTFLAGS}"
  197. local have_switched_compiler=
  198. if use clang && ! tc-is-clang ; then
  199. # Force clang
  200. einfo "Enforcing the use of clang due to USE=clang ..."
  201. have_switched_compiler=yes
  202. AR=llvm-ar
  203. CC=${CHOST}-clang
  204. CXX=${CHOST}-clang++
  205. NM=llvm-nm
  206. RANLIB=llvm-ranlib
  207. elif ! use clang && ! tc-is-gcc ; then
  208. # Force gcc
  209. have_switched_compiler=yes
  210. einfo "Enforcing the use of gcc due to USE=-clang ..."
  211. AR=gcc-ar
  212. CC=${CHOST}-gcc
  213. CXX=${CHOST}-g++
  214. NM=gcc-nm
  215. RANLIB=gcc-ranlib
  216. fi
  217. if [[ -n "${have_switched_compiler}" ]] ; then
  218. # Because we switched active compiler we have to ensure
  219. # that no unsupported flags are set
  220. strip-unsupported-flags
  221. fi
  222. # Ensure we use correct toolchain
  223. export HOST_CC="$(tc-getBUILD_CC)"
  224. export HOST_CXX="$(tc-getBUILD_CXX)"
  225. tc-export CC CXX LD AR NM OBJDUMP RANLIB PKG_CONFIG
  226. cd "${MOZJS_BUILDDIR}" || die
  227. # ../python/mach/mach/mixin/process.py fails to detect SHELL
  228. export SHELL="${EPREFIX}/bin/bash"
  229. local -a myeconfargs=(
  230. --host="${CBUILD:-${CHOST}}"
  231. --target="${CHOST}"
  232. --disable-jemalloc
  233. --disable-optimize
  234. --disable-strip
  235. --enable-readline
  236. --enable-shared-js
  237. --with-intl-api
  238. --with-system-icu
  239. --with-system-nspr
  240. --with-system-zlib
  241. --with-toolchain-prefix="${CHOST}-"
  242. $(use_enable debug)
  243. $(use_enable jit)
  244. $(use_enable test tests)
  245. )
  246. if ! use x86 && [[ ${CHOST} != armv*h* ]] ; then
  247. myeconfargs+=( --enable-rust-simd )
  248. fi
  249. # Modifications to better support ARM, bug 717344
  250. if use cpu_flags_arm_neon ; then
  251. myeconfargs+=( --with-fpu=neon )
  252. if ! tc-is-clang ; then
  253. # thumb options aren't supported when using clang, bug 666966
  254. myeconfargs+=( --with-thumb=yes )
  255. myeconfargs+=( --with-thumb-interwork=no )
  256. fi
  257. fi
  258. # Tell build system that we want to use LTO
  259. if use lto ; then
  260. myeconfargs+=( --enable-lto )
  261. if use clang ; then
  262. myeconfargs+=( --enable-linker=lld )
  263. else
  264. myeconfargs+=( --enable-linker=gold )
  265. fi
  266. fi
  267. # LTO flag was handled via configure
  268. filter-flags '-flto*'
  269. if tc-is-gcc ; then
  270. if ver_test $(gcc-fullversion) -ge 10 ; then
  271. einfo "Forcing -fno-tree-loop-vectorize to workaround GCC bug, see bug 758446 ..."
  272. append-cxxflags -fno-tree-loop-vectorize
  273. fi
  274. fi
  275. # Show flags we will use
  276. einfo "Build CFLAGS: ${CFLAGS}"
  277. einfo "Build CXXFLAGS: ${CXXFLAGS}"
  278. einfo "Build LDFLAGS: ${LDFLAGS}"
  279. einfo "Build RUSTFLAGS: ${RUSTFLAGS}"
  280. # Forcing system-icu allows us to skip patching bundled ICU for PPC
  281. # and other minor arches
  282. ECONF_SOURCE="${S}" \
  283. econf \
  284. ${myeconfargs[@]} \
  285. XARGS="${EPREFIX}/usr/bin/xargs"
  286. }
  287. src_compile() {
  288. cd "${MOZJS_BUILDDIR}" || die
  289. default
  290. }
  291. src_test() {
  292. if "${MOZJS_BUILDDIR}/js/src/js" -e 'print("Hello world!")'; then
  293. einfo "Smoke-test successful, continuing with full test suite"
  294. else
  295. die "Smoke-test failed: did interpreter initialization fail?"
  296. fi
  297. local -a KNOWN_TESTFAILURES
  298. KNOWN_TESTFAILURES+=( non262/Date/reset-time-zone-cache-same-offset.js )
  299. KNOWN_TESTFAILURES+=( non262/Date/time-zone-path.js )
  300. KNOWN_TESTFAILURES+=( non262/Date/time-zones-historic.js )
  301. KNOWN_TESTFAILURES+=( non262/Date/time-zones-imported.js )
  302. KNOWN_TESTFAILURES+=( non262/Date/toString-localized.js )
  303. KNOWN_TESTFAILURES+=( non262/Date/toString-localized-posix.js )
  304. KNOWN_TESTFAILURES+=( non262/Intl/Date/toLocaleString_timeZone.js )
  305. KNOWN_TESTFAILURES+=( non262/Intl/Date/toLocaleDateString_timeZone.js )
  306. KNOWN_TESTFAILURES+=( non262/Intl/DateTimeFormat/format.js )
  307. KNOWN_TESTFAILURES+=( non262/Intl/DateTimeFormat/format_timeZone.js )
  308. KNOWN_TESTFAILURES+=( non262/Intl/DateTimeFormat/timeZone_backward_links.js )
  309. KNOWN_TESTFAILURES+=( non262/Intl/DateTimeFormat/tz-environment-variable.js )
  310. KNOWN_TESTFAILURES+=( non262/Intl/DisplayNames/language.js )
  311. KNOWN_TESTFAILURES+=( non262/Intl/DisplayNames/region.js )
  312. KNOWN_TESTFAILURES+=( non262/Intl/Locale/likely-subtags.js )
  313. KNOWN_TESTFAILURES+=( non262/Intl/Locale/likely-subtags-generated.js )
  314. KNOWN_TESTFAILURES+=( test262/intl402/Locale/prototype/minimize/removing-likely-subtags-first-adds-likely-subtags.js )
  315. if use x86 ; then
  316. KNOWN_TESTFAILURES+=( non262/Date/timeclip.js )
  317. KNOWN_TESTFAILURES+=( test262/built-ins/Number/prototype/toPrecision/return-values.js )
  318. KNOWN_TESTFAILURES+=( test262/language/types/number/S8.5_A2.1.js )
  319. KNOWN_TESTFAILURES+=( test262/language/types/number/S8.5_A2.2.js )
  320. fi
  321. if [[ $(tc-endian) == "big" ]] ; then
  322. KNOWN_TESTFAILURES+=( test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js )
  323. fi
  324. echo "" > "${T}"/known_failures.list || die
  325. local KNOWN_TESTFAILURE
  326. for KNOWN_TESTFAILURE in ${KNOWN_TESTFAILURES[@]} ; do
  327. echo "${KNOWN_TESTFAILURE}" >> "${T}"/known_failures.list
  328. done
  329. PYTHONPATH="${S}/tests/lib" \
  330. ${PYTHON} \
  331. "${S}"/tests/jstests.py -d -s -t 1800 --wpt=disabled --no-progress \
  332. --exclude-file="${T}"/known_failures.list \
  333. "${MOZJS_BUILDDIR}"/js/src/js \
  334. || die
  335. if use jit ; then
  336. KNOWN_TESTFAILURES=()
  337. echo "" > "${T}"/known_failures.list || die
  338. for KNOWN_TESTFAILURE in ${KNOWN_TESTFAILURES[@]} ; do
  339. echo "${KNOWN_TESTFAILURE}" >> "${T}"/known_failures.list
  340. done
  341. PYTHONPATH="${S}/tests/lib" \
  342. ${PYTHON} \
  343. "${S}"/tests/jstests.py -d -s -t 1800 --wpt=disabled --no-progress \
  344. --exclude-file="${T}"/known_failures.list \
  345. "${MOZJS_BUILDDIR}"/js/src/js basic \
  346. || die
  347. fi
  348. }
  349. src_install() {
  350. cd "${MOZJS_BUILDDIR}" || die
  351. default
  352. # fix soname links
  353. pushd "${ED}"/usr/$(get_libdir) &>/dev/null || die
  354. mv lib${MY_PN}-${MY_MAJOR}.so lib${MY_PN}-${MY_MAJOR}.so.0.0.0 || die
  355. ln -s lib${MY_PN}-${MY_MAJOR}.so.0.0.0 lib${MY_PN}-${MY_MAJOR}.so.0 || die
  356. ln -s lib${MY_PN}-${MY_MAJOR}.so.0 lib${MY_PN}-${MY_MAJOR}.so || die
  357. popd &>/dev/null || die
  358. # remove unneeded files
  359. rm \
  360. "${ED}"/usr/bin/js${MY_MAJOR}-config \
  361. "${ED}"/usr/$(get_libdir)/libjs_static.ajs \
  362. || die
  363. # fix permissions
  364. chmod -x \
  365. "${ED}"/usr/$(get_libdir)/pkgconfig/*.pc \
  366. "${ED}"/usr/include/mozjs-${MY_MAJOR}/js-config.h \
  367. || die
  368. }