Icone dell'originale e motore linkato con le librerie per aarch64

- icone: icona app dal grumpydove.png 512x512, sprite Eudora per cartelle,
  In/Out/Trash/Junk, account e allegato (BSD 3-Clause, CHM) con licenza e
  nota nel README; via la barra di rientro, ora l'icona e' indentata
- spike: cross_sysroot.py costruisce un sysroot aarch64 dai .deb senza root;
  stub_gui.c/stub_pgp.c sostituiscono Qt e gpg; il motore completo si linka
  con libetpan, gpgme, jansson, curl, gnutls, libxml2 e legge una Maildir
- 0.1.1
This commit is contained in:
Carlo Baratto committed 2026-11-11 11:00:34 +01:00
1 parent 781f015597
commit 102908a265
23 files changed
+475 -18

No files matched your search

+94
View File
@@ -0,0 +1,94 @@
# Spike: il motore di GrumpyDove su ARM
Due prove separate, entrambe riproducibili senza telefono.
## 1. Il motore gira (`run.sh`)
Compila con il cross Debian e esegue in emulazione aarch64:
- un «hello Ada»;
- tutti i file Ada del motore (verifica semantica);
- un programma che legge una Maildir vera con il motore;
- un test di tasking (3 task, protected object, 30.000 incrementi).
```sh
./run.sh /percorso/grumpydove/src
```
## 2. Il motore completo, con gli shim C (questo file)
Serve a provare che il motore si linka **con libetpan, gpgme, jansson, curl,
gnutls e libxml2** — cioè come sarà nell'app — senza Qt e senza telefono.
### Sysroot aarch64 senza root
`cross_sysroot.py` scarica dai repo Debian i `.deb` arm64 delle librerie (e
delle loro dipendenze) e li estrae in un albero locale, da passare come
`--sysroot` al compilatore cross.
```sh
curl -o /tmp/arm64-Packages.xz \
http://ftp.it.debian.org/debian/dists/bookworm/main/binary-arm64/Packages.xz
python3 cross_sysroot.py sysroot /tmp/arm64-Packages.xz # ~120 pacchetti, 67 MB
```
Note che sono costate tempo:
- l'indice va decompresso con `xz` (1,8 s), **non** con `lzma` di Python (oltre
120 s su questo host);
- `libc6` **non** va escluso dalle dipendenze: senza, il linker non trova
`libc.so.6` né `ld-linux-aarch64.so.1`;
- serve anche `zlib1g-dev`, altrimenti `-lz` fallisce;
- il runtime Ada (`libgnat-12.so`, `libgnarl-12.so`) va copiato dal cross dentro
il sysroot, o il binario non parte.
### Compilare e linkare
```sh
SYS=$PWD/sysroot
# Ada (motore)
aarch64-linux-gnu-gnatmake -c -gnat2022 -O2 -Isrc src/grumpydove.adb
# shim C
aarch64-linux-gnu-gcc-12 --sysroot=$SYS -O2 -fPIC -Isrc \
-I$SYS/usr/include/libxml2 -c imap_shim.c jmap_shim.c smtp_bridge.c \
carddav_shim.c image_fetch.c
# stub della vista (gd_run) e di PGP/S-MIME: sostituiscono qt_shim.cpp e
# gpg_shim.cpp, che richiedono Qt 6 e g++, non disponibili nel cross
aarch64-linux-gnu-gcc-12 --sysroot=$SYS -O2 -fPIC -Isrc -c stub_gui.c stub_pgp.c
# link
aarch64-linux-gnu-gnatmake -gnat2022 -O2 -Isrc src/grumpydove.adb -largs *.o \
--sysroot=$SYS -L$SYS/usr/lib/aarch64-linux-gnu \
-letpan -lgpgme -ljansson -lcurl -lgnutls -lxml2 -lz -lpthread -ldl
```
`gnatlink` diretto su questo host risponde `Failed to open binder output`:
si passa da `gnatmake ... -largs`, che fa le stesse cose e funziona.
### Eseguire
```sh
HOME=<cartella con Mail/> qemu-aarch64-static -L $SYS ./grumpydove
```
Esito (11 novembre 2026):
```
--- cartelle viste dal motore (senza Qt) ---
Local / In / Out / Junk / Trash / In / Out / progetti / In / Out
--- messaggio in testa a ogni cartella ---
cartella 5 (In): 1 KB
colonna 1: 3
colonna 4: Luca Bianchi
```
Il motore elenca le cartelle, apre «In», legge il messaggio e ne restituisce i
campi attraverso le callback che riceve dalla vista: è esattamente il contratto
che il bridge QML dovrà fornire.
### Cosa manca
- `gpg_shim.cpp` (OpenPGP e S/MIME veri) richiede `g++-12-aarch64-linux-gnu`,
non installato: nel test è sostituito da `stub_pgp.c`, che risponde «non
incluso in questa build».
- Il sysroot è Debian: prima della consegna va rifatto contro le librerie del
telefono (un `tar` di `/lib` e `/usr/lib` dal device).
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env python3
"""Costruisce un sysroot aarch64 dai .deb di Debian, senza root.
Risolve le dipendenze delle librerie che servono al motore di GrumpyDove
(libetpan, gpgme, jansson, curl, gnutls, libxml2) e le estrae in un albero
locale, da usare come --sysroot del compilatore cross.
Uso: cross_sysroot.py <destinazione> [indice Packages.xz]
"""
import os
import subprocess
import sys
import urllib.request
BASE = "http://ftp.it.debian.org/debian"
ROOTS = ["libetpan-dev", "libjansson-dev", "libgpgme-dev",
"libcurl4-gnutls-dev", "libgnutls28-dev", "libxml2-dev",
"libc6-dev", "zlib1g-dev"]
# gia' forniti dal compilatore cross o non servono per compilare
SKIP = {"libgcc-12-dev", "gcc-12-base", "dpkg", "debconf", "libcrypt1",
"rpcsvc-proto"}
def parse_index(path):
# Python decompresso questo indice in minuti: si usa xz, che lo fa in
# un secondo (verificato: 47 MB in 1,8 s contro oltre 120 s).
text_path = path[:-3] + ".txt" if path.endswith(".xz") else path
if path.endswith(".xz") and not os.path.exists(text_path):
with open(text_path, "w") as out:
subprocess.run(["xz", "-dc", path], stdout=out, check=True)
with open(text_path, "r", encoding="utf-8", errors="replace") as fh:
data = fh.read()
pkgs = {}
for block in data.split("\n\n"):
d = {}
for line in block.split("\n"):
if line[:1] in (" ", "") or ":" not in line:
continue
k, v = line.split(":", 1)
d[k] = v.strip()
if "Package" in d and "Filename" in d:
pkgs[d["Package"]] = d
return pkgs
def deps_of(pkg):
out = []
for field in ("Pre-Depends", "Depends"):
raw = pkg.get(field, "")
for item in raw.split(","):
item = item.strip()
if not item:
continue
first = item.split("|")[0].strip()
name = first.split(" ")[0].split(":")[0]
if name:
out.append(name)
return out
def main():
dest = sys.argv[1] if len(sys.argv) > 1 else "cross-sysroot"
index = sys.argv[2] if len(sys.argv) > 2 else "/tmp/arm64-Packages.xz"
pkgs = parse_index(index)
print("indice:", len(pkgs), "pacchetti")
queue = list(ROOTS)
chosen, missing = {}, set()
while queue:
name = queue.pop()
if name in chosen or name in SKIP:
continue
pkg = pkgs.get(name)
if not pkg:
missing.add(name)
continue
chosen[name] = pkg
queue.extend(deps_of(pkg))
if missing:
print("non trovati (ignorati):", ", ".join(sorted(missing)))
os.makedirs(dest, exist_ok=True)
debs = os.path.join(dest, ".debs")
os.makedirs(debs, exist_ok=True)
total = 0
for name, pkg in sorted(chosen.items()):
fn = pkg["Filename"]
out = os.path.join(debs, os.path.basename(fn))
if not os.path.exists(out):
url = "%s/%s" % (BASE, fn)
urllib.request.urlretrieve(url, out)
total += os.path.getsize(out)
subprocess.run(["dpkg-deb", "-x", out, dest], check=True)
print(" estratto %-28s %s" % (name, pkg.get("Version", "")))
print("pacchetti: %d, scaricati %.1f MB -> %s" % (len(chosen), total / 1e6, dest))
if __name__ == "__main__":
main()
+85
View File
@@ -0,0 +1,85 @@
/* Sostituto della vista Qt per provare il motore senza GUI.
*
* Implementa le due funzioni che il main Ada si aspetta dalla vista
* (gd_single_instance, gd_already_open) e la gd_run: invece di aprire
* finestre, usa le callback che il motore le passa per elencare le cartelle
* e leggere la prima riga della prima cartella. Serve a provare il motore
* completo su ARM senza Qt.
*/
#include <stdio.h>
#include <string.h>
#include "qt_shim.h"
int gd_single_instance(void) { return 1; }
void gd_already_open(void) { printf("un'altra istanza e' aperta\n"); }
int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
gd_body_fn body, gd_sort_fn sort, gd_read_fn mark_read,
gd_id_of_fn id_of, gd_row_of_fn row_of, gd_move_fn move,
gd_commit_fn commit, gd_empty_fn empty, gd_log_fn log,
gd_set_fn priority, gd_set_fn label, gd_text_fn decrypt,
gd_text_fn sender, gd_text_fn key_of, gd_header_fn header,
gd_text_fn plain, gd_text_fn sheet, gd_compose_fn compose,
gd_filter_fn filter, gd_last_id_fn last_id,
gd_find_start_fn find_start, gd_find_poll_fn find_poll,
gd_find_cancel_fn find_cancel, gd_id_named_fn id_named,
gd_claim_fn claim, gd_send_done_fn send_done,
gd_send_start_fn send_start, gd_find_poll_fn send_poll,
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
gd_absorb_fn absorb, gd_rescan_fn rescan, gd_shown_at_fn shown_at,
gd_can_hold_fn can_hold, gd_make_folder_fn make_folder,
gd_can_hold_fn can_change, gd_make_folder_fn change_folder,
gd_can_hold_fn forget, gd_can_hold_fn has_box,
gd_place_fn place, gd_find_start_fn imap_create,
gd_find_start_fn book_start, gd_find_poll_fn book_poll,
gd_place_fn book_list, gd_queue_sent_fn queue_sent, gd_text_fn html,
gd_text_fn images, gd_text_fn attachments, gd_text_fn path,
gd_can_hold_fn unread)
{
char buf[512];
long total_k = 0;
int depth = 0, len, i;
(void)body; (void)sort; (void)mark_read; (void)id_of; (void)row_of;
(void)move; (void)commit; (void)empty; (void)log; (void)priority;
(void)label; (void)decrypt; (void)sender; (void)key_of; (void)header;
(void)plain; (void)sheet; (void)compose; (void)filter; (void)last_id;
(void)find_start; (void)find_poll; (void)find_cancel; (void)id_named;
(void)claim; (void)send_done; (void)send_start; (void)send_poll;
(void)imap_start; (void)imap_poll; (void)absorb; (void)rescan;
(void)shown_at; (void)can_hold; (void)make_folder; (void)can_change;
(void)change_folder; (void)forget; (void)has_box; (void)place;
(void)imap_create; (void)book_start; (void)book_poll; (void)book_list;
(void)queue_sent; (void)html; (void)images; (void)attachments;
(void)path; (void)unread;
printf("--- cartelle viste dal motore (senza Qt) ---\n");
for (i = 0; i < 40; i++) {
len = folder(i, &depth, buf, (int)sizeof buf);
if (len < 0) break;
if (len > (int)sizeof buf) len = (int)sizeof buf;
buf[len] = '\0';
printf("%*s%s\n", depth * 2, "", buf);
}
printf("--- messaggio in testa a ogni cartella ---\n");
for (i = 0; i < 40; i++) {
char name[512];
int d = 0, n = folder(i, &d, name, (int)sizeof name - 1);
if (n < 0) break;
if (n > (int)sizeof name - 1) n = (int)sizeof name - 1;
name[n] = '\0';
total_k = 0;
if (open(i, &total_k) == 0 || total_k == 0) continue;
printf("cartella %d (%s): %ld KB\n", i, name, total_k);
for (int c = 0; c < 5; c++) {
len = cell(i, 0, c, buf, (int)sizeof buf - 1);
if (len <= 0) continue;
if (len > (int)sizeof buf - 1) len = (int)sizeof buf - 1;
buf[len] = '\0';
printf(" colonna %d: %s\n", c, buf);
}
}
return 0;
}
+83
View File
@@ -0,0 +1,83 @@
/* Sostituto dello shim OpenPGP per il test di link senza Qt.
*
* gpg_shim.cpp e' C++ e usa gpgme: qui le stesse funzioni rispondono
* "non disponibile", cosi' il motore si linka e gira per tutto il resto.
* Le firme sono quelle di gpg_shim.h.
*/
#include <string.h>
static void dire(char *status, int cap, const char *msg)
{
if (status && cap > 0) {
strncpy(status, msg, (size_t)cap - 1);
status[cap - 1] = '\0';
}
}
int gd_pgp_verify_detached(const char *data, int len, const char *sig,
int sig_len, char *status, int cap)
{
(void)data; (void)len; (void)sig; (void)sig_len;
dire(status, cap, "OpenPGP non incluso in questa build");
return -1;
}
int gd_pgp_verify_clear(const char *data, int len, char *status, int cap)
{
(void)data; (void)len;
dire(status, cap, "OpenPGP non incluso in questa build");
return -1;
}
int gd_pgp_decrypt(const char *data, int len, char **plain, int *plain_len,
char *status, int cap)
{
(void)data; (void)len;
if (plain) *plain = NULL;
if (plain_len) *plain_len = 0;
dire(status, cap, "OpenPGP non incluso in questa build");
return -1;
}
int gd_pgp_protect(const char *data, int len, int mode, const char *recipients,
const char *signer, char **output, int *output_len,
char *micalg, int micalg_cap, char *status, int cap)
{
(void)data; (void)len; (void)mode; (void)recipients; (void)signer;
(void)micalg; (void)micalg_cap;
if (output) *output = NULL;
if (output_len) *output_len = 0;
dire(status, cap, "OpenPGP non incluso in questa build");
return -1;
}
void gd_pgp_free(char *plain) { (void)plain; }
/* S/MIME (gpgsm), stesso trattamento: non incluso in questa build. */
int gd_smime_verify_detached(const char *data, int len, const char *sig,
int sig_len, char *status, int cap)
{
(void)data; (void)len; (void)sig; (void)sig_len;
dire(status, cap, "S/MIME non incluso in questa build");
return -1;
}
int gd_smime_decrypt(const char *data, int len, char **plain, int *plain_len,
char *status, int cap)
{
(void)data; (void)len;
if (plain) *plain = NULL;
if (plain_len) *plain_len = 0;
dire(status, cap, "S/MIME non incluso in questa build");
return -1;
}
int gd_smime_open_signed(const char *data, int len, char **plain,
int *plain_len, char *status, int cap)
{
(void)data; (void)len;
if (plain) *plain = NULL;
if (plain_len) *plain_len = 0;
dire(status, cap, "S/MIME non incluso in questa build");
return -1;
}