To install the Roc Jupyter Kernel on your system:
- The Roc compiler must be installed and available in your system
$PATH(ensurerocis runnable). - Python and Jupyter (Jupyter Notebook or JupyterLab) must be installed.
Clone this repository and build the binary:
zig buildThe compiled binary will be placed at zig-out/bin/iroc.
Run the binary with the --install flag:
./zig-out/bin/iroc --installThis automatically generates the required kernel.json config and registers the spec with Jupyter.
Note
If your Jupyter installation resides in a virtual environment (e.g. conda, virtualenv), make sure to activate that environment before running the install command.
Start Jupyter and create a new notebook selecting the "Roc" kernel:
jupyter notebook
# or
jupyter labTo compile and run the application (expects connection file path as argument):
zig build run -- connection_file.jsonTo execute all unit and integration tests (including the ROUTER <-> DEALER message transmission tests and the handleExecuteRequest logic tests):
zig build test --summary allExpected output:
Build Summary: 5/5 steps succeeded; 7/7 tests passed
test success
+- run test 6 pass (6 total) 69ms MaxRSS:5M
| +- compile test Debug native cached 42ms MaxRSS:34M
+- run test 1 pass (1 total) 1s MaxRSS:2M
+- compile test Debug native success 992ms MaxRSS:299M
- build.zig: Configured to link against the system's
libzmqandlibc. It automatically searches standard Homebrew include/lib paths on macOS. - src/zmq.zig: Low-level C-interop wrapper around standard ZeroMQ calls (contexts, sockets, options, and multipart messages).
- src/protocol.zig: Implementation of the Jupyter JSON Wire Protocol structure, HMAC-SHA256 signature computation, and ZMQ message transmission functions.
- src/root.zig: Package root exporting
zmqandprotocolmodules and registering their tests. - src/main.zig: Application entrypoint that parses the Jupyter connection file, binds ROUTER (shell) and PUB (iopub) sockets, maintains the environment state, and runs the kernel execution request loop.
The ZeroMQ wrapper exposes:
- Context: Handles context creation (
zmq_ctx_new) and clean termination (zmq_ctx_term). - Socket: Wraps socket creation, socket binding, connections, single-part/multipart transmission, and socket option configuration.
- Msg: Wraps
zmq_msg_tfor memory-efficient dynamic receiving of frames. - Generic Options: A compile-time options getter/setter utilizing Zig's reflection system (
@typeInfo) to transparently configure either byte slice (e.g.,ZMQ_SUBSCRIBE) or numeric (e.g.,ZMQ_RCVMORE) options.
- Header & Message Structures: Standard Zig structs matching the Jupyter v5.3 protocol fields. Nested JSON structures (like
parent_header,metadata, andcontent) usestd.json.Valueto prevent parsing failures on variable payloads. - HMAC-SHA256 Signatures: Computes signatures using Zig's native
std.crypto.auth.hmac.sha2.HmacSha256over the concatenatedheader,parent_header,metadata, andcontentfields. The final signature is hex-encoded usingstd.fmt.bytesToHex. - ZMQ Message Helpers: High-level
sendMessageandrecvMessagefunctions that serialize/deserialize complete, signature-validated Jupyter messages over ZeroMQ sockets. - Resource Safety: Uses a
std.heap.ArenaAllocatorinside theParsedMessagestruct to manage the lifetime of parsed JSON values and duplicate ZMQ frames.
- Connection File Parsing: Parses the Jupyter JSON connection file path passed via command line, extracting
shell_port,iopub_port,transport,ip, and the HMACkey. - REPL Child Process: Spawns a persistent
roc repl --rpcsubprocess, managing the session with therepl.start,repl.evaluate, andrepl.stopJSON-RPC methods. - Request Evaluation: Intercepts cell execution requests and evaluates them within the running REPL session. Output and diagnostics (errors or compiler warnings) are collected from the RPC JSON responses.
- Jupyter Streams & Outputs:
- Standard output (
stdout) from the evaluated code is routed to theiopubsocket as astreammessage. - Evaluation results and compiler diagnostics are serialized using strict JSON stringification and published to the
iopubsocket asexecute_resultmessages.
- Standard output (