-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Description
A compilation error occurs in onWayland() function when building Wails v2.10.2 on some compilers.
The function declares a variable inside a case block without braces, which is not allowed in standard C.
Error message:
window.c:79:6: error: a label can only be part of a statement and a declaration is not a statement
79 | char *gdkBackend = getenv("XDG_SESSION_TYPE");
| ^~~~
To Reproduce
Steps to reproduce the behaviour:
Build the project for Linux target:
wails build -platform linux/amd64
Compilation fails with the above error.
Expected behaviour
The code should compile successfully on any standard-compliant C compiler, even those that strictly enforce C rules.
Specifically, variables should not be declared directly inside a case label without a new scope or outside the switch statement.
Screenshots
N/A — this is a compiler error and does not produce a UI screen.
Relevant build log snippet:
window.c: In function ‘onWayland’:
window.c:79:6: error: a label can only be part of a statement and a declaration is not a statement
79 | char *gdkBackend = getenv("XDG_SESSION_TYPE");
| ^~~~
ERROR exit status 1
Attempted Fixes
The root cause of the compilation error is that in C, declarations inside a case label must be inside a block scope (i.e., surrounded by {}), or be declared before the switch statement. This is because a case label is not a separate block by itself and declaring variables directly under it is not allowed by the C standard.
Original problematic code:
case -1:
char *gdkBackend = getenv("XDG_SESSION_TYPE");
if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0)
{
wmIsWayland = 1;
return TRUE;
}
wmIsWayland = 0;
return FALSE;
Fix 1: Wrap in braces to create a new scope
case -1: {
char *gdkBackend = getenv("XDG_SESSION_TYPE");
if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0)
{
wmIsWayland = 1;
return TRUE;
}
wmIsWayland = 0;
return FALSE;
}
Fix 2: Move declaration outside the switch (recommended for better clarity and compatibility)
char *gdkBackend = NULL;
switch (wmIsWayland)
{
case -1:
gdkBackend = getenv("XDG_SESSION_TYPE");
if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0)
{
wmIsWayland = 1;
return TRUE;
}
wmIsWayland = 0;
return FALSE;
Both fixes solve the compilation error by respecting C language rules on declarations within switch-case statements.
System Details
GOVERSION: go1.23.4 linux/amd64
Additional context
The problematic file is v2/internal/frontend/desktop/linux/window.c
The error occurs during the Linux build step of wails build.
Likely to affect any environment where the C compiler enforces standard C rules (e.g., -std=c89 or -std=c99 without extensions).
Proposed fix: move char *gdkBackend declaration out of the case block or wrap it in braces.