Linux from a console
A Linux machine with no desktop — a Raspberry Pi, a server, a laptop started to a
text login — has no X11 and no Wayland for a window to open on, and often none of their headers to
build against. On such a console rmp builds the game for DRM/KMS instead: raylib's
backend that draws straight to the screen through the kernel. There is nothing to configure.
rmp run, rmp build, rmp test and rmp pack decide
by themselves, and say so.
What decides it#
Once
per command, before anything is configured, rmp asks these in order, and the first
that answers decides:
RMP_DRM=1builds for DRM/KMS andRMP_DRM=0for the desktop, whatever else is true. Empty is the same as unset. Any other value is refused rather than read as one of the two, and so isRMP_DRM=1anywhere but Linux.- Not Linux: the desktop. DRM/KMS is a Linux backend.
DISPLAYorWAYLAND_DISPLAYis set: the desktop. There is one to open a window on.- Logged
in over SSH —
SSH_CONNECTION,SSH_CLIENTorSSH_TTYis set — with no display: the desktop, and a note saying so. XDG_SESSION_TYPE=tty, which logind sets for a text login: DRM/KMS.- The
terminal
rmpruns in is a virtual console,/dev/tty1,/dev/tty2and so on: DRM/KMS, for a console that logind did not set up. The terminal is stdin's or, when stdin is not one, the controlling terminal's, sormp run < /dev/nulltyped on a console still counts. A terminal window, SSH and tmux are/dev/pts/…and a serial line is/dev/ttyS0: none of them is a virtual console. - Anything else: the desktop. With a terminal and no display, a note says why.
The
order is there because a console's own word for itself is wrong twice. startx keeps
the console's XDG_SESSION_TYPE=tty inside the desktop it starts, so a display is asked
about first. And logind calls a login over SSH a tty session too, while the screen of
a machine you are logged into from elsewhere is not yours to take — so SSH comes before it. From
SSH, RMP_DRM=1 asks for the machine's own screen anyway:
RMP_DRM=1 rmp runWhen
it builds for DRM/KMS, rmp says why on a line of its own:
XDG_SESSION_TYPE=tty: building for DRM/KMS, in build/debug-drm and build/release-drm
(RMP_DRM=0 for the desktop).
The
framework's tests walk every combination of them.
Its own two folders#
On
a console the debug build goes to build/debug-drm and the release to
build/release-drm, never to build/debug and build/release.
They are presets of their own, debug-drm and release-drm: the debug and
release presets with RMP_TARGET_DRM on, which picks raylib's DRM platform. A console
and a desktop on the same machine never share a cache, so going from one to the other rebuilds
nothing.
rmp run # builds build/debug-drm/my_game, checks /dev, starts it
rmp build release # builds build/release-drm/my_gameWithout rmp, the same presets by hand:
cmake --preset debug-drm
cmake --build --preset debug-drmCMake
never looks for X11 in either. A test configures both presets with X11 made impossible to find,
and the desktop's preset beside them, which has to fail that way for the test to count. A
debug build on a console is sanitized the way any debug build is, as
[dev] sanitize says.
What to install#
A console build needs the development files of libdrm, GBM, EGL and OpenGL ES — what raylib's
DRM backend draws with — and none of X11's. The
installer decides the way rmp does, and on a console it looks for those instead
of the X11 headers and lists what is missing with the command for this system:
| System | Packages |
|---|---|
apt | libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev |
dnf | libdrm-devel mesa-libgbm-devel mesa-libEGL-devel mesa-libGLES-devel |
pacman | libdrm mesa libglvnd |
zypper | libdrm-devel libgbm-devel Mesa-libEGL-devel Mesa-libGLESv2-devel |
apk (Alpine) | libdrm-dev mesa-dev linux-headers |
sudo apt install libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-devIt says what it decided, too: This is a Linux console with no desktop: rmp builds games for DRM/KMS here, and how to build for a desktop instead. As everywhere, it prints the command and never runs it.
The screen and the keyboard#
A
DRM/KMS game opens the screen through /dev/dri/card*, which it has to be able to read
and write and be the DRM master of: the kernel makes the first program that opens a card
nobody else draws on its master. It reads the keyboard, the mouse and the gamepads from
/dev/input/event*. Those belong to root and to a group, video and
input, and logind lets the person at the console open the card but not read the
keyboard. A game that cannot reach them finds out after the screen has gone black, so
rmp run asks first, between the build and the start:
- No
card. The cards that count are the ones raylib tries, in its order:
/dev/dri/by-path/platform-gpu-card, thencard1,card0andcard2—card1beforecard0because on a Raspberry Picard0is the 3D engine andcard1the display. It takes the first of them it can open that has a display — that answersdrmModeGetResources(), as raylib asks — and says which one the game draws on. With none of them,rmp runrefuses: no display driver with modesetting has loaded, as in a virtual machine without a display device or a container started without--device /dev/dri; and with cards that answer no display — a GPU with no display engine, or a driver loaded withnomodeset— it says so, andsudodoes not help. - A
card something else holds. When another program is the DRM master of the card the game
would take — a desktop on another virtual console, most likely —
rmp runrefuses: FAIL: something else draws on the screen: it is the DRM master of …, and a game can only take a screen nobody holds. Log out of that desktop or stop it. sudo is not offered, because root cannot take a screen from its master either. - A
card or an input device you cannot open.
rmp runrefuses with the game could not reach the screen and the keyboard from here (DRM/KMS):, lists each one with its owner and mode the wayls -lshows them, and gives the two ways out below. - No input device at all. A note, and the game starts: it reads the keys of the terminal it runs on, and no mouse or gamepad.
The
smoke stage of rmp test boots the game on the console's screen, and asks the same
before it does.
Two ways out: sudo once, or the groups#
Start
the game as root this once, or put yourself in the video and input
groups for good. A group you are added to counts from your next login, so log out and in again,
and from then on rmp run starts the game as you, without root:
rmp run sudo # this once: the game as root, the build as you
sudo usermod -aG video,input "$USER" # for good, then log out and in againrmp
run sudo builds as you, says the exact command, and starts only the game with
sudo --: nothing rmp writes is ever root's. It asks the same questions
first, but the last: a card that is not there, or one that something else holds, is refused
before sudo asks for a password, because sudo fixes neither — what only root may open is what sudo
is for.
On
a desktop it is refused before anything is built: a window needs no root. When rmp is
root already it starts the game as it is, and on a machine with no sudo it refuses
and prints the game's path, to start as root some other way. rmp never runs sudo
unless you typed it.
Never sudo rmp#
rmp
never builds as root. Under sudo — root, with SUDO_USER naming somebody else — every
command but rmp help and rmp clean is refused before anything runs —
FAIL: rmp is running as root through sudo, and would build as root: … — because
build/, the files generated from the .toml, the sources and
.git would be root's, and the next command you ran as yourself could not write them.
sudo rmp clean is how what an earlier root left goes away. Root with nobody behind it
— a container, CI — has no other user to be, and builds.
Saves under sudo#
A
game started with sudo is root, and saves as root. With sudo's defaults its home is root's, so
rmp::save writes to
/root/.local/share/<name>/ and not to your folder; a sudoers that keeps your
HOME gives your own folder, written as root, and
[save] portable = true writes root's files next to the game. rmp run
sudo says so before it starts the game.
The
game says it as well, once, as it starts — WARNING: CONSOLE: started with sudo by … —
with your name, the folder it really saves in, read from the environment sudo left it, and the
groups. In the video and input groups the game runs as you and saves where
it always does.
The terminal comes back#
raylib's
DRM backend reads the keyboard from the terminal the game starts on, and changes it: no echo, no
line editing, no Ctrl+C, the terminal made non-blocking — a setting your shell shares — and a
virtual console's keyboard put in another mode. It puts them back only from an atexit
handler, which
a crash, abort(), a sanitizer's report and a kill never run, and the shell after
them would type blind, with no Ctrl+C.
So the framework puts it back however the game ends. Before the window opens it remembers the terminal, and puts it back on every fatal signal — then hands the signal on to whoever had it, so a crash is still a crash: a core dump, AddressSanitizer's report, the status your shell sees — on the sanitizers' way out, and at exit. Its handler runs on a stack set apart for signals — AddressSanitizer's, or one of its own where nothing set one up — because a stack overflow leaves none to run on.
SIGKILL
is the one ending nothing inside a process can catch, so rmp run also saves the
terminal before the game and restores it after, and says when it had to: the game left the
terminal changed -- … -- and rmp put it back. The screen needs none of this: the kernel
gives the console its screen back when the game's last handle on the card closes, however the
process ended.
The
framework's tests make a small program die each of those ways on a pseudo-terminal — an exit, a
segmentation fault, abort(), SIGTERM, a trap, a division by zero, a stack overflow,
an AddressSanitizer report — with the guard, and the terminal has to come back each time, with
the program still ending the way it would have. Without the guard, a crash, abort(),
SIGTERM, a stack overflow and the sanitizer's report have to leave it changed, or the test would
prove nothing. SIGKILL leaves it changed with the guard too, which is why rmp run
mends it from outside.
While it runs#
Ctrl+C does nothing while the game runs: the terminal's signals are off. The game quits from its own menu, and Escape is the game's key, not a way out — see the Escape key.
Ctrl+Alt+F1, F2 and the others still switch to another virtual console, but the screen may go on showing the game: the kernel does not take a screen from its DRM master. To end a game that is stuck, log in on another console — without seeing what you type, if it comes to that — or over SSH, and end it from there.
When it does not work#
| What you see | What it means |
|---|---|
rmp run says something else draws on the screen | A desktop, or another program on the card, holds it. Log out of the desktop or stop the program; sudo does not help. |
rmp run says no card raylib tries has a display | A GPU with no display engine, or a driver loaded with nomodeset. sudo does not help: give the machine a display driver with modesetting. |
rmp run says there is no card | No display driver with modesetting has loaded. In a container, pass the card in with --device /dev/dri. |
rmp run lists nodes under /dev/dri or /dev/input | You cannot open them. rmp run sudo this once, or the video and input groups and a new login. |
| Added to the groups, and still refused | Groups are read at login: log out and in again. |
| The game reads the keyboard, and no mouse or gamepad | There is no /dev/input/event*; the game reads the terminal's keys. |
| Over SSH, it built a game that opens a window | SSH counts as the desktop. RMP_DRM=1 rmp run builds for the machine's own screen. |
sudo rmp … is refused | Run rmp as yourself; rmp run sudo gives root to the game alone. |
| The screen stays black, and raylib's log says it failed to initialize the EGL device | Mesa could not draw on that card. CI's virtual display has no GPU behind it, and Mesa draws there only in software, with LIBGL_ALWAYS_SOFTWARE=1 in the environment; a display with no GPU Mesa can drive needs the same. |
What CI proves#
The
job that boots linux-x64-glibc-drm on a virtual display — vkms, a DRM device the kernel
provides with no hardware behind it — also runs rmp the way a console does: in the
build image, with the card passed in, no display, XDG_SESSION_TYPE=tty and
./rmp run. It
has to decide DRM/KMS by itself, build build/debug-drm without touching
build/debug, link libdrm and no X11 or Wayland, check /dev before it
starts the game, and boot it, draw and exit cleanly with no sanitizer report. It runs in a
game's CI too, when the game ships linux-x64-glibc-drm; only the framework's build is
held to having been sanitized there, because a game's [dev] sanitize is its own.
What
it cannot prove follows from where it runs: the container is root, so the groups and sudo are not
tried, and it is given no /dev/input, so no real keyboard either.