Skip to content

[RFC]: Auto-injecting the license header into main.wat #13468

Description

@0PrashantYadav0

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

  1. Should the copyright year always be the current build year (date +'%Y'), or pinned to a fixed value for reproducible builds?
  2. 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

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.

Metadata

Metadata

Labels

EnhancementIssue or pull request for enhancing existing functionality.Needs DiscussionNeeds further discussion.RFCRequest for comments. Feature requests and proposed changes.ToolsIssue or pull request related to project tooling.WebAssemblyIssue involves or relates to WebAssembly.

Fields

No fields configured for Enhancement.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions