diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-04-06 18:35:49 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-04-06 18:35:49 -0400 |
| commit | afa24ccd993e38b56407c83160da567bc2b0ae8a (patch) | |
| tree | aacd6d50fa61f700f9d1457f09ca3f45bc912f49 /build.zig | |
| parent | a59d31bd28f82e002f68ce25581c0437463137ed (diff) | |
| download | zig-afa24ccd993e38b56407c83160da567bc2b0ae8a.tar.gz zig-afa24ccd993e38b56407c83160da567bc2b0ae8a.zip | |
fix the build on Windows
Workaround for issue #2668
Zig std lib currently does not allow forward slashes in Windows path
names.
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -39,7 +39,7 @@ pub fn build(b: *Builder) !void { "config_h", "Path to the generated config.h", )) |config_h_path| - try std.fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) + try std.fs.cwd().readFileAlloc(b.allocator, toNativePathSep(b, config_h_path), max_config_h_bytes) else try findAndReadConfigH(b); @@ -65,7 +65,7 @@ pub fn build(b: *Builder) !void { const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; if (!only_install_lib_files and !skip_self_hosted) { - var ctx = parseConfigH(config_h_text); + var ctx = parseConfigH(b, config_h_text); ctx.llvm = try findLLVM(b, ctx.llvm_config_exe); try configureStage2(b, test_stage2, ctx); @@ -377,7 +377,7 @@ fn findAndReadConfigH(b: *Builder) ![]const u8 { } else unreachable; // TODO should not need `else unreachable`. } -fn parseConfigH(config_h_text: []const u8) Context { +fn parseConfigH(b: *Builder, config_h_text: []const u8) Context { var ctx: Context = .{ .cmake_binary_dir = undefined, .cxx_compiler = undefined, @@ -426,9 +426,19 @@ fn parseConfigH(config_h_text: []const u8) Context { if (mem.startsWith(u8, line, mapping.prefix)) { var it = mem.split(line, "\""); _ = it.next().?; // skip the stuff before the quote - @field(ctx, mapping.field) = it.next().?; // the stuff inside the quote + const quoted = it.next().?; // the stuff inside the quote + @field(ctx, mapping.field) = toNativePathSep(b, quoted); } } } return ctx; } + +fn toNativePathSep(b: *Builder, s: []const u8) []u8 { + const duplicated = mem.dupe(b.allocator, u8, s) catch unreachable; + for (duplicated) |*byte| switch (byte.*) { + '/' => byte.* = fs.path.sep, + else => {}, + }; + return duplicated; +} |
