@@ -27,8 +27,9 @@ argv_range: ?ArgRange,
2727const file_ext = ".class" ;
2828
2929const ArgRange = struct {
30- start : usize ,
31- end : usize ,
30+ argv_start : usize ,
31+ file_input_start : usize ,
32+ len : u32 ,
3233};
3334
3435/// Creates a D8Glob step which is used to collect all *.class output files after a javac process generates them
@@ -57,21 +58,28 @@ fn make(step: *Step, options: Build.Step.MakeOptions) !void {
5758 _ = options ;
5859 const b = step .owner ;
5960 const arena = b .allocator ;
60- const gpa = b .allocator ;
61- const glob : * @This () = @fieldParentPtr ("step" , step );
61+ const self : * D8Glob = @fieldParentPtr ("step" , step );
6262
63- const d8 = glob .run ;
63+ const d8 = self .run ;
64+
65+ // NOTE(jae): 2026-03-01
66+ // This step uses the output of various Java files from a .zig-cache folder so
67+ // in theory we shouldn't need to handle addDirectoryWatchInput
68+ //
69+ // ie. .zig-cache/o/078c6c3d6e14d425d58e182be74b7006/android_classes
70+ // const need_derived_inputs = try step.addDirectoryWatchInput(self.dir);
6471
6572 // Triggers on --watch if a Java file is modified.
6673 // For example: ZigSDLActivity.java
67- if (glob .argv_range ) | argv_range | {
68- try d8 .argv .replaceRange (d8 .step .owner .allocator , argv_range .start , argv_range .end - argv_range .start , &.{});
74+ if (self .argv_range ) | argv_range | {
75+ try d8 .file_inputs .replaceRange (d8 .step .owner .allocator , argv_range .file_input_start , argv_range .len , &.{});
76+ try d8 .argv .replaceRange (d8 .step .owner .allocator , argv_range .argv_start , argv_range .len , &.{});
6977 }
7078
7179 const search_dir = if (builtin .zig_version .major == 0 and builtin .zig_version .minor <= 15 )
72- glob .dir .getPath3 (b , step )
80+ self .dir .getPath3 (b , step )
7381 else
74- try glob .dir .getPath4 (b , step );
82+ try self .dir .getPath4 (b , step );
7583
7684 // NOTE(jae): 2024-09-22
7785 // Change current working directory to where the Java classes are
@@ -83,7 +91,7 @@ fn make(step: *Step, options: Build.Step.MakeOptions) !void {
8391 // A deeper fix to this problem could be:
8492 // - Zip up all the *.class files and just provide that as ONE argument or alternatively
8593 // - If "d8" has the ability to pass a file of command line parameters, that would work too but I haven't seen any in the docs
86- d8 .setCwd (glob .dir );
94+ d8 .setCwd (self .dir );
8795
8896 // NOTE(jae): 2025-07-23
8997 // As of Zig 0.15.0-dev.1092+d772c0627, package_name_path.openDir("") is not possible as it assumes you're appending a sub-path
@@ -97,44 +105,62 @@ fn make(step: *Step, options: Build.Step.MakeOptions) !void {
97105 dir .close (b .graph .io );
98106
99107 var optional_argv_start : ? usize = null ;
108+ var optional_file_input_start : ? usize = null ;
100109 var walker = try dir .walk (arena );
101110 defer walker .deinit ();
102111 while (if (builtin .zig_version .major == 0 and builtin .zig_version .minor <= 15 )
103112 try walker .next ()
104113 else
105114 try walker .next (b .graph .io )) | entry |
106115 {
107- if (entry .kind != .file ) {
108- continue ;
109- }
110- // NOTE(jae): 2024-10-01
111- // Initially ignored classes with alternate API postfixes / etc but
112- // that did not work with SDL2 so no longer do that.
113- // - !std.mem.containsAtLeast(u8, entry.basename, 1, "$") and
114- // - !std.mem.containsAtLeast(u8, entry.basename, 1, "_API")
115- if (std .mem .endsWith (u8 , entry .path , file_ext )) {
116- const absolute_file_path = try search_dir .root_dir .join (gpa , &.{ search_dir .sub_path , entry .path });
117- const relative_to_dir_path = absolute_file_path [search_dir .sub_path .len + 1 .. ];
118- // NOTE(jae): 2024-09-22
119- // We set the current working directory to "glob.Dir" and then make arguments be
120- // relative to that directory.
121- //
122- // This is to avoid the Java error "command line too long" that can occur with d8
123- if (optional_argv_start == null ) {
124- optional_argv_start = d8 .argv .items .len ;
125- }
126- d8 .addFileInput (LazyPath {
127- .cwd_relative = absolute_file_path ,
128- });
129- d8 .addArg (relative_to_dir_path );
116+ switch (entry .kind ) {
117+ .directory = > {
118+ // NOTE(jae): 2026-03-01
119+ // This step uses the output of various Java files from a .zig-cache folder so
120+ // in theory we shouldn't need to handle addDirectoryWatchInput
121+ //
122+ // if (need_derived_inputs) {
123+ // const entry_path = try search_dir.join(arena, entry.path);
124+ // try step.addDirectoryWatchInputFromPath(entry_path);
125+ // }
126+ },
127+ .file = > {
128+ // NOTE(jae): 2024-10-01
129+ // Initially ignored classes with alternate API postfixes / etc but
130+ // that did not work with SDL2 so no longer do that.
131+ // - !std.mem.containsAtLeast(u8, entry.basename, 1, "$") and
132+ // - !std.mem.containsAtLeast(u8, entry.basename, 1, "_API")
133+ if (std .mem .endsWith (u8 , entry .path , file_ext )) {
134+ const absolute_file_path = try search_dir .root_dir .join (arena , &.{ search_dir .sub_path , entry .path });
135+ const relative_to_dir_path = absolute_file_path [search_dir .sub_path .len + 1 .. ];
136+ // NOTE(jae): 2024-09-22
137+ // We set the current working directory to "glob.Dir" and then make arguments be
138+ // relative to that directory.
139+ //
140+ // This is to avoid the Java error "command line too long" that can occur with d8
141+ if (optional_argv_start == null ) {
142+ optional_argv_start = d8 .argv .items .len ;
143+ optional_file_input_start = d8 .file_inputs .items .len ;
144+ }
145+ d8 .addArg (relative_to_dir_path );
146+ d8 .addFileInput (LazyPath {
147+ .cwd_relative = absolute_file_path ,
148+ });
149+ }
150+ },
151+ else = > continue ,
130152 }
131153 }
132154
133155 // Track arguments added to "d8" so that we can remove them if "make" is re-run in --watch mode
134156 if (optional_argv_start ) | argv_start | {
135- glob .argv_range = .{
136- .start = argv_start ,
137- .end = d8 .argv .items .len ,
157+ const file_input_start = optional_file_input_start orelse unreachable ;
158+ const len : u32 = @intCast (d8 .argv .items .len - argv_start );
159+ assert (len == d8 .file_inputs .items .len - file_input_start );
160+ self .argv_range = .{
161+ .argv_start = argv_start ,
162+ .file_input_start = file_input_start ,
163+ .len = len ,
138164 };
139165 }
140166}
0 commit comments