@@ -23,8 +23,8 @@ config: Config,
2323lock : std.Thread.RwLock = .{},
2424thread_pool : if (builtin .single_threaded ) void else * std.Thread.Pool ,
2525handles : std .StringArrayHashMapUnmanaged (* Handle ) = .empty ,
26- build_files : std .StringArrayHashMapUnmanaged (* BuildFile ) = .empty ,
27- cimports : std .AutoArrayHashMapUnmanaged (Hash , translate_c .Result ) = .empty ,
26+ build_files : if ( supports_build_system ) std .StringArrayHashMapUnmanaged (* BuildFile ) else void = if ( supports_build_system ) .empty else {} ,
27+ cimports : if ( supports_build_system ) std .AutoArrayHashMapUnmanaged (Hash , translate_c .Result ) else void = if ( supports_build_system ) .empty else {} ,
2828diagnostics_collection : * DiagnosticsCollection ,
2929builds_in_progress : std .atomic .Value (i32 ) = .init (0 ),
3030transport : ? lsp.AnyTransport = null ,
@@ -41,6 +41,8 @@ pub const Hash = [Hasher.mac_length]u8;
4141
4242pub const max_document_size = std .math .maxInt (u32 );
4343
44+ pub const supports_build_system = std .process .can_spawn ;
45+
4446pub fn computeHash (bytes : []const u8 ) Hash {
4547 var hasher : Hasher = .init (&@splat (0 ));
4648 hasher .update (bytes );
@@ -316,6 +318,7 @@ pub const Handle = struct {
316318 /// `DocumentStore.build_files` is guaranteed to contain this Uri.
317319 /// Uri memory managed by its build_file
318320 pub fn getAssociatedBuildFileUri (self : * Handle , document_store : * DocumentStore ) error {OutOfMemory }! ? Uri {
321+ comptime std .debug .assert (supports_build_system );
319322 switch (try self .getAssociatedBuildFileUri2 (document_store )) {
320323 .none ,
321324 .unresolved ,
@@ -336,6 +339,8 @@ pub const Handle = struct {
336339 /// The associated build file (build.zig) has been successfully resolved.
337340 resolved : * BuildFile ,
338341 } {
342+ comptime std .debug .assert (supports_build_system );
343+
339344 self .impl .lock .lock ();
340345 defer self .impl .lock .unlock ();
341346
@@ -634,16 +639,19 @@ pub fn deinit(self: *DocumentStore) void {
634639 }
635640 self .handles .deinit (self .allocator );
636641
637- for (self .build_files .values ()) | build_file | {
638- build_file .deinit (self .allocator );
639- self .allocator .destroy (build_file );
640- }
641- self .build_files .deinit (self .allocator );
642+ if (supports_build_system ) {
643+ for (self .build_files .values ()) | build_file | {
644+ build_file .deinit (self .allocator );
645+ self .allocator .destroy (build_file );
646+ }
647+ self .build_files .deinit (self .allocator );
642648
643- for (self .cimports .values ()) | * result | {
644- result .deinit (self .allocator );
649+ for (self .cimports .values ()) | * result | {
650+ result .deinit (self .allocator );
651+ }
652+ self .cimports .deinit (self .allocator );
645653 }
646- self . cimports . deinit ( self . allocator );
654+
647655 self .* = undefined ;
648656}
649657
@@ -718,6 +726,7 @@ pub fn getOrLoadHandle(self: *DocumentStore, uri: Uri) ?*Handle {
718726/// **Thread safe** takes a shared lock
719727/// This function does not protect against data races from modifying the BuildFile
720728pub fn getBuildFile (self : * DocumentStore , uri : Uri ) ? * BuildFile {
729+ comptime std .debug .assert (supports_build_system );
721730 self .lock .lockShared ();
722731 defer self .lock .unlockShared ();
723732 return self .build_files .get (uri );
@@ -727,6 +736,8 @@ pub fn getBuildFile(self: *DocumentStore, uri: Uri) ?*BuildFile {
727736/// **Thread safe** takes an exclusive lock
728737/// This function does not protect against data races from modifying the BuildFile
729738fn getOrLoadBuildFile (self : * DocumentStore , uri : Uri ) ? * BuildFile {
739+ comptime std .debug .assert (supports_build_system );
740+
730741 if (self .getBuildFile (uri )) | build_file | return build_file ;
731742
732743 const new_build_file : * BuildFile = blk : {
@@ -754,9 +765,7 @@ fn getOrLoadBuildFile(self: *DocumentStore, uri: Uri) ?*BuildFile {
754765
755766 // this code path is only reached when the build file is new
756767
757- if (std .process .can_spawn ) {
758- self .invalidateBuildFile (new_build_file .uri );
759- }
768+ self .invalidateBuildFile (new_build_file .uri );
760769
761770 return new_build_file ;
762771}
@@ -817,8 +826,10 @@ pub fn closeDocument(self: *DocumentStore, uri: Uri) void {
817826 defer self .lock .unlock ();
818827
819828 self .garbageCollectionImports () catch {};
820- self .garbageCollectionCImports () catch {};
821- self .garbageCollectionBuildFiles () catch {};
829+ if (supports_build_system ) {
830+ self .garbageCollectionCImports () catch {};
831+ self .garbageCollectionBuildFiles () catch {};
832+ }
822833}
823834
824835/// Takes ownership of `new_text` which has to be allocated with this DocumentStore's allocator.
@@ -864,7 +875,7 @@ pub fn refreshDocumentFromFileSystem(self: *DocumentStore, uri: Uri) !bool {
864875/// Invalidates a build files.
865876/// **Thread safe** takes a shared lock
866877pub fn invalidateBuildFile (self : * DocumentStore , build_file_uri : Uri ) void {
867- comptime std .debug .assert (std . process . can_spawn );
878+ comptime std .debug .assert (supports_build_system );
868879
869880 if (self .config .zig_exe_path == null ) return ;
870881 if (self .config .build_runner_path == null ) return ;
@@ -1464,7 +1475,9 @@ fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]const u8, open: bool
14641475
14651476 _ = handle .setOpen (open );
14661477
1467- if (isBuildFile (handle .uri ) and ! isInStd (handle .uri )) {
1478+ if (! supports_build_system ) {
1479+ // nothing to do
1480+ } else if (isBuildFile (handle .uri ) and ! isInStd (handle .uri )) {
14681481 _ = self .getOrLoadBuildFile (handle .uri );
14691482 } else if (! isBuiltinFile (handle .uri ) and ! isInStd (handle .uri )) blk : {
14701483 const potential_build_files = self .collectPotentialBuildFiles (uri ) catch {
@@ -1614,6 +1627,8 @@ fn collectDependenciesInternal(
16141627 const tracy_zone = tracy .trace (@src ());
16151628 defer tracy_zone .end ();
16161629
1630+ if (! supports_build_system ) return ;
1631+
16171632 {
16181633 if (lock ) store .lock .lockShared ();
16191634 defer if (lock ) store .lock .unlockShared ();
@@ -1656,6 +1671,8 @@ pub fn collectIncludeDirs(
16561671 handle : * Handle ,
16571672 include_dirs : * std .ArrayListUnmanaged ([]const u8 ),
16581673) ! bool {
1674+ comptime std .debug .assert (supports_build_system );
1675+
16591676 var arena_allocator : std.heap.ArenaAllocator = .init (allocator );
16601677 defer arena_allocator .deinit ();
16611678
@@ -1695,6 +1712,8 @@ pub fn collectCMacros(
16951712 handle : * Handle ,
16961713 c_macros : * std .ArrayListUnmanaged ([]const u8 ),
16971714) ! bool {
1715+ comptime std .debug .assert (supports_build_system );
1716+
16981717 const collected_all = switch (try handle .getAssociatedBuildFileUri2 (store )) {
16991718 .none = > true ,
17001719 .unresolved = > false ,
@@ -1719,10 +1738,11 @@ pub fn collectCMacros(
17191738/// returned memory is owned by DocumentStore
17201739/// **Thread safe** takes an exclusive lock
17211740pub fn resolveCImport (self : * DocumentStore , handle : * Handle , node : Ast.Node.Index ) error {OutOfMemory }! ? Uri {
1741+ comptime std .debug .assert (supports_build_system );
1742+
17221743 const tracy_zone = tracy .trace (@src ());
17231744 defer tracy_zone .end ();
17241745
1725- if (! std .process .can_spawn ) return null ;
17261746 if (self .config .zig_exe_path == null ) return null ;
17271747 if (self .config .zig_lib_dir == null ) return null ;
17281748 if (self .config .global_cache_dir == null ) return null ;
@@ -1891,17 +1911,21 @@ pub fn uriFromImportStr(self: *DocumentStore, allocator: std.mem.Allocator, hand
18911911
18921912 return try URI .fromPath (allocator , std_path );
18931913 } else if (std .mem .eql (u8 , import_str , "builtin" )) {
1894- if (try handle .getAssociatedBuildFileUri (self )) | build_file_uri | {
1895- const build_file = self .getBuildFile (build_file_uri ).? ;
1896- if (build_file .builtin_uri ) | builtin_uri | {
1897- return try allocator .dupe (u8 , builtin_uri );
1914+ if (supports_build_system ) {
1915+ if (try handle .getAssociatedBuildFileUri (self )) | build_file_uri | {
1916+ const build_file = self .getBuildFile (build_file_uri ).? ;
1917+ if (build_file .builtin_uri ) | builtin_uri | {
1918+ return try allocator .dupe (u8 , builtin_uri );
1919+ }
18981920 }
18991921 }
19001922 if (self .config .builtin_path ) | builtin_path | {
19011923 return try URI .fromPath (allocator , builtin_path );
19021924 }
19031925 return null ;
19041926 } else if (! std .mem .endsWith (u8 , import_str , ".zig" )) {
1927+ if (! supports_build_system ) return null ;
1928+
19051929 if (try handle .getAssociatedBuildFileUri (self )) | build_file_uri | blk : {
19061930 const build_file = self .getBuildFile (build_file_uri ).? ;
19071931 const build_config = build_file .tryLockConfig () orelse break :blk ;
0 commit comments