#Consistent C++ standard version across modules with build.zig?

1 messages · Page 1 of 1 (latest)

astral nebula
#

I'm trying to move away from CMake and use zig instead. I'd like to write a build.zig file for a dependency project. However, I'd like to make sure that the dependency gets compiled with the main projects C++ standard version. So I'd like to have the main project specify a C++ version, and then have all of the dependencies in my project be compiled with that standard version, to ensure compatibility. So, is there a way to do this in build.zig/build.zig.zon? I think this is necessary, as the C++ standard version might change the ABI of the resulting libraries.

simple cairn
#

I don't think there's standard way for this.

astral nebula
#

Thinking about this, I get the impression that every project should specifiy an optional minimum and optional maximum version. Then when all dependencies are gathered, the build system should find a common C++ version that works.

simple cairn
#

currently the cxx/cflags are decided by a module, there is no standard abstraction, though module could offer build option to decide on such variants.

soft wigeon
#

From my experience in C++, each compilation unit can use a different standard without issue
The problem are the headers, which should support all versions you care about

simple cairn
#

It works sometimes sometimes not

soft wigeon
#

Yeah I never tried using C++98 😅 only 11 and above

soft wigeon
#

But yeah, we never know with C++

simple cairn
#

for clang it's probably less serious

#

the less I have to deal with c++ the better tbh

#

minus msvc lol

soft wigeon
#

(Ah yes now that you mention it i remember this, before zig build existed I was using Conan and had to set the ABI to C++11 and above, even though everything was recompiled by the same compiler.)
But OK, you can set a build option for a standard version so that consumers of your package can choose, why not

astral nebula
simple cairn
#

the dependencies can't change that macro, so as long as you build everything with same zig version (clang version) you should be fine

#

emphasis on should of course, been there long enough staring at the voids of C++ ABI stability

astral nebula
#

Hehe, I have some experience myself with that (made the mistake to link with a gcc-compiled library from clang-compiled project: the mutex size was different, so structs had different layout).