Run it
Single-header verification in 2 minutes, plus four hands-on network routes.
Step 2Integrate
Build system, release shapes, and feature trimming.
Step 3See the whole picture
Repository layout, concurrency models, module map, and extensions.
AfterwardsLearn & look up
The 144-chapter tutorial, API reference, and stability evidence.
2.0.0-dev.Start using XRT with one C file
Open single/xrt.h in the repository, save it next to you via the Raw / download button, then create main.c.
#define XRT_IMPLEMENTATION #include "xrt.h" #include <stdio.h> int main(void) { printf("XRT %s\n", XRT_VERSION_TEXT); return 0; }
cc -std=c11 -O2 main.c -o hello ./hello
gcc -std=c11 -O2 main.c -o hello.exe .\hello.exe
Expected output: XRT 2.0.0-dev. The minimal example above needs no extra network system libraries; when networking features are enabled, the repository build tool configures the platform link options.
HTTP / HTTPS client
Start from a verified synchronous GET client that prints the status code and body; then move on to async Futures, cookies, retries, and connection pooling.
extlibs/xhttp/examples/http/client_easy/main.cHTTPS: client_https/main.cSuccess: status code and body receivedTCP echo service
Start a loopback listener, echo client data, then dig into hard backpressure, connection shutdown, and server lifecycles as needed.
examples/network/tcp_server/main.cListen: 127.0.0.1:dynamic portSuccess: listening endpoint printed and one echo round completedTLS request with certificate verification
Make an HTTPS request against the system trust store. The default path covers DNS, TCP, TLS 1.3, SNI, certificate identity verification, and HTTP/1.1.
extlibs/xhttp/examples/http/client_https/main.cInput: one https:// URLSuccess: secure=yes and the response sizeHTTP server with health check
Start a raw-response server that returns JSON for /health and 404 elsewhere. It is also the basis of the raw path in the performance benchmarks.
extlibs/xhttp/examples/http/server_raw/main.cEndpoint: /healthSuccess: returns {"code":200,"msg":"OK"}Build system and verified examples
The network examples live in examples/ and the extensions' examples/,
and pair with their test suites for learning calls and lifecycles. The unified build entry tools/build.py provides:
SHA256-fingerprint incremental compilation, module dependency-closure expansion, and automatic response-file switching for long Windows command lines;
the GCC / Clang / MSVC (including clang-cl) / TCC compiler families are interchangeable. build.bat and build.sh are thin wrappers around it.
git clone https://gitee.com/xywhsoft/xrt.git cd xrt # Default: build and run the kernel tests (build.bat on Windows, ./build.sh on Linux/macOS) python tools/build.py # Pick a suite: module name, comma combinations, or all; --jobs parallelizes, --start-test resumes from a failure python tools/build.py --suite core,concurrency --jobs 4 python tools/build.py --suite all --start-test test_http_client # Extension libraries: layer the extension manifest python tools/build.py --manifest extlibs/xhttp/config/modules.json --suite xhttp_tests python tools/build.py --manifest extlibs/xws/config/modules.json --suite xws_tests # Package static / shared libraries and compile+run consumer programs to verify python tools/package.py --kind static --verify python tools/package.py --manifest extlibs/xhttp/config/modules.json --kind shared --verify # Regenerate the single-header artifact (supports --manifest and --check drift verification) python tools/amalgamate.py
Choose a release shape
Single header (fast integration)
/* single/xrt.h contains the full implementation; extensions likewise (e.g. extlibs/xhttp/single/xhttp.h) */ #define XRT_IMPLEMENTATION #include "xrt.h"
Modular / library (engineering integration)
Use tools/package.py to produce static or shared libraries (with import libraries), or bring the kernel sources straight into your build —
the module manifests already declare every source file's ownership and dependencies. Header paths are uniformly <xrt/xxx.h>.
Choose by project boundary, not by jargon: single header for prototypes and tools, libraries for product builds.
Feature trimming system
Trimming works in units of module macros: after defining XRT_MODULE_<NAME>, include/xrt/features.h
(generated from modules.json by tools/generate_features.py) automatically expands its dependency closure and sets the corresponding
XRT_FEATURE_* macros; a missing dependency raises a direct #error in the header.
/* Just TCP networking and coroutines */ #define XRT_MODULE_NET_TCP #define XRT_MODULE_COROUTINE #include "xrt.h" /* Enable everything */ /* #define XRT_MODULE_ALL */
Trimming correctness is guarded by two gates:
- Reverse trim verification (
build.py --trim-only): for every module, its direct dependency macros are deliberately removed and compilation must fail, preventing missing guards. - Symbol ban (
measure_size.py): the minimal core trim artifact must not contain symbols with prefixes likexrtNet / xrtHttp / xrtWs / xrtTls / xrtRegex— binary-level prevention of feature creep.
Extensions have a parallel macro system (XHTTP_MODULE_*, XWS_MODULE_*…), generated by generate_extension_features.py, chaining kernel module macros as requirements.
Getting to know XRT
XRT is a systematic cross-platform C infrastructure library, aiming to provide a complete infrastructure loop with zero third-party runtime dependencies for the Internet + AI era. Since v2.0, the repository splits into two parts:
- Kernel (
src/+include/xrt/): concurrent coroutines, the five-backend network engine, TLS, the HTTP/WebSocket protocol core, memory and containers, files and processes, regex and pattern matching. 94 public headers; the module manifests declare 386 distinct feature macros. - Extension libraries (
extlibs/): five independent products split by domain — xhttp, xws, xruntime, xmail, xssh. Each is a self-contained mini-project (its own src / include / tests / examples / config / single) depending one-way on the kernel. The xregex library has been merged into the kernelregexmodule.
Two consumption shapes: modular sources / static library / shared library, or the self-contained single header (the kernel and every extension each ship one).
Repository tour
| Directory | Contents |
|---|---|
include/xrt/ | Kernel public headers. Every exported function uses the XRT_API macro and the xrt prefix. |
src/ | Kernel implementation organized by capability domain, with private contract headers under src/internal/. |
extlibs/ | The five extension libraries. Public headers install into the xrt/ namespace (e.g. <xrt/http_client.h>); facade headers are <xhttp.h>, <xws.h>, etc. |
config/modules.json | The kernel module manifest — the single source of truth: headers, sources, tests, examples, and dependencies of every module. |
tools/ | Toolchain entries: build.py (build), package.py (packaging), amalgamate.py (single-header merge), measure_size / measure_performance (measurement), generate_features / generate_api_reference (generators). |
tests/ | Kernel tests; tests/single/ provides single-header build and call probes. |
examples/ | Examples organized by module, showing complete flows from setup and calls to resource release. |
single/ | Kernel single-header artifacts xrt.h / xrt_decl.h. |
fuzz/ | libFuzzer targets (HTTP/WS protocols and more). |
dev/ | Performance benchmarks (dated reports), controlled archives, and development-process assets. |
Concurrency models: pick by problem, use them all if you must — or not
Threads, coroutines, Channel, Future, task groups, and cancellation tokens each solve a different boundary. First decide whether the work needs true parallelism, I/O waiting, message passing, result composition, or a coordinated stop; then pick the smallest set of mechanisms.
| Mechanism | Prefer it for | Boundaries & next steps |
|---|---|---|
| Threads & synchronization | CPU parallelism, integrating blocking interfaces, guarding shared state. | Use mutex / rwlock / cond / sem / once to make sharing explicit; start with Chapter 52. |
| Stackful coroutines & scheduler | I/O waiting, readability-first stepwise flows, timing and resumption. | Coroutines run cooperatively inside a scheduler and don't replace OS threads; read Chapter 54 and Chapter 55. |
| Channel / select | Producer-consumer, handing work across execution units, waiting on several message sources at once. | Use message passing to shrink shared state; read Chapter 56. |
| Future / Promise | Composing async completion events — continuation, joining, racing, or failure handling. | Describe result dependencies with then / catch / any / all / race; read Chapter 57. |
| executor / task group | Reusing a thread pool, batch submission, waiting on a controlled group of work. | Separate execution resources from task scope; read Chapter 58. |
| deadline / cancel | Request timeouts, connection shutdown, service stops, or aborting a task chain. | Let stop signals propagate along the cancellation-token tree and finish necessary cleanup before exit; read Chapter 59. |
Suggested learning order
Master threads and synchronization first, then coroutine scheduling; next organize workflows with Channel and Future; finally compose executor, task groups, and cancellation into the service lifecycle.
The repository offers directly comparable examples: examples/concurrency/thread, coroutine, channel_select, future_combine, task_group, and cancel.
Kernel module map
A quick lookup of modules grouped by system (public headers under include/xrt/; full per-API documentation in the API reference):
| System | Modules / headers |
|---|---|
| Foundation | core error error_format atomic memory memory_debug math hash random xid |
| Data & containers | array map set avl list buffer queue (MPMC/MPSC/SPSC) slot_map value json xlon jsonl xlonl string charset number html regex pattern codec compress template |
| Concurrency | coroutine channel future future_bridge executor task cancel mutex/cond/sem/rwlock/once |
| System services | file file_async path process signal logger io time environment console |
| Networking | net tcp udp proxy net_frame net_file net_interface |
| Security | crypto asn1 pem x509 tls tls_client tls_server tls_session tls_stream |
| Web protocols | http http1 http1_net http1_tls http_connection http_decode http_encoding http_te http_trailer http_upgrade websocket websocket_stream websocket_upgrade |
Extension library guide
Every extension shares one directory layout: src/ include/ tests/ examples/ bench/ config/modules.json single/ docs/. Public headers stay in the xrt/ namespace, stitching seamlessly with kernel headers.
xhttp — HTTP client & server
Entry <xhttp.h>; layered headers <xrt/http_client.h>, <xrt/http_server_runtime.h> and 70 more. Covers URL / Query / Form / MIME / Cookie / SSE / multipart / static files. Error component name "xhttp".
xws — WebSocket runtime
Entry <xws.h>; runtime APIs in <xrt/websocket_runtime.h>. The client reuses the entire xhttp stack (proxy / cookies / timeouts all apply), with group broadcast and zero-copy sending.
xruntime — dynamic types & object system
Entry <xruntime.h>; type registry, reference-counted objects, object-graph reclamation, dynamic invocation, typed container projections (<xrt/typed_*.h>).
xmail — mail protocol suite
SMTP (STARTTLS / BDAT / XOAUTH2), IMAP4 (IDLE / COMPRESS=DEFLATE / BODYSTRUCTURE), POP3, MIME parsing and building, RFC 2047/2231 codecs.
extlibs/xmail/ · 51 modulesxssh — SSH2 protocol stack
Transport, curve25519-sha256 KEX, ssh-ed25519 host keys, AES-GCM encryption, password/publickey/hostbased/keyboard-interactive authentication, channels and port forwarding.
extlibs/xssh/ · 68 modulesHow tests and examples are organized
Test file name suffixes encode the test dimension, and the same contract appears in several variants (e.g. test_http_client_iocp.c
is one #define line + #include "test_http_client.c"):
| Suffix | Meaning |
|---|---|
_oom | OOM fault injection: the N-th allocation fails exactly / budget exhausted / all fail |
_noalloc | Zero-heap-allocation contract: allocation forbidden throughout the operation |
_iocp / _uring / _epoll / _kqueue / _select | Instantiated per event backend |
_threads / _race | Multi-threaded concurrency / precisely controlled race windows |
_tls | TLS-link variant |
_mutation / _fuzz / _stress | Mutation equivalence / deterministic random fuzzing / stress |
tests/single/ | Single-header equivalence probes (amalgamated artifact = modular build) |
The kernel and five extensions provide 680 example C files and 2,512 test C files. Use the module manifests to find sources and build entries, then follow call flows into the implementation.
Suggested learning path
- Get the build running:
python tools/build.py --suite core; watch fingerprint increments and test output. - Read examples: pick a
main.cfromexamples/for a module you care about; understand setup, calls, and resource wind-down. - Read tests: pair with assertions in
tests/<module>/to understand interface behavior and boundary conditions. - Try trimming: use
XRT_MODULE_*macros to carve out your minimal set and verify with--trim-only.
Where to go next
Single header, sources, or library
Back to the engineering-integration part of this page for release shapes and trimming constraints.
LearnEnter the tutorial
Follow the network-service, client, or project tracks through the chapters.
Look upLocate modules and APIs
Search a function name and jump straight to signatures, parameters, returns, and examples.
VerifyMeet engineering quality
Learn the error model, protocol design, fault injection, and build verification.
Resource links
- Gitee repository — sources and issue tracking
- API reference — per-API docs for 96 modules
- Architecture overview — kernel + extensions layering