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.
#Consistent C++ standard version across modules with build.zig?
1 messages · Page 1 of 1 (latest)
I don't think there's standard way for this.
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.
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.
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
It works sometimes sometimes not
https://gcc.gnu.org/wiki/Cxx11AbiCompatibility
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html is one documented ABI breakage, but I've had e.g. protobuf crash and burn if compiled on different std
Yeah I never tried using C++98 😅 only 11 and above
That’s more about being compiled by an older compiler no? With zig build everything is compiled with the same compiler, should be fine
But yeah, we never know with C++
nah the abi changes depending on std flag, but you can also have weird ABI by setting the _GLIBCXX_USE_CXX11_ABI define
for clang it's probably less serious
the less I have to deal with c++ the better tbh
I think with clang it should be safe https://libcxx.llvm.org/DesignDocs/ABIVersioning.html
minus msvc lol
(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
Oh wauw, really interesting. So as long as it compiles, and none of the depdnencies set the LIBCPP_ABI_VERSION manually, we get the compiler default. Which is stable regardless of the C++ version.
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
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).