diff options
author | Robin Jarry <robin@jarry.cc> | 2023-01-17 14:33:09 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-26 00:20:45 +0100 |
commit | 3191ee171c435a43912264b131340af66fea8112 (patch) | |
tree | 2a68c5c4a3b9975d102cb379171548e7a8937da5 /Makefile | |
parent | a8b6693f7e7bdcc8b73c3fa0baa0ef5f51993dc7 (diff) | |
download | aerc-3191ee171c435a43912264b131340af66fea8112.tar.gz |
filters: rewrite wrap in c
This utility introduced in commit c9524d265793 ("filters: add wrap
utility written in go") allows to reflow text to view emails that have
very long lines without breaking quotes, lists and indentation.
For such a simple task, go produces a binary that is 2.0M bytes on disk.
After stripping debugging symbols, it can be reduced to 1.2M bytes. All
of this for 267 lines of source code. This is a bit ridiculous, provided
people may load this binary into memory multiple times per minute. This
tool is a small side-project that seems not suitable for golang.
Rewrite it in C. It now only depends on a POSIX libc to run. It is safe
to assume that there is one available on all *NIX systems in the world
of 2023. The resulting binary is now 27K bytes (15K after stripping).
To build it, a C compiler and libc headers are required. These should
most likely be available since they are dependencies of the go compiler
toolchain.
I have tested compilation (with clang-analyzer and gcc -fanalyzer) and
basic operation on FreeBSD, Fedora (glibc) and Alpine (musl libc). More
tests would probably be required on MacOSX and older Linux distros.
I also added test vectors to give some confidence that this works as
expected.
Update CI with aggressive gcc hardening flags and to run these tests
with valgrind --leak-check=full.
Command line options are unchanged:
usage: wrap [-h] [-w INT] [-r] [-l INT] [-f FILE]
Wrap text without messing up email quotes.
options:
-h show this help message
-w INT preferred wrap margin (default 80)
-r reflow all paragraphs even if no trailing space
-l INT minimum percentage of letters in a line to be considered
a paragaph
-f FILE read from filename (default stdin)
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Maxwell G <gotmax@e.email>
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -54,9 +54,11 @@ _!=grep -sqFx '$(build_cmd)' .aerc.d || rm -f .aerc.d aerc: $(GOSRC) .aerc.d $(build_cmd) -wrap: filters/wrap.go .aerc.d - $(GO) build $(BUILD_OPTS) $(GOFLAGS) -ldflags "$(GO_EXTRA_LDFLAGS)" \ - -o wrap filters/wrap.go +CC?=cc +CFLAGS?=-O2 -g + +wrap: filters/wrap.c + $(CC) $(CFLAGS) $(LDFLAGS) -o wrap filters/wrap.c .PHONY: dev dev: @@ -72,7 +74,8 @@ linters.so: contrib/linters.go .PHONY: lint lint: linters.so - @contrib/check-whitespace `git ls-files` && echo white space ok. + @contrib/check-whitespace `git ls-files ':!:filters/vectors'` && \ + echo white space ok. @$(GO) run mvdan.cc/gofumpt -d . | grep ^ \ && echo The above files need to be formatted, please run make fmt && exit 1 \ || echo all files formatted. @@ -83,8 +86,9 @@ vulncheck: $(GO) run golang.org/x/vuln/cmd/govulncheck@latest ./... .PHONY: tests -tests: +tests: wrap $(GO) test $(GOFLAGS) ./... + filters/test.sh .PHONY: debug debug: aerc.debug @@ -109,7 +113,7 @@ doc: $(DOCS) RM?=rm -f clean: - $(RM) $(DOCS) aerc + $(RM) $(DOCS) aerc wrap install: $(DOCS) aerc wrap mkdir -m755 -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 $(DESTDIR)$(MANDIR)/man5 $(DESTDIR)$(MANDIR)/man7 \ |