Skip to content

Commit

Permalink
gpu-dawn: remove source division workaround
Browse files Browse the repository at this point in the history
I've fixed the issue in Zig upstream: ziglang/zig#10950

Helps #86

Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
slimsag committed Feb 21, 2022
1 parent e451e4a commit 1bc6a7e
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions gpu-dawn/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fn buildLibDawnCommon(b: *Builder, step: *std.build.LibExeObjStep, options: Opti
var cpp_flags = std.ArrayList([]const u8).init(b.allocator);
cpp_flags.appendSlice(flags.items) catch unreachable;
options.appendFlags(&cpp_flags, false, true) catch unreachable;
addCSourceFiles(b, lib, cpp_sources.items, cpp_flags.items);
lib.addCSourceFiles(cpp_sources.items, cpp_flags.items);
return lib;
}

Expand Down Expand Up @@ -453,7 +453,7 @@ fn buildLibDawnPlatform(b: *Builder, step: *std.build.LibExeObjStep, options: Op
cpp_sources.append(abs_path) catch unreachable;
}

addCSourceFiles(b, lib, cpp_sources.items, cpp_flags.items);
lib.addCSourceFiles(cpp_sources.items, cpp_flags.items);
return lib;
}

Expand Down Expand Up @@ -735,7 +735,7 @@ fn buildLibDawnNative(b: *Builder, step: *std.build.LibExeObjStep, options: Opti
var cpp_flags = std.ArrayList([]const u8).init(b.allocator);
cpp_flags.appendSlice(flags.items) catch unreachable;
options.appendFlags(&cpp_flags, false, true) catch unreachable;
addCSourceFiles(b, lib, cpp_sources.items, cpp_flags.items);
lib.addCSourceFiles(cpp_sources.items, cpp_flags.items);
return lib;
}

Expand Down Expand Up @@ -890,7 +890,7 @@ fn buildLibTint(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *
var cpp_flags = std.ArrayList([]const u8).init(b.allocator);
cpp_flags.appendSlice(flags.items) catch unreachable;
options.appendFlags(&cpp_flags, false, true) catch unreachable;
addCSourceFiles(b, lib, cpp_sources.items, cpp_flags.items);
lib.addCSourceFiles(cpp_sources.items, cpp_flags.items);
return lib;
}

Expand Down Expand Up @@ -1160,7 +1160,7 @@ fn buildLibDawnUtils(b: *Builder, step: *std.build.LibExeObjStep, options: Optio
var cpp_flags = std.ArrayList([]const u8).init(b.allocator);
cpp_flags.appendSlice(flags.items) catch unreachable;
options.appendFlags(&cpp_flags, false, true) catch unreachable;
addCSourceFiles(b, lib, cpp_sources.items, cpp_flags.items);
lib.addCSourceFiles(cpp_sources.items, cpp_flags.items);
return lib;
}

Expand All @@ -1172,29 +1172,6 @@ fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}

// TODO(build-system): This and divideSources are needed to avoid Windows process creation argument
// length limits. This should probably be fixed in Zig itself, not worked around here.
fn addCSourceFiles(b: *Builder, step: *std.build.LibExeObjStep, sources: []const []const u8, flags: []const []const u8) void {
for (divideSources(b, sources) catch unreachable) |divided| step.addCSourceFiles(divided, flags);
}

fn divideSources(b: *Builder, sources: []const []const u8) ![]const []const []const u8 {
var divided = std.ArrayList([]const []const u8).init(b.allocator);
var current = std.ArrayList([]const u8).init(b.allocator);
var current_size: usize = 0;
for (sources) |src| {
if (current_size + src.len >= 30000) {
try divided.append(current.items);
current = std.ArrayList([]const u8).init(b.allocator);
current_size = 0;
}
current_size += src.len;
try current.append(src);
}
try divided.append(current.items);
return divided.items;
}

fn appendLangScannedSources(
b: *Builder,
step: *std.build.LibExeObjStep,
Expand Down Expand Up @@ -1244,7 +1221,7 @@ fn appendScannedSources(b: *Builder, step: *std.build.LibExeObjStep, args: struc
for (args.rel_dirs) |rel_dir| {
try scanSources(b, &sources, rel_dir, args.extensions, args.excluding, args.excluding_contains);
}
addCSourceFiles(b, step, sources.items, args.flags);
step.addCSourceFiles(sources.items, args.flags);
}

/// Scans rel_dir for sources ending with one of the provided extensions, excluding relative paths
Expand Down

0 comments on commit 1bc6a7e

Please sign in to comment.