Blob Blame History Raw
%global major 102

# LTO - Enable in Release builds, but consider disabling for development as it increases compile time
%global build_with_lto    1

# Require tests to pass?
%global require_tests     1

%if 0%{?build_with_lto}
# LTO is the default
%define _lto_cflags %{nil}

# Big endian platforms
%ifarch ppc ppc64 s390 s390x
%global big_endian 1

Name:           mozjs%{major}
Version:        102.15.1
Release:        %autorelease
Summary:        SpiderMonkey JavaScript library

License:        MPL-2.0 AND Apache-2.0 AND BSD-3-Clause AND BSD-2-Clause AND MIT AND GPL-3.0-or-later

# Known failures with system libicu
Source1:        known_failures.txt

# Patches from mozjs68, rebased for mozjs78:
Patch01:        fix-soname.patch
Patch02:        copy-headers.patch
Patch03:        tests-increase-timeout.patch
Patch10:        icu_sources_data-Write-command-output-to-our-stderr.patch

# Build fixes -
Patch12:        emitter.patch
Patch13:        tests-Use-native-TemporaryDirectory.patch

# Build fixes
Patch14:        init_patch.patch
Patch15:        remove-sloppy-m4-detection-from-bundled-autoconf.patch

# tentative patch for RUSTFLAGS parsing issue, taken from firefox package:
Patch16:        firefox-112.0-commasplit.patch

Patch17:        Replace-distutils.LooseVersion-with-looseversion.LooseVersion.patch
# This is ugly, I know, I know...
Patch18:        Hacky-workaround-for-expected-string-or-bytes-like-object.patch

# TODO: Check with mozilla for cause of these fails and re-enable spidermonkey compile time checks if needed
Patch20:        spidermonkey_checks_disable.patch

# s390x/ppc64 fixes
Patch21:        0001-Skip-failing-tests-on-ppc64-and-s390x.patch

BuildRequires:  cargo
%if !0%{?rhel}
BuildRequires:  ccache
BuildRequires:  clang-devel
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  m4
BuildRequires:  make
%if !0%{?rhel}
BuildRequires:  nasm
BuildRequires:  libicu-devel
BuildRequires:  llvm
BuildRequires:  rust
BuildRequires:  rustfmt
BuildRequires:  perl-devel
BuildRequires:  pkgconfig(libffi)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-looseversion
BuildRequires:  python3-six
BuildRequires:  readline-devel
BuildRequires:  wget
BuildRequires:  zip

SpiderMonkey is the code-name for Mozilla Firefox's C++ implementation of
JavaScript. It is intended to be embedded in other applications
that provide host environments for JavaScript.

%package        devel
Summary:        Development files for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%autosetup -n firefox-%{version}/js/src -N

pushd ../..
%autopatch -p1

# Purge the bundled six library incompatible with Python 3.12
rm third_party/python/six/

# Link the system six library (build tooling expects that)
ln -s /usr/lib/python%{python3_version}/site-packages/ third_party/python/six/

# Set up looseversion
mkdir third_party/python/looseversion
ln -s /usr/lib/python%{python3_version}/site-packages/looseversion/ third_party/python/looseversion/
echo "vendored:third_party/python/looseversion" >>  python/sites/mach.txt

# Copy out the LICENSE file
cp LICENSE js/src/

# Copy out file containing known test failures with system libicu
cp %{SOURCE1} js/src/

# Remove zlib directory (to be sure using system version)
rm -rf modules/zlib

# Remove unneeded bundled stuff
rm -rf js/src/devtools/automation/variants/
rm -rf js/src/octane/
rm -rf js/src/ctypes/libffi/


%if 0%{?build_with_lto}

# Use bundled autoconf
export M4=m4
export AWK=awk
export AC_MACRODIR=/builddir/build/BUILD/firefox-%{version}/build/autoconf/

sh ../../build/autoconf/ --localdir=/builddir/build/BUILD/firefox-%{version}/js/src > configure
chmod +x configure

%configure \
  --with-system-icu \
  --with-system-zlib \
  --disable-tests \
  --disable-strip \
  --with-intl-api \
  --enable-readline \
  --enable-shared-js \
  --enable-optimize \
  --disable-debug \
  --enable-pie \



# Fix permissions
chmod -x %{buildroot}%{_libdir}/pkgconfig/*.pc

# Avoid multilib conflicts
case `uname -i` in
  i386 | ppc | s390 | sparc )
  x86_64 | ppc64 | s390x | sparc64 )

if test -n "$wordsize"
  mv %{buildroot}%{_includedir}/mozjs-%{major}/js-config.h \

  cat >%{buildroot}%{_includedir}/mozjs-%{major}/js-config.h <<EOF

#include <bits/wordsize.h>

#if __WORDSIZE == 32
# include "js-config-32.h"
#elif __WORDSIZE == 64
# include "js-config-64.h"
# error "unexpected value for __WORDSIZE macro"



# Remove unneeded files
rm %{buildroot}%{_bindir}/js%{major}-config
rm %{buildroot}%{_libdir}/libjs_static.ajs

# Rename library and create symlinks, following fix-soname.patch
mv %{buildroot}%{_libdir}/libmozjs-%{major}.so \
ln -s libmozjs-%{major}.so.0.0.0 %{buildroot}%{_libdir}/libmozjs-%{major}.so.0
ln -s libmozjs-%{major}.so.0 %{buildroot}%{_libdir}/libmozjs-%{major}.so

# Run SpiderMonkey tests
%if 0%{?require_tests}
%{python3} tests/ -d -s -t 2400 --exclude-file=known_failures.txt --no-progress --wpt=disabled ../../js/src/dist/bin/js%{major}
%{python3} tests/ -d -s -t 2400 --exclude-file=known_failures.txt --no-progress --wpt=disabled ../../js/src/dist/bin/js%{major} || :

# Run basic JIT tests
%if 0%{?require_tests}

# large-arraybuffers/basic.js fails on s390x
%ifarch s390 s390x
%{python3} jit-test/ -s -t 2400 --no-progress -x large-arraybuffers/basic.js ../../js/src/dist/bin/js%{major} basic
%{python3} jit-test/ -s -t 2400 --no-progress ../../js/src/dist/bin/js%{major} basic

%{python3} jit-test/ -s -t 2400 --no-progress ../../js/src/dist/bin/js%{major} basic || :

%doc README.html
%license LICENSE

%files devel