Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build][Zig] Make more flags from src/config.h configurable #4407

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sagehane
Copy link
Contributor

This PR does not depend on #4406.

Currently, only flags containing the word SUPPORT is override-able via -Dconfig. This was the case as there was no code to check for what value they were set to, and all SUPPORT flags have a value of 1. This is also not ideal because it'll cause unexpected behaviour if the convention of the current src/config.h changes.

With this PR, everything that isn't defined between #ifdef or #ifndef and #endif can be passed or configured. I didn't bother evaluating flags between those as they already seem to be meant to be configured and truly evaluating them would be very annoying.

List of flags that are now passed by default when passing -Dconfig:

-DSUPPORT_MODULE_RSHAPES=1
-DSUPPORT_MODULE_RTEXTURES=1
-DSUPPORT_MODULE_RTEXT=1
-DSUPPORT_MODULE_RMODELS=1
-DSUPPORT_MODULE_RAUDIO=1
-DSUPPORT_CAMERA_SYSTEM=1
-DSUPPORT_GESTURES_SYSTEM=1
-DSUPPORT_RPRAND_GENERATOR=1
-DSUPPORT_MOUSE_GESTURES=1
-DSUPPORT_SSH_KEYBOARD_RPI=1
-DSUPPORT_WINMM_HIGHRES_TIMER=1
-DSUPPORT_PARTIALBUSY_WAIT_LOOP=1
-DSUPPORT_SCREEN_CAPTURE=1
-DSUPPORT_GIF_RECORDING=1
-DSUPPORT_COMPRESSION_API=1
-DSUPPORT_AUTOMATION_EVENTS=1
-DMAX_FILEPATH_CAPACITY=8192
-DMAX_FILEPATH_LENGTH=4096
-DMAX_KEYBOARD_KEYS=512
-DMAX_MOUSE_BUTTONS=8
-DMAX_GAMEPADS=4
-DMAX_GAMEPAD_AXIS=8
-DMAX_GAMEPAD_BUTTONS=32
-DMAX_GAMEPAD_VIBRATION_TIME=2.0f
-DMAX_TOUCH_POINTS=8
-DMAX_KEY_PRESSED_QUEUE=16
-DMAX_CHAR_PRESSED_QUEUE=16
-DMAX_DECOMPRESSION_SIZE=64
-DMAX_AUTOMATION_EVENTS=16384
-DRL_DEFAULT_BATCH_BUFFERS=1
-DRL_DEFAULT_BATCH_DRAWCALLS=256
-DRL_DEFAULT_BATCH_MAX_TEXTURE_UNITS=4
-DRL_MAX_MATRIX_STACK_SIZE=32
-DRL_MAX_SHADER_LOCATIONS=32
-DRL_CULL_DISTANCE_NEAR=0.01
-DRL_CULL_DISTANCE_FAR=1000.0
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION=0
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD=1
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL=2
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR=3
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT=4
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2=5
-DRL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES=6
-DRL_SUPPORT_MESH_GPU_SKINNING
-DRL_DEFAULT_SHADER_ATTRIB_NAME_POSITION="vertexPosition"
-DRL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD="vertexTexCoord"
-DRL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL="vertexNormal"
-DRL_DEFAULT_SHADER_ATTRIB_NAME_COLOR="vertexColor"
-DRL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT="vertexTangent"
-DRL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2="vertexTexCoord2"
-DRL_DEFAULT_SHADER_UNIFORM_NAME_MVP="mvp"
-DRL_DEFAULT_SHADER_UNIFORM_NAME_VIEW="matView"
-DRL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION="matProjection"
-DRL_DEFAULT_SHADER_UNIFORM_NAME_MODEL="matModel"
-DRL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL="matNormal"
-DRL_DEFAULT_SHADER_UNIFORM_NAME_COLOR="colDiffuse"
-DRL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0="texture0"
-DRL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1="texture1"
-DRL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2="texture2"
-DSUPPORT_QUADS_DRAW_MODE=1
-DSPLINE_SEGMENT_DIVISIONS=24
-DSUPPORT_FILEFORMAT_PNG=1
-DSUPPORT_FILEFORMAT_GIF=1
-DSUPPORT_FILEFORMAT_QOI=1
-DSUPPORT_FILEFORMAT_DDS=1
-DSUPPORT_IMAGE_EXPORT=1
-DSUPPORT_IMAGE_GENERATION=1
-DSUPPORT_IMAGE_MANIPULATION=1
-DSUPPORT_DEFAULT_FONT=1
-DSUPPORT_FILEFORMAT_TTF=1
-DSUPPORT_FILEFORMAT_FNT=1
-DSUPPORT_TEXT_MANIPULATION=1
-DSUPPORT_FONT_ATLAS_WHITE_REC=1
-DMAX_TEXT_BUFFER_LENGTH=1024
-DMAX_TEXTSPLIT_COUNT=128
-DSUPPORT_FILEFORMAT_OBJ=1
-DSUPPORT_FILEFORMAT_MTL=1
-DSUPPORT_FILEFORMAT_IQM=1
-DSUPPORT_FILEFORMAT_GLTF=1
-DSUPPORT_FILEFORMAT_VOX=1
-DSUPPORT_FILEFORMAT_M3D=1
-DSUPPORT_MESH_GENERATION=1
-DMAX_MATERIAL_MAPS=12
-DSUPPORT_FILEFORMAT_WAV=1
-DSUPPORT_FILEFORMAT_OGG=1
-DSUPPORT_FILEFORMAT_MP3=1
-DSUPPORT_FILEFORMAT_QOA=1
-DSUPPORT_FILEFORMAT_XM=1
-DSUPPORT_FILEFORMAT_MOD=1
-DAUDIO_DEVICE_FORMAT=ma_format_f32
-DAUDIO_DEVICE_CHANNELS=2
-DAUDIO_DEVICE_SAMPLE_RATE=0
-DMAX_AUDIO_BUFFER_POOL_CHANNELS=16
-DSUPPORT_STANDARD_FILEIO=1
-DSUPPORT_TRACELOG=1
-DMAX_TRACELOG_MSG_LENGTH=256

build.zig Show resolved Hide resolved
@sagehane
Copy link
Contributor Author

Side note: I wonder if using std.Build.Step.Compile.defineCMacro is more or less idiomatic than passing these flags the way it is. My guess that it's more idiomatic, so I'll switch to that approach.

@sagehane
Copy link
Contributor Author

sagehane commented Oct 21, 2024

Should be ready to merge; just needs reviews.

Edit: #4411 could render a lot of the code here unnecessary, but I think it's worth merging this first and then removing it again later if the proposal is implemented. Perhaps I should add a code comment to indicate that the issue is worth subscribing to.

Edit 2:

Side note: I wonder if using std.Build.Step.Compile.defineCMacro is more or less idiomatic than passing these flags the way it is. My guess that it's more idiomatic, so I'll switch to that approach.

Actually, maybe this might break behaviour with addRaygui if raygui depends on the same flags... I have no idea how raygui works tbh.

build.zig Outdated Show resolved Hide resolved
@raysan5
Copy link
Owner

raysan5 commented Oct 26, 2024

@sagehane What is the state of this PR? Can it be merged?

@sagehane
Copy link
Contributor Author

@sagehane What is the state of this PR? Can it be merged?

It's mostly okay but has a minor conflict because I extracted a portion of this patch to a different PR. I haven't had time to fix it and I don't know if I'll have much time for this until the end of the month.

That said, this is an enhancement that could use testing and not a bug fix of some immediate issue so it could wait until you release a new version like you said you're planning to. Feel free to close it if you don't want noise in the PR tracker; I can just reopen it after you tag a new release.

@sagehane
Copy link
Contributor Author

Okay, I finally had the time to update this PR.

Here's the flags passed now:

@as(*const [24:0]u8, "SUPPORT_MODULE_RSHAPES=1")
@as(*const [26:0]u8, "SUPPORT_MODULE_RTEXTURES=1")
@as(*const [22:0]u8, "SUPPORT_MODULE_RTEXT=1")
@as(*const [24:0]u8, "SUPPORT_MODULE_RMODELS=1")
@as(*const [23:0]u8, "SUPPORT_MODULE_RAUDIO=1")
@as(*const [23:0]u8, "SUPPORT_CAMERA_SYSTEM=1")
@as(*const [25:0]u8, "SUPPORT_GESTURES_SYSTEM=1")
@as(*const [26:0]u8, "SUPPORT_RPRAND_GENERATOR=1")
@as(*const [24:0]u8, "SUPPORT_MOUSE_GESTURES=1")
@as(*const [26:0]u8, "SUPPORT_SSH_KEYBOARD_RPI=1")
@as(*const [29:0]u8, "SUPPORT_WINMM_HIGHRES_TIMER=1")
@as(*const [31:0]u8, "SUPPORT_PARTIALBUSY_WAIT_LOOP=1")
@as(*const [24:0]u8, "SUPPORT_SCREEN_CAPTURE=1")
@as(*const [23:0]u8, "SUPPORT_GIF_RECORDING=1")
@as(*const [25:0]u8, "SUPPORT_COMPRESSION_API=1")
@as(*const [27:0]u8, "SUPPORT_AUTOMATION_EVENTS=1")
@as(*const [26:0]u8, "MAX_FILEPATH_CAPACITY=8192")
@as(*const [24:0]u8, "MAX_FILEPATH_LENGTH=4096")
@as(*const [21:0]u8, "MAX_KEYBOARD_KEYS=512")
@as(*const [19:0]u8, "MAX_MOUSE_BUTTONS=8")
@as(*const [14:0]u8, "MAX_GAMEPADS=4")
@as(*const [18:0]u8, "MAX_GAMEPAD_AXIS=8")
@as(*const [22:0]u8, "MAX_GAMEPAD_BUTTONS=32")
@as(*const [31:0]u8, "MAX_GAMEPAD_VIBRATION_TIME=2.0f")
@as(*const [18:0]u8, "MAX_TOUCH_POINTS=8")
@as(*const [24:0]u8, "MAX_KEY_PRESSED_QUEUE=16")
@as(*const [25:0]u8, "MAX_CHAR_PRESSED_QUEUE=16")
@as(*const [25:0]u8, "MAX_DECOMPRESSION_SIZE=64")
@as(*const [27:0]u8, "MAX_AUTOMATION_EVENTS=16384")
@as(*const [30:0]u8, "RL_SUPPORT_MESH_GPU_SKINNING=1")
@as(*const [26:0]u8, "RL_DEFAULT_BATCH_BUFFERS=1")
@as(*const [30:0]u8, "RL_DEFAULT_BATCH_DRAWCALLS=256")
@as(*const [36:0]u8, "RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS=4")
@as(*const [27:0]u8, "RL_MAX_MATRIX_STACK_SIZE=32")
@as(*const [26:0]u8, "RL_MAX_SHADER_LOCATIONS=32")
@as(*const [26:0]u8, "RL_CULL_DISTANCE_NEAR=0.01")
@as(*const [27:0]u8, "RL_CULL_DISTANCE_FAR=1000.0")
@as(*const [44:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION=0")
@as(*const [44:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD=1")
@as(*const [42:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL=2")
@as(*const [41:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR=3")
@as(*const [43:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT=4")
@as(*const [45:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2=5")
@as(*const [43:0]u8, "RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES=6")
@as(*const [55:0]u8, "RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION=\"vertexPosition\"")
@as(*const [55:0]u8, "RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD=\"vertexTexCoord\"")
@as(*const [51:0]u8, "RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL=\"vertexNormal\"")
@as(*const [49:0]u8, "RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR=\"vertexColor\"")
@as(*const [53:0]u8, "RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT=\"vertexTangent\"")
@as(*const [57:0]u8, "RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2=\"vertexTexCoord2\"")
@as(*const [40:0]u8, "RL_DEFAULT_SHADER_UNIFORM_NAME_MVP=\"mvp\"")
@as(*const [45:0]u8, "RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW=\"matView\"")
@as(*const [57:0]u8, "RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION=\"matProjection\"")
@as(*const [47:0]u8, "RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL=\"matModel\"")
@as(*const [49:0]u8, "RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL=\"matNormal\"")
@as(*const [49:0]u8, "RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR=\"colDiffuse\"")
@as(*const [52:0]u8, "RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0=\"texture0\"")
@as(*const [52:0]u8, "RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1=\"texture1\"")
@as(*const [52:0]u8, "RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2=\"texture2\"")
@as(*const [25:0]u8, "SUPPORT_QUADS_DRAW_MODE=1")
@as(*const [27:0]u8, "SPLINE_SEGMENT_DIVISIONS=24")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_PNG=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_GIF=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_QOI=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_DDS=1")
@as(*const [22:0]u8, "SUPPORT_IMAGE_EXPORT=1")
@as(*const [26:0]u8, "SUPPORT_IMAGE_GENERATION=1")
@as(*const [28:0]u8, "SUPPORT_IMAGE_MANIPULATION=1")
@as(*const [22:0]u8, "SUPPORT_DEFAULT_FONT=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_TTF=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_FNT=1")
@as(*const [27:0]u8, "SUPPORT_TEXT_MANIPULATION=1")
@as(*const [30:0]u8, "SUPPORT_FONT_ATLAS_WHITE_REC=1")
@as(*const [27:0]u8, "MAX_TEXT_BUFFER_LENGTH=1024")
@as(*const [23:0]u8, "MAX_TEXTSPLIT_COUNT=128")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_OBJ=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_MTL=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_IQM=1")
@as(*const [25:0]u8, "SUPPORT_FILEFORMAT_GLTF=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_VOX=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_M3D=1")
@as(*const [25:0]u8, "SUPPORT_MESH_GENERATION=1")
@as(*const [20:0]u8, "MAX_MATERIAL_MAPS=12")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_WAV=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_OGG=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_MP3=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_QOA=1")
@as(*const [23:0]u8, "SUPPORT_FILEFORMAT_XM=1")
@as(*const [24:0]u8, "SUPPORT_FILEFORMAT_MOD=1")
@as(*const [33:0]u8, "AUDIO_DEVICE_FORMAT=ma_format_f32")
@as(*const [23:0]u8, "AUDIO_DEVICE_CHANNELS=2")
@as(*const [26:0]u8, "AUDIO_DEVICE_SAMPLE_RATE=0")
@as(*const [33:0]u8, "MAX_AUDIO_BUFFER_POOL_CHANNELS=16")
@as(*const [25:0]u8, "SUPPORT_STANDARD_FILEIO=1")
@as(*const [18:0]u8, "SUPPORT_TRACELOG=1")
@as(*const [27:0]u8, "MAX_TRACELOG_MSG_LENGTH=256")
@as(*const [25:0]u8, "SUPPORT_CLIPBOARD_IMAGE=1")

It's worth noting that these newly introduced lines are hard to parse properly due to them being defined inside a conditional block.

raylib/src/config.h

Lines 279 to 301 in 00396e3

#define SUPPORT_CLIPBOARD_IMAGE 1
#if defined(SUPPORT_CLIPBOARD_IMAGE)
#ifndef STBI_REQUIRED
#define STBI_REQUIRED
#endif
#ifndef SUPPORT_FILEFORMAT_BMP // For clipboard image on Windows
#define SUPPORT_FILEFORMAT_BMP 1
#endif
#ifndef SUPPORT_FILEFORMAT_PNG // Wayland uses png for prints, at least it was on 22 LTS ubuntu
#define SUPPORT_FILEFORMAT_PNG 1
#endif
#ifndef SUPPORT_FILEFORMAT_JPG
#define SUPPORT_FILEFORMAT_JPG 1
#endif
#ifndef SUPPORT_MODULE_RTEXTURES
#define SUPPORT_MODULE_RTEXTURES 1
#endif
#endif

The project currently successfully compiles when passing zig build -Dconfig="-DSTBI_REQUIRED -DSUPPORT_FILEFORMAT_BMP".

I think it can still be treated as a draft until a new release comes out.

@raysan5 raysan5 changed the title build.zig: Make more flags from src/config.h configurable [build][Zig] Make more flags from src/config.h configurable Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants