Skip to content

Commit e910228

Browse files
author
Aztekode
committed
Initial commit (minigui v0.1.0)
0 parents  commit e910228

15 files changed

Lines changed: 28082 additions & 0 deletions

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
build-linux:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Install deps
14+
run: sudo apt-get update -y && sudo apt-get install -y build-essential pkg-config libgtk-3-dev
15+
- name: Build port
16+
run: make port
17+
- name: Prepare asset
18+
run: |
19+
cp -f priv/minigui ./minigui
20+
sha256sum ./minigui > ./minigui.sha256
21+
- uses: actions/upload-artifact@v4
22+
with:
23+
name: linux-assets
24+
path: |
25+
minigui
26+
minigui.sha256
27+
28+
build-windows:
29+
runs-on: windows-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Build port (MSVC)
33+
shell: pwsh
34+
run: |
35+
cl /O2 /Fe:priv\minigui.exe c_src\minigui_port.c user32.lib gdi32.lib
36+
Copy-Item priv\minigui.exe .\minigui.exe -Force
37+
(Get-FileHash .\minigui.exe -Algorithm SHA256).Hash.ToLower() + " minigui.exe" | Out-File -Encoding ascii .\minigui.exe.sha256
38+
- uses: actions/upload-artifact@v4
39+
with:
40+
name: windows-assets
41+
path: |
42+
minigui.exe
43+
minigui.exe.sha256
44+
45+
publish:
46+
needs: [build-linux, build-windows]
47+
runs-on: ubuntu-latest
48+
permissions:
49+
contents: write
50+
steps:
51+
- name: Check tag matches gleam.toml version
52+
run: |
53+
TAG="${GITHUB_REF_NAME}"
54+
VERSION="${TAG#v}"
55+
TOML_VERSION="$(python3 - <<'PY'
56+
import re
57+
import pathlib
58+
txt = pathlib.Path('gleam.toml').read_text(encoding='utf-8')
59+
m = re.search(r'^version\\s*=\\s*\"([^\"]+)\"\\s*$', txt, re.M)
60+
print(m.group(1) if m else '')
61+
PY
62+
)"
63+
echo "tag=$TAG version=$VERSION gleam.toml=$TOML_VERSION"
64+
test -n "$TOML_VERSION"
65+
test "$VERSION" = "$TOML_VERSION"
66+
67+
- uses: actions/download-artifact@v4
68+
with:
69+
path: dist
70+
- name: Create GitHub Release
71+
uses: softprops/action-gh-release@v2
72+
with:
73+
files: |
74+
dist/linux-assets/minigui
75+
dist/linux-assets/minigui.sha256
76+
dist/windows-assets/minigui.exe
77+
dist/windows-assets/minigui.exe.sha256

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Gleam / Erlang build outputs
2+
build/
3+
4+
# Native port binaries (se generan en CI o con `make port`)
5+
priv/minigui
6+
priv/minigui.exe
7+
priv/minigui_port
8+
priv/minigui_port.exe
9+
10+
# OS / tooling
11+
.DS_Store
12+
*.swp
13+
*.swo
14+

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## v0.1.0
4+
5+
- Instalación “sin toolchain”: descarga automática del port desde GitHub Releases, con cache por usuario.
6+
- Protocolo v1 con handshake (`HELLO`/`HELLO_ACK`) y `OK/ERR` por `request_id`.
7+
- Backends:
8+
- Windows: Win32 (Window + Label + TextBox + Button)
9+
- Linux: GTK3 (Window + Label + TextBox + Button)
10+
- API de Gleam basada en `Result` y comandos con ACK.
11+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Aztekode
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PORT_NAME := minigui
2+
PRIV_DIR := priv
3+
C_SRC := c_src/minigui_port.c
4+
5+
UNAME_S := $(shell uname -s 2>/dev/null || echo unknown)
6+
7+
.PHONY: all port gleam demo clean
8+
9+
all: port gleam
10+
11+
$(PRIV_DIR):
12+
mkdir -p $(PRIV_DIR)
13+
14+
port: $(PRIV_DIR)
15+
ifeq ($(UNAME_S),Linux)
16+
$(CC) -O2 -Wall -Wextra -o $(PRIV_DIR)/$(PORT_NAME) $(C_SRC) $$(pkg-config --cflags --libs gtk+-3.0) -pthread
17+
else ifeq ($(UNAME_S),Darwin)
18+
@echo "macOS: por ahora no hay backend nativo. Usa el modo headless (MINIGUI_HEADLESS=1) o implementa Cocoa."
19+
$(CC) -O2 -Wall -Wextra -o $(PRIV_DIR)/$(PORT_NAME) $(C_SRC)
20+
else
21+
@echo "Sistema no reconocido. Compila manualmente c_src/minigui_port.c para tu plataforma."
22+
endif
23+
24+
@# Compatibilidad con el nombre anterior durante desarrollo
25+
@if [ -f "$(PRIV_DIR)/minigui" ]; then cp -f "$(PRIV_DIR)/minigui" "$(PRIV_DIR)/minigui_port"; fi
26+
27+
gleam:
28+
gleam build
29+
30+
demo: port
31+
gleam run -m demo
32+
33+
clean:
34+
rm -rf build $(PRIV_DIR)

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# minigui
2+
3+
`minigui` es una biblioteca experimental para crear interfaces gráficas desde **Gleam (target Erlang)** usando un **port externo en C** (nativo).
4+
5+
## Estado / alcance
6+
7+
- **Windows**: backend **Win32** (ventana + label + textbox + botón).
8+
- **Linux**: backend **GTK3** (ventana + label + textbox + botón).
9+
- **macOS**: por ahora solo **modo headless** (simulado).
10+
11+
> Nota: en Linux el binario `minigui` enlaza con GTK3, por lo que el sistema debe tener GTK3 disponible en runtime (en desktops es común; en servidores minimalistas puede requerir instalar paquetes).
12+
13+
El objetivo es mantener una API pequeña y estable en Gleam, y permitir backends nativos por plataforma.
14+
15+
## Releases / publicación
16+
17+
Ver el checklist: [`RELEASING.md`](./RELEASING.md)
18+
19+
## Instalación (Gleam Packages)
20+
21+
```bash
22+
gleam add minigui
23+
```
24+
25+
### “Sin dependencias de build” (binario precompilado)
26+
27+
Para evitar que tus usuarios tengan que instalar un compilador C o headers (`libx11-dev`, etc.), `minigui` está pensado para usar un **ejecutable precompilado** como puente (un *port*) y descargarlo automáticamente a `priv/` en el primer uso.
28+
29+
Por defecto construye la URL así:
30+
31+
```
32+
https://github.com/Aztekode/minigui/releases/download/v<version>/<asset>
33+
```
34+
35+
Donde `<version>` sale del `vsn` del paquete (ej. `0.1.0`) y `<asset>` depende del OS/arquitectura, por ejemplo:
36+
37+
- `minigui.exe` (Windows x64)
38+
- `minigui` (Linux x64)
39+
40+
Puedes sobreescribir la base de descargas con:
41+
42+
```bash
43+
MINIGUI_RELEASE_BASE_URL="https://github.com/Aztekode/minigui/releases/download/v0.1.0"
44+
```
45+
46+
Si prefieres un enlace exacto tipo `.../minigui.exe`, puedes fijar la URL completa:
47+
48+
```bash
49+
MINIGUI_PORT_URL="https://github.com/Aztekode/minigui/releases/download/v0.1.0/minigui.exe"
50+
```
51+
52+
Opciones de seguridad/cache:
53+
54+
- Por defecto, `minigui` **requiere** que exista `minigui(.exe).sha256` y valida el SHA256.
55+
- `MINIGUI_REQUIRE_SHA=0`: desactiva la validación (no recomendado).
56+
- El binario se cachea por usuario (Linux: `~/.cache/minigui/<version>/`, Windows: `%LOCALAPPDATA%\\minigui\\<version>\\`).
57+
58+
> Requisito de runtime: una instalación “completa” de Erlang/OTP que incluya las aplicaciones estándar `inets` + `ssl` (normalmente ya vienen con OTP; en algunas distros Linux pueden venir en paquetes separados).
59+
60+
## Protocolo (v1)
61+
62+
El port se abre con `open_port(..., [{packet, 2}, binary, ...])`.
63+
64+
- Handshake:
65+
- `0x00` `HELLO` + `u16 version`
66+
- `0xF0` `HELLO_ACK` + `u16 version` + `u32 capabilities`
67+
68+
- Comandos:
69+
- `0x10` `CREATE_WINDOW` + `u32 request_id` + título UTF-8
70+
- `0x11` `SET_LABEL` + `u32 request_id` + texto UTF-8
71+
- `0x12` `SET_TEXT` + `u32 request_id` + texto UTF-8
72+
- `0x13` `ADD_BUTTON` + `u32 request_id` + `u8 id` + etiqueta UTF-8
73+
- `0x14` `RUN` + `u32 request_id`
74+
- `0x15` `QUIT` + `u32 request_id`
75+
- Respuestas:
76+
- `0x70` `OK` + `u32 request_id`
77+
- `0x71` `ERR` + `u32 request_id` + mensaje UTF-8
78+
- Eventos:
79+
- `0x81` `BUTTON_CLICKED` + `u8 id`
80+
- `0x82` `CLOSED`
81+
- `0x83` `LOG` + texto UTF-8
82+
- `0x84` `TEXT_CHANGED` + texto UTF-8
83+
- `0x85` `KEY_DOWN` + `u32 keycode`
84+
- `0x86` `ERROR` + texto UTF-8
85+
86+
## Compilar (Linux)
87+
88+
Requisitos: `gcc`, `make`, `pkg-config`, `libgtk-3-dev`, `Erlang/OTP`, `gleam`.
89+
90+
> Probado con **Gleam v1.17.0**.
91+
92+
```bash
93+
make port
94+
gleam build
95+
make demo
96+
```
97+
98+
Si estás en un entorno sin servidor X (CI/headless), fuerza el modo simulado:
99+
100+
```bash
101+
MINIGUI_HEADLESS=1 make demo
102+
```
103+
104+
## Compilar (Windows)
105+
106+
1. Compila `c_src/minigui_port.c` a `priv/minigui_port.exe` (MSVC o mingw).
107+
2. Ejecuta el demo:
108+
109+
```powershell
110+
gleam build
111+
gleam run -m demo
112+
```
113+
114+
> Nota: el código Win32 está dentro de `#ifdef _WIN32`.

RELEASING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Publicación de minigui (checklist)
2+
3+
Este repositorio publica **dos cosas**:
4+
5+
1. **Paquete Gleam (Hex / Gleam Packages)**: código Gleam + Erlang helper.
6+
2. **Assets nativos (GitHub Releases)**: `minigui` (Linux x64) y `minigui.exe` (Windows x64) + `.sha256`.
7+
8+
La librería descarga el port desde:
9+
10+
```
11+
https://github.com/Aztekode/minigui/releases/download/v<VERSION>/<asset>
12+
```
13+
14+
Por lo tanto, **el tag de git SIEMPRE debe ser `vX.Y.Z`** y la versión del paquete debe ser **`X.Y.Z`**.
15+
16+
---
17+
18+
## 0) Preparación
19+
20+
- Asegúrate de que `gleam.toml` tenga la versión final `X.Y.Z`.
21+
- Actualiza `CHANGELOG.md`.
22+
- (Opcional) corre el demo en headless:
23+
24+
```bash
25+
make port
26+
MINIGUI_HEADLESS=1 gleam run -m demo
27+
```
28+
29+
---
30+
31+
## 1) Crear tag y release (assets nativos)
32+
33+
1. Commit de la versión:
34+
35+
```bash
36+
git add -A
37+
git commit -m "Release vX.Y.Z"
38+
```
39+
40+
2. Tag:
41+
42+
```bash
43+
git tag vX.Y.Z
44+
git push origin main --tags
45+
```
46+
47+
3. GitHub Actions ejecutará el workflow `release.yml` y adjuntará:
48+
- `minigui` + `minigui.sha256`
49+
- `minigui.exe` + `minigui.exe.sha256`
50+
51+
> Nota: el workflow falla si el tag `vX.Y.Z` no coincide con la versión `X.Y.Z` en `gleam.toml`.
52+
53+
---
54+
55+
## 2) Publicar el paquete en Hex / Gleam Packages
56+
57+
En la máquina donde tengas configuradas credenciales de Hex:
58+
59+
```bash
60+
gleam publish
61+
```
62+
63+
Si vas a usar CI para publicar, tendrás que configurar el token correspondiente (no se incluye en este repo).
64+

0 commit comments

Comments
 (0)