Description
This RFC proposes automatically prepending the standard Apache-2.0 license header to every generated WebAssembly text (.wat) file as the final step of a successful make wasm build.
Today, when C source is compiled to WebAssembly, the toolchain emits src/main.wasm (the binary) and src/main.wat (the text format, produced by wasm2wat). wasm2wat emits main.wat without a license header, so the header must currently be pasted into each file by hand after every build. This is tedious, easy to forget, and produces inconsistent copyright years across packages.
Proposed change: add the header injection to a single central script — tools/scripts/compile_wasm — which every repository-level make wasm funnels through:
make wasm PKGS_WASM_PATTERN=... (repo root)
-> tools/make/lib/wasm/Makefile (iterates matched packages)
-> tools/scripts/compile_wasm <pkg> <-- single choke-point
-> compile(): cd src/ && make wasm (per-package Makefile runs wasm2wat)
A new add_license_header() function runs after a successful compile(). It stamps the current year via date +'%Y', iterates the *.wat files in the package src/ directory, and prepends the Apache-2.0 block (matching stdlib's committed .wat convention: ;; line comments, quoted "License"/"AS IS", indented license URL, followed by a single blank line before (module).
The function is idempotent: files already beginning with ;; @license are skipped, so re-running make wasm never produces duplicate headers. When main.wasm is rebuilt, a fresh header-less main.wat is regenerated and the header is re-applied — always present, never doubled.
Related Issues
None
Questions
- Should the copyright year always be the current build year (
date +'%Y'), or pinned to a fixed value for reproducible builds?
- Should coverage extend to running
make wasm directly inside a package's src/ directory (which bypasses compile_wasm)? Doing so would require editing the per-package src/Makefile template and its generator — a much larger change deliberately left out of this RFC.
Other
Implementation notes
- Single-file change:
tools/scripts/compile_wasm. The alternative — editing the $(wat_targets) rule in each package's src/Makefile — would touch 150+ duplicated template files plus the template generator, and is neither DRY nor maintainable.
- Maintainer documentation added at
tools/scripts/WASM_LICENSE_HEADER.md.
Sample output (head -4 src/main.wat after make wasm):
;; @license Apache-2.0
;;
;; Copyright (c) 2026 The Stdlib Authors.
;;
Verification
# Auto-add on rebuild:
rm lib/node_modules/@stdlib/stats/strided/wasm/smeanwd/src/main.wat
make wasm PKGS_WASM_PATTERN="stats/strided/wasm/smeanwd"
head -3 lib/node_modules/@stdlib/stats/strided/wasm/smeanwd/src/main.wat
# Idempotency (prints 1):
make wasm PKGS_WASM_PATTERN="stats/strided/wasm/smeanwd"
grep -c "@license" lib/node_modules/@stdlib/stats/strided/wasm/smeanwd/src/main.wat
Checklist
Description
This RFC proposes automatically prepending the standard Apache-2.0 license header to every generated WebAssembly text (
.wat) file as the final step of a successfulmake wasmbuild.Today, when C source is compiled to WebAssembly, the toolchain emits
src/main.wasm(the binary) andsrc/main.wat(the text format, produced bywasm2wat).wasm2watemitsmain.watwithout a license header, so the header must currently be pasted into each file by hand after every build. This is tedious, easy to forget, and produces inconsistent copyright years across packages.Proposed change: add the header injection to a single central script —
tools/scripts/compile_wasm— which every repository-levelmake wasmfunnels through:A new
add_license_header()function runs after a successfulcompile(). It stamps the current year viadate +'%Y', iterates the*.watfiles in the packagesrc/directory, and prepends the Apache-2.0 block (matching stdlib's committed.watconvention:;;line comments, quoted"License"/"AS IS", indented license URL, followed by a single blank line before(module).The function is idempotent: files already beginning with
;; @licenseare skipped, so re-runningmake wasmnever produces duplicate headers. Whenmain.wasmis rebuilt, a fresh header-lessmain.watis regenerated and the header is re-applied — always present, never doubled.Related Issues
None
Questions
date +'%Y'), or pinned to a fixed value for reproducible builds?make wasmdirectly inside a package'ssrc/directory (which bypassescompile_wasm)? Doing so would require editing the per-packagesrc/Makefiletemplate and its generator — a much larger change deliberately left out of this RFC.Other
Implementation notes
tools/scripts/compile_wasm. The alternative — editing the$(wat_targets)rule in each package'ssrc/Makefile— would touch 150+ duplicated template files plus the template generator, and is neither DRY nor maintainable.tools/scripts/WASM_LICENSE_HEADER.md.Sample output (
head -4 src/main.wataftermake wasm):Verification
Checklist
RFC:.