authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-06 18:35:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-06 18:35:49-04:00
logafa24ccd993e38b56407c83160da567bc2b0ae8a
treeaacd6d50fa61f700f9d1457f09ca3f45bc912f49
parenta59d31bd28f82e002f68ce25581c0437463137ed

fix the build on Windows

Workaround for issue #2668 Zig std lib currently does not allow forward slashes in Windows path names.

1 files changed, 14 insertions(+), 4 deletions(-)

build.zig+14-4
......@@ -39,7 +39,7 @@ pub fn build(b: *Builder) !void {
3939 "config_h",
4040 "Path to the generated config.h",
4141 )) |config_h_path|
42 try std.fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes)
42 try std.fs.cwd().readFileAlloc(b.allocator, toNativePathSep(b, config_h_path), max_config_h_bytes)
4343 else
4444 try findAndReadConfigH(b);
4545
......@@ -65,7 +65,7 @@ pub fn build(b: *Builder) !void {
6565
6666 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
6767 if (!only_install_lib_files and !skip_self_hosted) {
68 var ctx = parseConfigH(config_h_text);
68 var ctx = parseConfigH(b, config_h_text);
6969 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);
7070
7171 try configureStage2(b, test_stage2, ctx);
......@@ -377,7 +377,7 @@ fn findAndReadConfigH(b: *Builder) ![]const u8 {
377377 } else unreachable; // TODO should not need `else unreachable`.
378378}
379379
380fn parseConfigH(config_h_text: []const u8) Context {
380fn parseConfigH(b: *Builder, config_h_text: []const u8) Context {
381381 var ctx: Context = .{
382382 .cmake_binary_dir = undefined,
383383 .cxx_compiler = undefined,
......@@ -426,9 +426,19 @@ fn parseConfigH(config_h_text: []const u8) Context {
426426 if (mem.startsWith(u8, line, mapping.prefix)) {
427427 var it = mem.split(line, "\"");
428428 _ = it.next().?; // skip the stuff before the quote
429 @field(ctx, mapping.field) = it.next().?; // the stuff inside the quote
429 const quoted = it.next().?; // the stuff inside the quote
430 @field(ctx, mapping.field) = toNativePathSep(b, quoted);
430431 }
431432 }
432433 }
433434 return ctx;
434435}
436
437fn toNativePathSep(b: *Builder, s: []const u8) []u8 {
438 const duplicated = mem.dupe(b.allocator, u8, s) catch unreachable;
439 for (duplicated) |*byte| switch (byte.*) {
440 '/' => byte.* = fs.path.sep,
441 else => {},
442 };
443 return duplicated;
444}