Skip to content

ConfigHeader: Add support for meson style templates #23943

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

GalaxyShard
Copy link
Contributor

Revival of #18079

I rebased the two commits and fixed the tests which now compile and run correctly.

@GalaxyShard GalaxyShard force-pushed the meson-config-headers branch from 783a2ee to 9854d63 Compare May 23, 2025 07:17
@GalaxyShard
Copy link
Contributor Author

I've done some thorough testing of this with porting over all of the meson config headers from GTK and its several dependencies. All of the resulting headers are identical to the corresponding ones in my /usr/include (aside from the "This file was generated by ConfigHeader using the Zig Build System." comment).

@Jan200101
Copy link
Contributor

the big issue with mesondefine is that they don't strictly specify how its suppose to work and there is little to no regression testing, so a change upstream could cause interop issues with zig in subtle ways.

@GalaxyShard
Copy link
Contributor Author

the big issue with mesondefine is that they don't strictly specify how its suppose to work and there is little to no regression testing, so a change upstream could cause interop issues with zig in subtle ways.

Meson's documentation (https://mesonbuild.com/Configuration.html) defines how mesondefine is to be expanded:

#define TOKEN     // If TOKEN is set to boolean true.
#undef TOKEN      // If TOKEN is set to boolean false.
#define TOKEN 4   // If TOKEN is set to an integer or string value.
/* undef TOKEN */ // If TOKEN has not been set to any value.

If there were regressions, it would be a bug on meson's part, and it would break many projects using meson so I doubt any accidental regressions would become "features" especially considering the logic is fairly straightforward (the only 4 possibilities are in the block above; you'd have to break almost every project by changing the behavior of any one of them).

switch (value) {
.undef, .defined => {},
.boolean => |b| {
try buffer.appendSlice(if (b) "true" else "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meson uses the uppercase spelling of True and False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking closer at the current upstream source code, it appears meson fires an exception if a boolean value added with set (the equivalent meson's of addValue) is used as a variable. Since every other configuration header style handles this case by substituting a 0 or a 1 in place of a boolean, and because meson has a dedicated function for adding boolean variables (set10 vs set) that also substitutes 0's and 1's like that, I think I'll have it follow that behavior for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'd think that but in python bool is an integer subclass

>>> var = True
>>> isinstance(var, int)
True

meson does str(var) if var is an integer instance so it will become True or False for boolean values... fun stuff

@GalaxyShard GalaxyShard force-pushed the meson-config-headers branch from 9854d63 to 6716481 Compare June 2, 2025 06:06
@GalaxyShard GalaxyShard force-pushed the meson-config-headers branch from 6716481 to 96ff024 Compare June 2, 2025 06:09
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.

4 participants