Skip to content

Commit 69d6f2e

Browse files
committed
build.zig: add support for using "zig c++" as the bootstrap c++ compiler
The build was previously failing with `error: unknown command: -print-file-name=libstdc++.a` because the command invocation was `zig -print-file-name=libstdc++.a` instead of `zig c++ -print-file-name=libstdc++.a` note: .cxx_compiler_arg1 = "" instead of undefined to avoid breaking existing setups without requiring to run cmake again.
1 parent 0afead5 commit 69d6f2e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

build.zig

+13-2
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,11 @@ fn addCxxKnownPath(
735735
) !void {
736736
if (!std.process.can_spawn)
737737
return error.RequiredLibraryNotFound;
738-
const path_padded = b.exec(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) });
738+
739+
const path_padded = if (ctx.cxx_compiler_arg1.len > 0)
740+
b.exec(&.{ ctx.cxx_compiler, ctx.cxx_compiler_arg1, b.fmt("-print-file-name={s}", .{objname}) })
741+
else
742+
b.exec(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) });
739743
var tokenizer = mem.tokenizeAny(u8, path_padded, "\r\n");
740744
const path_unpadded = tokenizer.next().?;
741745
if (mem.eql(u8, path_unpadded, objname)) {
@@ -778,6 +782,7 @@ const CMakeConfig = struct {
778782
cmake_static_library_prefix: []const u8,
779783
cmake_static_library_suffix: []const u8,
780784
cxx_compiler: []const u8,
785+
cxx_compiler_arg1: []const u8,
781786
lld_include_dir: []const u8,
782787
lld_libraries: []const u8,
783788
clang_libraries: []const u8,
@@ -844,6 +849,7 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
844849
.cmake_static_library_prefix = undefined,
845850
.cmake_static_library_suffix = undefined,
846851
.cxx_compiler = undefined,
852+
.cxx_compiler_arg1 = "",
847853
.lld_include_dir = undefined,
848854
.lld_libraries = undefined,
849855
.clang_libraries = undefined,
@@ -875,6 +881,10 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
875881
.prefix = "#define ZIG_CXX_COMPILER ",
876882
.field = "cxx_compiler",
877883
},
884+
.{
885+
.prefix = "#define ZIG_CXX_COMPILER_ARG1 ",
886+
.field = "cxx_compiler_arg1",
887+
},
878888
.{
879889
.prefix = "#define ZIG_LLD_INCLUDE_PATH ",
880890
.field = "lld_include_dir",
@@ -917,7 +927,8 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
917927
var it = mem.splitScalar(u8, line, '"');
918928
_ = it.first(); // skip the stuff before the quote
919929
const quoted = it.next().?; // the stuff inside the quote
920-
@field(ctx, mapping.field) = toNativePathSep(b, quoted);
930+
const trimmed = mem.trim(u8, quoted, " ");
931+
@field(ctx, mapping.field) = toNativePathSep(b, trimmed);
921932
}
922933
}
923934
if (mem.startsWith(u8, line, "#define ZIG_LLVM_LINK_MODE ")) {

stage1/config.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@"
2222
#define ZIG_CMAKE_STATIC_LIBRARY_SUFFIX "@CMAKE_STATIC_LIBRARY_SUFFIX@"
2323
#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
24+
#define ZIG_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@"
2425
#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
2526
#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
2627
#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"

0 commit comments

Comments
 (0)