cellar-cli-c: client CLI di Cellar reimplementato in C (statico, retrocompatibile)

Reimplementazione fedele di cellar-cli.py (enne2/cellar @ f5216b1) in C99
POSIX.1-2008, mono-thread, senza dipendenze esterne: miniz e' vendored per
deflate/inflate raw, mentre contenitore gzip, multipart/form-data in streaming,
tar PAX/ustar, JSON e client HTTP/1.1 sono scritti a mano.

- 7 comandi (list, upload, download, install, scan-local, wizard-upload,
  wizard-install) con stdout/stderr/exit code identici al client Python
- 30/30 test di parita' (tests/parity_test.sh) contro due server mock
  indipendenti: output a confronto, alberi installati, interop tar con
  tarfile di Python e con GNU tar, archivio C equivalente a quello Python
- build statiche x86-64 / i686 / aarch64: nessun simbolo GLIBC richiesto,
  nessuna syscall moderna (statx/openat2/memfd_create/getrandom), LFS 64 bit,
  resolver DNS di riserva (hosts + query UDP) per glibc statica senza NSS
- miglioramento rispetto all'originale: upload multipart in streaming invece
  di leggere l'intero archivio in RAM
- divergenze volute documentate nel README (help piu' sintetico, mtime dei
  symlink non ripristinato come tarfile, EOF nei prompt, niente TLS)

Build: make | make 32 | make arm64 | make test | make verify
This commit is contained in:
Matteo Benedetto
2026-09-20 17:29:14 +02:00
commit 090005f6b9
40 changed files with 16741 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
# cellar-cli-c — reimplementazione C del client CLI di Cellar
#
# Target principali:
# make -> dist/cellar-cli (x86-64 statico, glibc)
# make 32 -> dist/cellar-cli-i686 (i686 statico, per sistemi 32 bit)
# make arm64 -> dist/cellar-cli-aarch64 (aarch64 statico via cross toolchain)
# make dist -> tutti e tre
# make verify -> controlla dipendenze, simboli GLIBC richiesti, ldd, size
# make test -> parity test contro il client Python (server mock incluso)
# make asan -> build dinamica con AddressSanitizer/UBSan per i test
CC ?= gcc
AARCH64_CC ?= $(HOME)/toolchains/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Wno-unused-parameter
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Isrc -Ithird_party
SRCS := $(wildcard src/*.c) third_party/miniz.c
DIST := dist
NAME := cellar-cli
.PHONY: all 32 arm64 dist verify test asan clean
all: $(DIST)/$(NAME)
$(DIST)/$(NAME): $(SRCS)
@mkdir -p $(DIST)
$(CC) $(CFLAGS) $(CPPFLAGS) -static -static-libgcc -s -o $@ $(SRCS)
$(DIST)/$(NAME)-i686: $(SRCS)
@mkdir -p $(DIST)
$(CC) -m32 $(CFLAGS) $(CPPFLAGS) -static -static-libgcc -s -o $@ $(SRCS)
$(DIST)/$(NAME)-aarch64: $(SRCS)
@mkdir -p $(DIST)
$(AARCH64_CC) $(CFLAGS) $(CPPFLAGS) -static -s -o $@ $(SRCS)
32: $(DIST)/$(NAME)-i686
arm64: $(DIST)/$(NAME)-aarch64
dist: all 32 arm64
# Build dinamica con sanitizzatori: usata dai test di parità.
$(DIST)/$(NAME)-asan: $(SRCS)
@mkdir -p $(DIST)
$(CC) -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer $(CFLAGS) $(CPPFLAGS) -o $@ $(SRCS)
asan: $(DIST)/$(NAME)-asan
verify: all
tests/verify_binary.sh $(DIST)/$(NAME)
test: asan
tests/parity_test.sh
clean:
rm -rf $(DIST) build tests/tmp