@@ -303,36 +303,38 @@ pub fn fetchAndAddDependencies(
303303 root_prog_node ,
304304 );
305305
306- if (! sub .found_existing ) {
307- try sub .mod .fetchAndAddDependencies (
308- deps_pkg ,
309- arena ,
310- thread_pool ,
311- http_client ,
312- sub .mod .root_src_directory ,
313- global_cache_directory ,
314- local_cache_directory ,
315- dependencies_source ,
316- build_roots_source ,
317- sub_prefix ,
318- error_bundle ,
319- all_modules ,
320- root_prog_node ,
321- );
322- }
306+ if (sub .mod ) | mod | {
307+ if (! sub .found_existing ) {
308+ try mod .fetchAndAddDependencies (
309+ deps_pkg ,
310+ arena ,
311+ thread_pool ,
312+ http_client ,
313+ mod .root_src_directory ,
314+ global_cache_directory ,
315+ local_cache_directory ,
316+ dependencies_source ,
317+ build_roots_source ,
318+ sub_prefix ,
319+ error_bundle ,
320+ all_modules ,
321+ root_prog_node ,
322+ );
323+ }
323324
324- try pkg .add (gpa , name , sub . mod );
325- if (deps_pkg .table .get (dep .hash .? )) | other_sub | {
326- // This should be the same package (and hence module) since it's the same hash
327- // TODO: dedup multiple versions of the same package
328- assert (other_sub == sub . mod );
329- } else {
330- try deps_pkg .add (gpa , dep .hash .? , sub . mod );
331- }
325+ try pkg .add (gpa , name , mod );
326+ if (deps_pkg .table .get (dep .hash .? )) | other_sub | {
327+ // This should be the same package (and hence module) since it's the same hash
328+ // TODO: dedup multiple versions of the same package
329+ assert (other_sub == mod );
330+ } else {
331+ try deps_pkg .add (gpa , dep .hash .? , mod );
332+ }
332333
333- try dependencies_source .writer ().print (" pub const {s} = @import(\" {}\" );\n " , .{
334- std .zig .fmtId (fqn ), std .zig .fmtEscapes (dep .hash .? ),
335- });
334+ try dependencies_source .writer ().print (" pub const {s} = @import(\" {}\" );\n " , .{
335+ std .zig .fmtId (fqn ), std .zig .fmtEscapes (dep .hash .? ),
336+ });
337+ }
336338 }
337339}
338340
@@ -420,7 +422,10 @@ const MultiHashHexDigest = [hex_multihash_len]u8;
420422/// This is to avoid creating multiple modules for the same build.zig file.
421423/// If the value is `null`, the package is a known dependency, but has not yet
422424/// been fetched.
423- pub const AllModules = std .AutoHashMapUnmanaged (MultiHashHexDigest , ? * Package );
425+ pub const AllModules = std .AutoHashMapUnmanaged (MultiHashHexDigest , ? union (enum ) {
426+ zig_pkg : * Package ,
427+ non_zig_pkg : void ,
428+ });
424429
425430fn ProgressReader (comptime ReaderType : type ) type {
426431 return struct {
@@ -474,7 +479,7 @@ fn fetchAndUnpack(
474479 fqn : []const u8 ,
475480 all_modules : * AllModules ,
476481 root_prog_node : * std.Progress.Node ,
477- ) ! struct { mod : * Package , found_existing : bool } {
482+ ) ! struct { mod : ? * Package , found_existing : bool } {
478483 const gpa = http_client .allocator ;
479484 const s = fs .path .sep_str ;
480485
@@ -503,15 +508,26 @@ fn fetchAndUnpack(
503508 if (gop .found_existing ) {
504509 if (gop .value_ptr .* ) | mod | {
505510 gpa .free (build_root );
506- return .{
507- .mod = mod ,
508- .found_existing = true ,
509- };
511+ switch (mod ) {
512+ .zig_pkg = > | pkg | return .{
513+ .mod = pkg ,
514+ .found_existing = true ,
515+ },
516+ .non_zig_pkg = > return .{
517+ .mod = null ,
518+ .found_existing = true ,
519+ },
520+ }
510521 }
511522 }
512523
513524 root_prog_node .completeOne ();
514525
526+ pkg_dir .access (build_zig_basename , .{}) catch return .{
527+ .mod = null ,
528+ .found_existing = false ,
529+ };
530+
515531 const ptr = try gpa .create (Package );
516532 errdefer gpa .destroy (ptr );
517533
@@ -527,7 +543,7 @@ fn fetchAndUnpack(
527543 .root_src_path = owned_src_path ,
528544 };
529545
530- gop .value_ptr .* = ptr ;
546+ gop .value_ptr .* = .{ . zig_pkg = ptr } ;
531547 return .{
532548 .mod = ptr ,
533549 .found_existing = false ,
@@ -673,8 +689,20 @@ fn fetchAndUnpack(
673689 std .zig .fmtId (fqn ), std .zig .fmtEscapes (build_root ),
674690 });
675691
692+ {
693+ var build_root_dir = try std .fs .openDirAbsolute (build_root , .{});
694+ defer build_root_dir .close ();
695+ build_root_dir .access (build_zig_basename , .{}) catch {
696+ try all_modules .put (gpa , actual_hex , .non_zig_pkg );
697+ return .{
698+ .mod = null ,
699+ .found_existing = false ,
700+ };
701+ };
702+ }
703+
676704 const mod = try createWithDir (gpa , global_cache_directory , pkg_dir_sub_path , build_zig_basename );
677- try all_modules .put (gpa , actual_hex , mod );
705+ try all_modules .put (gpa , actual_hex , .{ . zig_pkg = mod } );
678706 return .{
679707 .mod = mod ,
680708 .found_existing = false ,
0 commit comments