zig
zig copied to clipboard
`zig c++`: Doesn't support c++ modules
LLVM 16 currently adds support for c++ modules to clang/++, in addition to clang modules. However, zig cc/c++ does not have optimal support based on the references below.
Test
zig - version 0.11.0-dev.2868+1a455b2dd
# download fork
$> git clone https://github.com/kassane/fmt
$> cd fmt/
$> zig build # add -DTests to build all tests (default libfmt only)
$> zig cc -x c++ -std=c++2b -Iinclude test/module-test.cc -o module -lc++ -Lzig-out/lib -lfmt
test/module-test.cc:47:8: fatal error: module 'fmt' not found
import fmt;
~~~~~~~^~~
1 error generated.
$> zig cc -x c++-module -std=c++2b -Iinclude test/module-test.cc -o module -lc++ -Lzig-out/lib -lfmt
error: language not recognized: 'c++-module'
cc: @Vexu => (please, add tag)
References
- https://github.com/kassane/fmt/issues/1
- https://github.com/ziglang/zig/pull/13544
- https://github.com/llvm/llvm-project/issues/61198
title should like be "doesn't"
Also tried with build.zig
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const flags: []const []const u8 = &.{
"-std=c++20"
};
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "run",
.target = target,
.optimize = optimize,
});
exe.addCSourceFiles(&.{
"./src/main.cpp",
"./src/helloworld.cpp"
}, flags);
exe.linkLibCpp();
b.installArtifact(exe);
}
getting fatal error: module 'helloworld' not found
with g++-13 everything is Ok.
Adding -x c++-module
to the end of flags yields the following:
clang failed with stderr: zig: warning: '-x c++-module' after last input file has no effect [-Wunused-command-line-argument]
And this seems to only err because of -Wall
.
So I think to implement this, the zig cc
invocation just needs to have -x c++-module
right at the front, before everything else? Not sure what version of clang we're using, though.
documentation for clang 18 c++ modules: https://clang.llvm.org/docs/StandardCPlusPlusModules.html#how-to-enable-standard-c-modules
Bumped into same issue trying to build amd ROCm stuff with -x hip
error: error(compilation): clang failed with stderr: zig: warning: '-x hip' after last input file has no effect [-Wunused-command-line-argument]