File nodejs-vscode-oniguruma.spec of Package nodejs-vscode-oniguruma
Name: nodejs-vscode-oniguruma
Version: 1.7.0
# Old versions do not work with binaryen from fedora
%define emscripten_version 3.1.21
%global toolchain clang
Release: 0
Summary: Oniguruma library for Visual Studio Code
License: MIT and BSD-2-Clause and (MIT or NCSA)
Group: Development/Languages/NodeJS
Url: https://github.com/microsoft/vscode-oniguruma
# Created by create-tarball.sh
Source0: vscode-oniguruma-%{version}.tar.xz
Source1: https://github.com/emscripten-core/emscripten/archive/refs/tags/%{emscripten_version}/emscripten-%{emscripten_version}.tar.gz
Source2: emscripten-vendor.tar.xz
Patch0: build-cflags.patch
Source2001: emscripten-cflags.patch
Source3000: musl-add-env-module.patch
Source3001: missing-__stack_chk_fail.patch
BuildArch: noarch
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: binaryen
BuildRequires: libtool
%if 0%{?suse_version} >= 1550 || 0%{?sle_version} >= 150600 || 0%{?fedora}
BuildRequires: clang >= 17
BuildRequires: lld >= 17
BuildRequires: llvm >= 17
%else
BuildRequires: clang17
BuildRequires: lld17
BuildRequires: llvm17
%endif
BuildRequires: nodejs-packaging
BuildRequires: nodejs-electron-devel
%if 0%{?fedora}
BuildRequires: nodejs-npm
BuildRequires: python3
%else
BuildRequires: npm
BuildRequires: python3-base
%endif
Provides: bundled(oniguruma) = 6.9.8
Provides: bundled(emscripten) = %emscripten_version
# this is to be used by electron, not node
%global __nodejs_requires %nil
%description
Oniguruma bindings for VS Code.
This library is used in VS Code and is not intended to grow to have general Oniguruma WASM bindings.
%package devel
Summary: Oniguruma library for Visual Studio Code – development files
Requires: nodejs-vscode-oniguruma = %version
%description devel
Oniguruma bindings for VS Code.
This package provides the typescript declarations needed to develop software using nodejs-vscode-oniguruma.
%prep
%autosetup -p1 -n vscode-oniguruma-%{version}
test $(grep -F 'emsdk activate' .devcontainer/Dockerfile|sed 's/^.*activate //') = %emscripten_version
cd %_builddir
tar -xzf %SOURCE1
cd emscripten-%{emscripten_version}
tar -xJf %SOURCE2
patch -p1 --verbose < %SOURCE2001
patch -p1 --verbose < %SOURCE3000
patch -p1 --verbose < %SOURCE3001
rm -rvf third_party/{ply,websockify,jni/jni.h,*.h,*.c}
%build
export MAKEFLAGS="%{_smp_mflags}"
#remove arch-specific options
export CFLAGS="$(echo "-flto=auto -fvisibility=hidden %{optflags} "|sed 's/ -m\S*//g')"
#remove fedora spec which does not work on clang
export CFLAGS="$(echo "$CFLAGS"|sed 's/ --config \S*//g')"
#does not work with wasm and is useless anyway
export CFLAGS="$(echo "$CFLAGS"|sed 's/ -ffat-lto-objects\S*//g')"
#error: option 'cf-protection=return' cannot be specified on this target
export CFLAGS="$(echo "$CFLAGS"|sed 's/ -fcf-protection\S*//g')"
#debuginfo does not really work with wasm, but -g options have different meaning
export CFLAGS="$(echo "$CFLAGS"|sed 's/ -g\S*//g') -g0"
#linking as PIE does not work anyway with LLVM 17
export CFLAGS="$CFLAGS -fno-pie -fno-pic"
# Do not apped -fno-inline-functions
export CFLAGS="$CFLAGS -sINLINING_LIMIT=0"
#This may be a noarch package, but we still care about the target “hardware”
#The reason is that the compiler (clang) and VM (chromium/V8) are unrelated projects, and clang by default targets an ancient VM version.
#Enable instruction sets that our actual target (Chromium 120 atm) supports.
#See https://webassembly.org/features/ (note: for Electron only the Chromium version is relevant, not the Node version)
HWFLAGS='-matomics -mbulk-memory -mextended-const -mmultivalue -mmutable-globals -mnontrapping-fptoint -mreference-types -msign-ext -mtail-call'
# HWFLAGS="$HWFLAGS -mexception-handling" the compiler crashes on Fedora.
# HWFLAGS="$HWFLAGS -mrelaxed-simd -msimd128" not supported on all hardware, see https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/function-body-decoder-impl.h;l=373
# HWFLAGS="$HWFLAGS -mmultimemory" wasm-opt does not support it yet
HWFLAGS="$HWFLAGS -sMIN_FIREFOX_VERSION=-1 -sMIN_SAFARI_VERSION=-1 -sMIN_EDGE_VERSION=-1 -sMIN_CHROME_VERSION=120"
export CFLAGS="$CFLAGS $HWFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="%{?build_ldflags} $HWFLAGS -s -g0 -Wl,-O2 -Wl,--lto-O2"
export LDFLAGS="$(echo "$LDFLAGS"|sed 's/ --config \S*//g')"
export LDFLAGS="$(echo "$LDFLAGS"| sed 's/ -Wl,--as-needed//')"
export LDFLAGS="$(echo "$LDFLAGS"| sed 's/ -Wl,--build-id=\S*//')"
export LDFLAGS="$(echo "$LDFLAGS"|sed 's/ -ffat-lto-objects\S*//g')"
export PATH="%{_builddir}/emscripten-%{emscripten_version}:%{_libexecdir}/electron-node:$PATH"
# /usr/bin/wasm-opt: error while loading shared libraries: libbinaryen.so: cannot open shared object file: No such file or directory
%if 0%{?sle_version} || 0%{?sle_version} < 150500
export LD_LIBRARY_PATH=%{_libdir}/binaryen
%endif
export BINARYEN="%{_prefix}"
export EMCC_VERBOSE=1
emcc --generate-config
npm rebuild --verbose --foreground-scripts
npm run build-onig||(cat deps/oniguruma/config.log && false)
cat deps/oniguruma/config.log # Includes output from building of Emscripten itself.
mkdir out
npm run build-wasm
npm run build-tsc
npx webpack
cp -l out/onig.wasm release/onig.wasm
%install
mkdir -pv %{buildroot}%{nodejs_sitelib}/vscode-oniguruma
cp -lv package.json %{buildroot}%{nodejs_sitelib}/vscode-oniguruma
cp -lv main.d.ts %{buildroot}%{nodejs_sitelib}/vscode-oniguruma
cp -lrv release %{buildroot}%{nodejs_sitelib}/vscode-oniguruma
%check
export MAKEFLAGS="%{_smp_mflags}"
export CFLAGS="$(echo "-flto=auto -fvisibility=hidden %{optflags} "|sed 's/ -m\S*//g')"
export CFLAGS="$(echo "$CFLAGS"|sed 's/ --config \S*//g')"
export CFLAGS="$(echo "$CFLAGS"|sed 's/ -ffat-lto-objects\S*//g')"
export CFLAGS="$(echo "$CFLAGS"|sed 's/ -fcf-protection\S*//g')"
export CFLAGS="$(echo "$CFLAGS"|sed 's/ -g\S*//g') -g0"
export CFLAGS="$CFLAGS -fno-pie -fno-pic"
export CFLAGS="$CFLAGS -sINLINING_LIMIT=0"
HWFLAGS='-matomics -mbulk-memory -mextended-const -mmultivalue -mmutable-globals -mnontrapping-fptoint -mreference-types -msign-ext -mtail-call'
HWFLAGS="$HWFLAGS -sMIN_FIREFOX_VERSION=-1 -sMIN_SAFARI_VERSION=-1 -sMIN_EDGE_VERSION=-1 -sMIN_CHROME_VERSION=120"
export CFLAGS="$CFLAGS $HWFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="%{?build_ldflags} $HWFLAGS -s -g0 -Wl,-O2 -Wl,--lto-O2"
export LDFLAGS="$(echo "$LDFLAGS"|sed 's/ --config \S*//g')"
export LDFLAGS="$(echo "$LDFLAGS"| sed 's/ -Wl,--as-needed//')"
export LDFLAGS="$(echo "$LDFLAGS"| sed 's/ -Wl,--build-id=\S*//')"
export LDFLAGS="$(echo "$LDFLAGS"|sed 's/ -ffat-lto-objects\S*//g')"
export PATH="%{_builddir}/emscripten-%{emscripten_version}:%{_libexecdir}/electron-node:$PATH"
%if 0%{?sle_version} || 0%{?sle_version} < 150500
export LD_LIBRARY_PATH=%{_libdir}/binaryen
%endif
export BINARYEN="%{_prefix}"
export EMCC_VERBOSE=1
npm test
cd deps/oniguruma
emmake make check || true # The autotools test harness fails to actually run the tests, but compiles them correctly
cd test/.libs
for i in _utf8 _syntax _options c cu _regset _back
do
# add single-threaded otherwise Electron sometimes hangs on exit. Does not happen with “real” Node.
node --single-threaded "test$i"
done
%files
%defattr(-,root,root)
%license LICENSE.txt NOTICES.txt
%dir %{nodejs_sitelib}
%dir %{nodejs_sitelib}/vscode-oniguruma
%{nodejs_sitelib}/vscode-oniguruma/package.json
%{nodejs_sitelib}/vscode-oniguruma/release
%files devel
%{nodejs_sitelib}/vscode-oniguruma/main.d.ts
%changelog