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 {...@@ -39,7 +39,7 @@ pub fn build(b: *Builder) !void {
39 "config_h",39 "config_h",
40 "Path to the generated config.h",40 "Path to the generated config.h",
41 )) |config_h_path|41 )) |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)
43 else43 else
44 try findAndReadConfigH(b);44 try findAndReadConfigH(b);
4545
...@@ -65,7 +65,7 @@ pub fn build(b: *Builder) !void {...@@ -65,7 +65,7 @@ pub fn build(b: *Builder) !void {
6565
66 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;66 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
67 if (!only_install_lib_files and !skip_self_hosted) {67 if (!only_install_lib_files and !skip_self_hosted) {
68 var ctx = parseConfigH(config_h_text);68 var ctx = parseConfigH(b, config_h_text);
69 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);69 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);
7070
71 try configureStage2(b, test_stage2, ctx);71 try configureStage2(b, test_stage2, ctx);
...@@ -377,7 +377,7 @@ fn findAndReadConfigH(b: *Builder) ![]const u8 {...@@ -377,7 +377,7 @@ fn findAndReadConfigH(b: *Builder) ![]const u8 {
377 } else unreachable; // TODO should not need `else unreachable`.377 } else unreachable; // TODO should not need `else unreachable`.
378}378}
379379
380fn parseConfigH(config_h_text: []const u8) Context {380fn parseConfigH(b: *Builder, config_h_text: []const u8) Context {
381 var ctx: Context = .{381 var ctx: Context = .{
382 .cmake_binary_dir = undefined,382 .cmake_binary_dir = undefined,
383 .cxx_compiler = undefined,383 .cxx_compiler = undefined,
...@@ -426,9 +426,19 @@ fn parseConfigH(config_h_text: []const u8) Context {...@@ -426,9 +426,19 @@ fn parseConfigH(config_h_text: []const u8) Context {
426 if (mem.startsWith(u8, line, mapping.prefix)) {426 if (mem.startsWith(u8, line, mapping.prefix)) {
427 var it = mem.split(line, "\"");427 var it = mem.split(line, "\"");
428 _ = it.next().?; // skip the stuff before the quote428 _ = it.next().?; // skip the stuff before the quote
429 @field(ctx, mapping.field) = it.next().?; // the stuff inside the quote429 const quoted = it.next().?; // the stuff inside the quote
430 @field(ctx, mapping.field) = toNativePathSep(b, quoted);
430 }431 }
431 }432 }
432 }433 }
433 return ctx;434 return ctx;
434}435}
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}