Porting software
Mizu has a C library: musl, with a layer that answers Linux's system calls from
Mizu's. Ordinary portable C builds for it with its usual configure and
make. curl, NetSurf and FFmpeg came over this way.
The tools
The easy way: download the ready SDK (about 84 MB), unpack it, and
everything below is already built. From Mizu's source instead, build musl into the SDK once, then use sdk/koi-gcc wherever a build wants a C
compiler. It is your host's GCC with Mizu's headers, start-up code and linker script.
ports/musl/build.sh # sdk/libc: headers and libc.a (not needed with the archive)
sdk/koi-g++ -O2 game.cpp -o GAME.EXE # C++, with libstdc++
sdk/koi-gcc -O2 hello.c -o HELLO.EXE # one file, from any folder
# Autotools
./configure --host=x86_64-linux-musl CC=/path/to/sdk/koi-gcc \
AR=ar RANLIB=ranlib --disable-shared
make
With the C library a program is ordinary C: #include <stdio.h> and
int main(int argc, char** argv), not the main(const char* arguments) of a
koi.h program.
#include <stdio.h>
int main(int argc, char** argv) {
printf("Hello from musl, %d argument(s)\n", argc - 1);
return 0;
}
What comes out is a static, position-independent ELF program. Name it .EXE, copy
it to a Mizu drive and run it from the Command Prompt or the Run box. printf
goes to the Command Prompt it was started from.
Libraries already in the SDK
Each is built by a script in ports/ and installs into sdk/libc,
with a .pc file in sdk/libc/lib/pkgconfig for
pkg-config.
| Script | What it gives |
|---|---|
ports/libs/build.sh | zlib, libpng, libjpeg-turbo, expat, FreeType |
ports/mbedtls/build.sh | Mbed TLS: TLS and cryptography |
ports/curl/build.sh | libcurl with https, and CURL.EXE |
ports/llvm, ports/libdrm, ports/mesa | OpenGL: -lGL (Mesa's OSMesa, with llvmpipe) |
ports/sdl2/build.sh | SDL 2: windows on the desktop (or the whole screen), keys, the pointer and sound |
ports/ffmpeg/build.sh | FFmpeg's decoders, demuxers, libswscale and libswresample |
ports/ncurses/build.sh | ncurses (wide, UTF-8), with xterm, vt100 and ansi built in |
ports/nano/build.sh | GNU nano, a whole program, as an example to read |
ports/netsurf/build.sh | NetSurf, a whole program, as an example to read |
Run them in that order: each needs the ones above it. The CA certificates for TLS are in
Z:\MIZU\CACERT.PEM on every Mizu.
What works
- Files and directories:
open,read,stat,opendir,renameand the rest./is the root of the current drive andZ:/...names a drive. Mizu's own disk (KFS) keeps long names; a FAT32 stick keeps what FAT keeps. - Memory:
malloc,mmapfor anonymous memory. - Threads: pthreads, mutexes, condition variables, thread-local storage.
- Network: TCP sockets over IPv4 (
socket,connect,bind,listen,accept),getaddrinfo,pollandselect. - Terminals: termios (raw mode, no echo, the window's size), ANSI colours and the alternate screen in the Command Prompt, and ncurses: nano runs as it is.
- Time and randomness:
clock_gettime,nanosleep,getrandomand/dev/urandomfrom the kernel's generator.
What does not, yet
- No
fork,eventfdorsocketpair: they fail withENOSYS. Starting programs works the other way:posix_spawn(withdup2actions for pipes),waitpid,execvp,pipe,popenandsystem, which run their line in Mizu's own shell, not POSIX sh. Most portable programs have a way round them; look for a configure switch (curl:ac_cv_func_eventfd=no,--disable-socketpair). - Signals arrive between system calls:
kill,sigactionhandlers,SIGCHLD, and Ctrl+C asSIGINTto the foreground process group. A loop that makes no system calls is not interrupted yet, and there is no job control. - UDP only as far as DNS needs it; no IPv6.
- No shared libraries: link statically (
--disable-shared).
Each of these is a gap to fill when something worth running needs it. If your port runs into one, say so: koiayame.com/help-mizu.
Drawing and sound
The easiest way is SDL 2, which most games and many tools already use. Its window is a window
of the desktop's, with keys going down and up, the pointer, both mouse buttons held, the wheel
and sound; SDL_WINDOW_FULLSCREEN maximises it. Without a desktop it takes the whole
screen instead, scaled to fit.
sdk/koi-gcc -O2 $(sdk/libc/bin/sdl2-config --cflags) game.c \
$(sdk/libc/bin/sdl2-config --libs) -lm -o GAME.EXE
OpenGL is Mesa 24.3 through OSMesa (ports/mesa): llvmpipe on the processor
(OpenGL 4.5), or the graphics card where Mizu drives one (crocus for Intel HD 2000/3000, virgl
in QEMU). Link with -lGL and SDL's SDL_GL_* calls work; QuakeSpasm
(ports/quakespasm) builds unchanged this way. A program that does not link
-lGL does not carry Mesa.
A ported program can call the same koi_* functions as any Mizu program: include
koi.h beside the C library and draw with koi_gfx_*, play with
koi_sound_* (see Writing a program). For a window on
the desktop, NetSurf's ports/netsurf/mizu.c shows how a program from elsewhere
opens one.
Sharing it
Put the result in a package (Packages) and it can reach the App Store. Keep the program's licence beside it.