initial import (rhbz#2245271)

This commit is contained in:
Jan Staněk 2023-09-21 12:34:06 +02:00
parent e568d6b933
commit 22eeff3c0d
No known key found for this signature in database
GPG Key ID: 2972F2037B243B6D
4 changed files with 163 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/cjs-module-lexer-1.2.3.tar.gz
/cjs-module-lexer-1.2.3-nm-dev.tgz
/cjs-module-lexer-1.2.3-bundled-licenses.txt

View File

@ -0,0 +1,89 @@
From 182e2768a4029365144d287257be0ca606c0ab40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= <jstanek@redhat.com>
Date: Mon, 26 Jun 2023 09:05:38 +0200
Subject: [PATCH] Parametrize WASM compilation process (#87)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Makefile: extract compilation flags to variables
Previously, the WASM compilation step was hard to adjust for different
systems, as it required re-writing the actual rule.
This change extracts all the flags into make variables,
and separates them into system- and project-specific ones.
The system-specific ones are expected to change from machine to machine,
and now can be easily overridden:
$ make WASM_CC=clang WASM_CFLAGS=--target=wasm32-wasi …
The project-specific flags are also extracted to variables,
although at this point this is mainly for consistency sake.
* Makefile: parametrize all binaries
Similarly to previous change,
this allows for all binary paths to be easily adjusted.
* Makefile: polish
Tiny leftover nitpicks:
- Mark `optimize` and `clean` targets as phony
- Use separate target for `lib/` directory creation
- Use make's built-in `$(RM)` command
---
Makefile | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index 3098484..961b336 100755
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,33 @@
-lslib/lexer.wat: lib/lexer.wasm
- ../wabt/bin/wasm2wat lib/lexer.wasm -o lib/lexer.wat
+# These flags depend on the system and may be overridden
+WASM_CC := ../wasi-sdk-12.0/bin/clang
+WASM_CFLAGS := --sysroot=../wasi-sdk-12.0/share/wasi-sysroot
+WASM_LDFLAGS := -nostartfiles
-lib/lexer.wasm: include-wasm/cjs-module-lexer.h src/lexer.c
- @mkdir -p lib
- ../wasi-sdk-12.0/bin/clang src/lexer.c -I include-wasm --sysroot=../wasi-sdk-12.0/share/wasi-sysroot -o lib/lexer.wasm -nostartfiles \
- -Wl,-z,stack-size=13312,--no-entry,--compress-relocations,--strip-all,--export=__heap_base,\
- --export=parseCJS,--export=sa,--export=e,--export=re,--export=es,--export=ee,--export=rre,--export=ree,--export=res,--export=ru,--export=us,--export=ue \
- -Wno-logical-op-parentheses -Wno-parentheses \
- -Oz
+WASM2WAT := ../wabt/bin/wasm2wat
+WASM_OPT := ../binaryen/bin/wasm-opt
+
+# These are project-specific and are expected to be kept intact
+WASM_EXTRA_CFLAGS := -I include-wasm/ -Wno-logical-op-parentheses -Wno-parentheses -Oz
+WASM_EXTRA_LDFLAGS := -Wl,-z,stack-size=13312,--no-entry,--compress-relocations,--strip-all
+WASM_EXTRA_LDFLAGS += -Wl,--export=__heap_base,--export=parseCJS,--export=sa
+WASM_EXTRA_LDFLAGS += -Wl,--export=e,--export=re,--export=es,--export=ee
+WASM_EXTRA_LDFLAGS += -Wl,--export=rre,--export=ree,--export=res,--export=ru,--export=us,--export=ue
+
+.PHONY: optimize clean
+
+lib/lexer.wat: lib/lexer.wasm
+ $(WASM2WAT) lib/lexer.wasm -o lib/lexer.wat
+
+lib/lexer.wasm: include-wasm/cjs-module-lexer.h src/lexer.c | lib/
+ $(WASM_CC) $(WASM_CFLAGS) $(WASM_EXTRA_CFLAGS) \
+ src/lexer.c -o lib/lexer.wasm \
+ $(WASM_LDFLAGS) $(WASM_EXTRA_LDFLAGS)
+
+lib/:
+ @mkdir -p $@
optimize: lib/lexer.wasm
- ../binaryen/bin/wasm-opt -Oz lib/lexer.wasm -o lib/lexer.wasm
+ $(WASM_OPT) -Oz lib/lexer.wasm -o lib/lexer.wasm
clean:
- rm lib/*
+ $(RM) lib/*

View File

@ -0,0 +1,68 @@
%global npm_name cjs-module-lexer
%global prebuilt_blobs lib/lexer.wasm
Name: nodejs-%{npm_name}
Summary: A very fast lexer used to detect the named exports of a CommonJS module
Version: 1.2.3
Release: %autorelease
License: MIT
URL: https://www.npmjs.com/package/cjs-module-lexer
# The npmjs.org archive does not contain sources, only built artifacts
Source: https://github.com/nodejs/%{npm_name}/archive/%{version}/%{npm_name}-%{version}.tar.gz
# Production archive is not needed
Source2: %{npm_name}-%{version}-nm-dev.tgz
Source3: %{npm_name}-%{version}-bundled-licenses.txt
# Adapt Makefile for easier rebuilds
Patch: 0001-parametrize-wasm-compilation-process.patch
# Binary files in this package are aimed at the wasm32-wasi "architecture".
%global _binaries_in_noarch_packages_terminate_build 0
BuildArch: noarch
ExclusiveArch: %{nodejs_arches} noarch
BuildRequires: clang lld make wasi-libc-devel
BuildRequires: nodejs-devel npm
# for autosetup -S git_am
BuildRequires: git-core
%description
A very fast JS CommonJS module syntax lexer used to detect the most likely list
of named exports of a CommonJS module. This project is used in Node.js core
for detecting the named exports available when importing a CJS module into ESM,
and is maintained for this purpose.
%prep
%autosetup -n %{npm_name}-%{version} -S git_am
cp -p %{S:3} .
%build
rm -rf %{prebuilt_blobs}
tar -xzf %{S:2} && ln -rsf node_modules_dev node_modules
%make_build -j1 \
WASM_CC=clang \
WASM_CFLAGS='--target=wasm32-wasi --sysroot=/usr/wasm32-wasi' \
WASM_LDFLAGS='-nostartfiles -nodefaultlibs -lc' \
clean lib/lexer.wasm
npm --offline run build
npm --offline pack
%install
mkdir -p %{buildroot}%{nodejs_sitelib}/%{npm_name}
tar --strip-components=1 -xzf %{npm_name}-%{version}.tgz -C %{buildroot}%{nodejs_sitelib}/%{npm_name}
%check
%{__nodejs} -e 'require("./")'
%nodejs_symlink_deps --check
npm --offline run test
%files
%license LICENSE %{npm_name}-%{version}-bundled-licenses.txt
%doc README.md
%{nodejs_sitelib}/%{npm_name}/
%changelog
%autochangelog

3
sources Normal file
View File

@ -0,0 +1,3 @@
SHA512 (cjs-module-lexer-1.2.3.tar.gz) = dab77f606c0b0c12abf9e91994cd56b3492e45ecb6e615236abb948fa2a66146d25776bb895b4b25a1b3cb15168eb073b07ff405da47d3b2a1e62428171b4f76
SHA512 (cjs-module-lexer-1.2.3-nm-dev.tgz) = 44d91bfe4e782a47d0506ec5d0bf12877083b263222535019efd0e0d50614d6688edde17571025ddd9c8f1c2a428974bfb59ee9d9c97d1b7e20150785cfab3de
SHA512 (cjs-module-lexer-1.2.3-bundled-licenses.txt) = 3e591adb16e09b1c6fb75eb97a6ac51cd06e0aeae2bd5950a15902346e2c9626cb50203bfd0e15c7e8c98af8f24b81c1ce6617c359e7c0e7d0a6366457c844ba