Followup from #35428.
There is already https://github.com/ziglang/zig/issues/615 to track serving Compilation information. This is for stuff like type information, looking up definitions, refactoring, etc.
By contrast, this issue is to implement the build system protocol which is a higher layer, exposed by zig build --listen=-, which provides a machine interface to the build system. Thanks to #35428 the entire build graph is available in read-only serialized form, however, what's lacking is interactivity. Connected clients, which are IDEs and related tooling, need access to generated file paths, error bundles and other messages, and success status for each step. Furthermore, they need to be able to control the maker process by issuing a rebuild command.
The CLI flag will be --listen=- which turns stdin/stdout into the build system protocol. --listen=[ip] will be reserved for listening via network socket, but not implemented at first. stderr reserved for troubleshooting the maker process itself. This will cause the maker process to be long-running, the same as if --webui, --watch, or --fuzz is passed. However, the process should not panic or otherwise crash if file watching cannot be performed. Instead the file watching failure should be communicated via the protocol to the parent process. File watching is still an independent feature that can be enabled or disabled simultaneously with the build system protocol.
Unlike some of the other protocols only used for zig-version-locked processes talking to each other, this protocol faces third party software. As such, it needs to be independently versioned and benefits from ABI stability. For now, the plan is to have an integer protocol version and bump it whenever any backwards incompatible changes to the protocol are made. The configuration file format also should have this version.
MVP Protocol Specifics
This is the issue close criteria, which should unblock ZLS from updating to latest Zig.
Upon first connection, server sends to client:
- protocol version
- path to configuration file
Server does not kick off a build until client sends a build message. If any -D CLI flags or step names are provided along with --listen, maker process reports an error and exits.
Client to server messages:
- build (protocol equivalent of
zig build ...)- set of step names
- set of options (equivalent to
-Don the command line)
Server to client messages:
- build started (might trigger due to explicit rebuild, or due to file system watching)
- build complete
- for each step:
- status
- error bundle / other error information
- peak rss and duration
- set of generated files that changed
- for each step:
- configuration file changed, path to new configuration file. All messages after this reference the new configuration.
- log messages (info, warning, debug, error) pertaining to the maker process itself. For example, error, file watching could not be initialized.
When closing this issue, file new issues as follow-up enhancements:
Followup Enhancement: Run Proxy
IDE needs to be able to drive a particular child process execution so that it can let the user drive a debugger (think breakpoints on source locations).
- client to server messages:
- enable/disable run proxy for a particular run step
- ran command
- server to client messages:
- run command request
- argv, environ
- need to send a ran command response
- run command request
Followup Enhancement: Unit Testing
- provide (live!) source coverage information
- ability to choose which unit tests to run
- fuzz testing status updates & other integration