Skip to content

Instantly share code, notes, and snippets.

@JoshuaWierenga
Last active May 9, 2024 15:20
Show Gist options
  • Save JoshuaWierenga/07bc24e0b40108a477b9ff52a3c0f77f to your computer and use it in GitHub Desktop.
Save JoshuaWierenga/07bc24e0b40108a477b9ff52a3c0f77f to your computer and use it in GitHub Desktop.
x11/xcb libaries can be built with
CC=x86_64-unknown-cosmo-cc PKG_CONFIG_PATH=$PWD/../output/share/pkgconfig:$PWD/../output/lib/pkgconfig ./autogen.sh --prefix=$PWD/../output --disable-shared --enable-static
make
make install
sdl2 can be built with
./autogen.sh
CC=x86_64-unknown-cosmo-cc PKG_CONFIG_PATH=$PWD/../output/share/pkgconfig:$PWD/../output/lib/pkgconfig ./configure --prefix=$PWD/../output --disable-shared --enable-static --disable-diskaudio --disable-pulseaudio --disable-sndio --disable-video-kmsdrm --disable-video-opengles2 --disable-video-wayland --disable-video-vulkan --enable-video-x11 --disable-dbus --disable-ime --disable-fcitx --disable-joystick-virtual --disable-cpuinfo --disable-joystick --disable-haptic --disable-hidapi --disable-sensor --disable-power --disable-locale --disable-loadso --x-includes=/home/joshua/src/src/cosmo/gui/xlib/output/include --x-libraries=/home/joshua/src/src/cosmo/gui/xlib/output/lib
make
make install
I tried cosmocc instead of x86_64-unknown-cosmo-cc but it failed because aarch64 versions of libaries were not made as so exec building failed.
Working build order:
xorgproto from https://gitlab.freedesktop.org/xorg/proto/xorgproto
xcbproto from https://gitlab.freedesktop.org/xorg/proto/xcbproto
libxau from https://gitlab.freedesktop.org/xorg/lib/libxau
libxcb from https://gitlab.freedesktop.org/xorg/lib/libxcb
libxtrans from https://gitlab.freedesktop.org/xorg/lib/libxtrans
libx11 from https://gitlab.freedesktop.org/xorg/lib/libx11
add the following in src/XlibInt.c, same as https://github.com/jart/cosmopolitan/issues/1139, required for struct pollfd
#ifdef __COSMOPOLITAN__
#include "libc/sock/struct/pollfd.h"
#endif
libxext from https://gitlab.freedesktop.org/xorg/lib/libxext
sdl2 from https://github.com/libsdl-org/SDL
tested with release-2.30.3
comment/remove the sys/sysctl.h include in src/cpuinfo/SDL-cpuinfo.c, header does not exist, sys/types.h has macos only sysctlbyname
add the following in src/thread/pthread/SDL_systhread.c, required for SCHED constants
#ifdef __COSMOPOLITAN__
#include <time.h>
#endif
With https://en.wikibooks.org/wiki/X_Window_Programming/Xlib's demo as x11demo.c
x86_64-unknown-cosmo-cc -o x11test x11test.c -I output/include -L output/lib -lX11 -lxcb -lXau
apelink -o x11test.com -l /opt/cosmo/.cosmocc/3.3.5/bin/ape-x86_64.elf x11test
With https://github.com/xyproto/sdl2-examples/blob/main/c18/main.c as sdltest.c and grumpy-cat.bmp downloaded, update the path in sdltest.c as required.
x86_64-unknown-cosmo-cc -o sdltest sdltest.c -I output/include -L output/lib -l SDL2 -l X11 -l xcb -l Xau -l Xext
apelink -o sdltest.com -l /opt/cosmo/.cosmocc/3.3.5/bin/ape-x86_64.elf sdltest
Only tested on linux but with minimal tweaking other unix likes should work without much issue.
Windows may be a massive pain and it may end up being easier to use a shared libary for sdl so that it can be swapped out for one supporting windows(gdi specifically?).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment