Something went wrong. Try again.
Converting between UTF-8 and legacy character encodings, as the WHATWG Encoding Standard and glibc's iconv define them.
Something went wrong. Try again.
zig-charset CONTRIBUTING.md
Contributing to zig-charset #
Issues and pull requests go to the Tangled mirror, https://tangled.org/jcollie.dev/zig-charset.
Setting up #
Everything runs inside the Nix devshell, which provides Zig 0.17.1, Python
for the crosschecks, glibc 2.44 for the glibc ones, and reuse:
nix develop
What a change has to pass #
CI (.forgejo/workflows/test.yaml) runs all of these, and a change should
pass them locally first:
nix develop -c reuse lint # every file has a licence
nix develop -c zig fmt --check . # formatting
nix develop -c zig build test --summary all # unit, conformance and fuzz seeds
nix develop -c zig build check # tools nothing else compiles
nix develop -c zig build gen-tables && git diff --exit-code -- src/tables
nix develop -c python3 tools/crosscheck.py # against CPython's codecs
nix develop -c python3 tools/glibc_names.py --check
nix develop -c python3 tools/crosscheck_glibc.py # against glibc's iconv
nix develop -c zig build fuzz-run -- --iterations=200000
The rules the code keeps #
- Three definitions of an encoding are kept apart.
Encodingis the WHATWG Encoding Standard's closed set, and onlyEncoding.fromLabelresolves labels. EBCDIC and the Korean encodings outside the standard are reached only by naming them in code.Glibcis glibc 2.44's charsets, and onlyGlibc.lookupresolves glibc's names. Nothing outside the standard goes intoEncoding.GLOSSARY.mdhas the words for these, anddocs/adr/has the reasons. - Tables come from published sources. The files in
data/are copies of what the WHATWG and Unicode.org publish, kept byte for byte, andsrc/tables/is generated from them byzig build gen-tables. Never edit a generated table by hand. - glibc is checked against, never copied from. A glibc charset is built
from a table the library already has, plus exceptions observed from glibc
and written in our own words (
src/codecs/glibc_single_byte.zigshows the shape). The one thing taken from glibc is the list of its names,data/glibc-names.txt, whichtools/glibc_names.pywrites. - A
Glibcmember matches glibc exactly. Adding one meanstools/crosscheck_glibc.pyfinds no difference on any input. A charset that is close but not exact stays out, andGlibc.lookupreports it as unsupported. Every exception goes in the README's list of differences. - The WHATWG codecs do not change for glibc's sake. A glibc variant is a
flag on a shared codec, or a codec of its own, and
tools/crosscheck.pyshould print exactly what it printed before. - Tests do not read the tables they test. A conformance test's expected value comes from the standard's worked examples or from arithmetic done by hand. The crosschecks are what cover every input.
Moving to a new glibc #
The glibc tools refuse to run on any glibc but the one in GLIBC_VERSION, so
a nixpkgs update that moves glibc fails CI on purpose. To move:
- Change
GLIBC_VERSIONintools/glibc_names.pyandtools/crosscheck_glibc.py. - Run
tools/glibc_names.pyandzig build gen-tables, and read the diff todata/glibc-names.txt. - Run
tools/crosscheck_glibc.py. Fix or remove any charset that no longer matches. - Update the version wherever the README,
src/glibc.zigandGLOSSARY.mdname it.
Licensing #
Code is MIT, and every file carries an SPDX header or is covered by
REUSE.toml. A new data file from somewhere else needs an annotation there
giving its own licence, as the WHATWG and Unicode files have.