gawk — GNU awk for WASIX
GNU awk 5.3.2 (Debian trixie's version), built for WASIX. Reads files, reads pipes, and keeps the whole gawk language.
wasmer run icedcoffee/gawk -- '{ print NR": "$0 }' file.txt
printf 'a 1\nb 2\n' | wasmer run icedcoffee/gawk -- '{ s += $2 } END { print s }'
wasmer run icedcoffee/gawk -- -f prog.awk file.txt
What is in the package
gawk (and an awk command pointing at the same module):
BEGIN/END/BEGINFILE/ENDFILE, user functions, arrays of arrays,
getline (plain, from a file, from a pipe, and cmd |& getline coprocess),
-F, -v, -f, -i includefile, -e, -b, -c, -l (no extensions are
built in), --posix, --traditional, printf, the full string/number function
set, PROCINFO, RT, FIELDWIDTHS, FPAT, and gawk's gensub/strtonum/
asort/asorti.
The @include/@load extension mechanism and MPFR are not compiled in.
Verified
$ printf 'a 1\nb 2\nc 3\n' | gawk '{ s += $2 } END { printf "rows=%d sum=%d\n", NR, s }'
rows=3 sum=6
$ printf 'hi\n' | gawk '{ print toupper($0) }'
HI
$ gawk '{ print NR": "$0 }' file.txt
1: x
$ gawk 'BEGIN { print 2+3 }'
5
Spread over two patches
os_isreadable()inposix/gawkmisc.cdecides whether an input descriptor is usable by switching onst_mode & S_IFMT. WASIX reports no type bits at all for some descriptors — a pipe on stdin arrives as mode0— so the switch fell through todefaultand gawk refused it withcannot open file '-' for reading: Success. An unknown type is now treated as readable: the descriptor is already open, which is the only fact that matters.- asyncify. gawk longjmps out of its error and signal paths, and on WASIX
longjmpisstack_checkpoint, which the runtime drives through the module's asyncify exports. Without it every run exits 45 before printing anything.
Building
./configure --host=wasm32-wasi --build=x86_64-linux-gnu --disable-nls \
--disable-mpfr --disable-extensions
make
wasm-opt --asyncify --enable-threads --enable-bulk-memory gawk -o gawk.wasm
with -matomics -mbulk-memory -pthread -mthread-model posix -ftls-model=local-exec, -Wl,--shared-memory -Wl,--import-memory -Wl,--max-memory=4294967296 and the __heap_base/__stack_pointer/
__wasm_init_tls/__tls_* exports. 830 KiB raw, 3.0 MB asyncified.
License: GPL-3.0-or-later, as upstream.