Step 1

Run it

Single-header verification in 2 minutes, plus four hands-on network routes.

Step 2

Integrate

Build system, release shapes, and feature trimming.

Step 3

See the whole picture

Repository layout, concurrency models, module map, and extensions.

Afterwards

Learn & look up

The 144-chapter tutorial, API reference, and stability evidence.

Preparation: the minimal single-header example needs only a C11 compiler. To run the repository examples, have Python 3 ready, clone the XRT repository, and run commands from the repository root. This page targets 2.0.0-dev.
Step 1 · Single-header integration

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.

Get xrt.h →
main.c
#define XRT_IMPLEMENTATION
#include "xrt.h"
#include <stdio.h>

int main(void)
{
    printf("XRT %s\n", XRT_VERSION_TEXT);
    return 0;
}
Linux / macOS
cc -std=c11 -O2 main.c -o hello
./hello
Windows PowerShell / MinGW-w64
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.

5 minutes · xhttp

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.

Example: extlibs/xhttp/examples/http/client_easy/main.cHTTPS: client_https/main.cSuccess: status code and body received
8 minutes · Network kernel

TCP echo service

Start a loopback listener, echo client data, then dig into hard backpressure, connection shutdown, and server lifecycles as needed.

Example: examples/network/tcp_server/main.cListen: 127.0.0.1:dynamic portSuccess: listening endpoint printed and one echo round completed
10 minutes · xhttp + TLS

TLS 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.

Example: extlibs/xhttp/examples/http/client_https/main.cInput: one https:// URLSuccess: secure=yes and the response size
10 minutes · xhttp

HTTP 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.

Example: 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.

Repository root · common commands
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
Extensions compile jointly with the kernel: layer an extension manifest in the same source tree to resolve dependencies, compile, and verify uniformly. You can also pick the extension single headers with the kernel embedded for integration.

Choose a release shape

Single header (fast integration)

main.c
/* 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.

Trimming example
/* 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:

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:

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

DirectoryContents
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.jsonThe 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.

MechanismPrefer it forBoundaries & next steps
Threads & synchronizationCPU parallelism, integrating blocking interfaces, guarding shared state.Use mutex / rwlock / cond / sem / once to make sharing explicit; start with Chapter 52.
Stackful coroutines & schedulerI/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 / selectProducer-consumer, handing work across execution units, waiting on several message sources at once.Use message passing to shrink shared state; read Chapter 56.
Future / PromiseComposing async completion events — continuation, joining, racing, or failure handling.Describe result dependencies with then / catch / any / all / race; read Chapter 57.
executor / task groupReusing a thread pool, batch submission, waiting on a controlled group of work.Separate execution resources from task scope; read Chapter 58.
deadline / cancelRequest 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.

Start with threadsEnter the coroutine tutorialSee concurrency APIs

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):

SystemModules / headers
Foundationcore error error_format atomic memory memory_debug math hash random xid
Data & containersarray 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
Concurrencycoroutine channel future future_bridge executor task cancel mutex/cond/sem/rwlock/once
System servicesfile file_async path process signal logger io time environment console
Networkingnet tcp udp proxy net_frame net_file net_interface
Securitycrypto asn1 pem x509 tls tls_client tls_server tls_session tls_stream
Web protocolshttp 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".

extlibs/xhttp/ · 272 modules

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.

extlibs/xws/ · 74 modules

xruntime — dynamic types & object system

Entry <xruntime.h>; type registry, reference-counted objects, object-graph reclamation, dynamic invocation, typed container projections (<xrt/typed_*.h>).

extlibs/xruntime/ · 47 modules

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 modules

xssh — 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 modules

How 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"):

SuffixMeaning
_oomOOM fault injection: the N-th allocation fails exactly / budget exhausted / all fail
_noallocZero-heap-allocation contract: allocation forbidden throughout the operation
_iocp / _uring / _epoll / _kqueue / _selectInstantiated per event backend
_threads / _raceMulti-threaded concurrency / precisely controlled race windows
_tlsTLS-link variant
_mutation / _fuzz / _stressMutation 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

  1. Get the build running: python tools/build.py --suite core; watch fingerprint increments and test output.
  2. Read examples: pick a main.c from examples/ for a module you care about; understand setup, calls, and resource wind-down.
  3. Read tests: pair with assertions in tests/<module>/ to understand interface behavior and boundary conditions.
  4. Try trimming: use XRT_MODULE_* macros to carve out your minimal set and verify with --trim-only.

Where to go next