CLI & Toolchain Reference
The xu command line tool uses a unified single-binary driver architecture, integrating the AOT compiler, semantic checker, test runner, dependency package manager, code formatter, documentation extractor, flowchart mapper, LSP daemon, and atomic release updater into a single toolchain. Every command and sibling tool fully supports standard --help and -h structured help output.
Subcommand Overview
| Command | Syntax | Core Purpose |
|---|---|---|
build | xu build [options] <input.xu...> [native.a/.xulib...] | AOT compile into native machine executables, intermediate object files, or desktop apps |
run | xu run [options] <input.xu...> [-- args] | Compile and immediately execute on the host machine; cleans up temp artifacts unless -o is provided |
debug | xu debug [options] <input.xu...> [-- args] | Build a DWARF-enabled binary and start LLDB, or GDB if LLDB is unavailable. Requires an installed debugger. This is source debugging; xu xacp debug only inspects and launches a program. |
test | xu test [options] <file.xu...> | Build a test harness and execute fn test_* assertion suites and fn bench_* benchmarks |
check | xu check [options] <file.xu...> | Perform lexical, parser, type, and ownership/borrow checking without emitting machine code |
cbind | xu cbind [-o FILE.h] [--target TARGET] [--guard MACRO] <input...> | Emit C header declarations and compile-time layout assertions from Xu FFI surfaces |
init | xu init [options] [module] | Initialize a canonical xu.xun manifest and starter main.xu source in the current directory |
get | xu get [options] <module>@<version> | (Recommended) Add or update an explicit dependency, write to xu.xun, download to vendor/, and refresh xu.lock |
install | xu install [options] [dir] | Resolve the full dependency graph declared in xu.xun via MVS, download to vendor/, and verify locks |
fmt | xu fmt [options] <file.xu...> | Format source files according to official style; -w rewrites files in place (defaults to stdout) |
doc | xu doc [options] [path...] | Extract doc comments to Markdown, or --serve to start the built-in XUDOCS Web live documentation server |
map | xu map [options] [path...] | Analyze code control flows and call graphs to emit Mermaid flowcharts or raw canvas lines |
doctor | xu doctor [options] | Verify host toolchain health, native linkers, C headers, and desktop packaging prerequisites |
native | xu native <cmd> [options] | Native C module compilation, xu.o metadata injection, .xulib multi-target packaging & inspection |
xacp | xu xacp <inspect|run|debug|record|control|attach|connect> ... | Launcher for an XACP-enabled hosted native program. Runs the sibling xu-xacp tool. See XACP control. |
setup | xu setup [options] | Launch the native GUI installer wizard or run silent global environment configuration |
lsp | xu lsp [options] | Start Language Server Protocol (JSON-RPC 2.0) daemon for VS Code, Cursor, Neovim, etc. |
up / update | xu update [options] (or xu up) | Check and download official GitHub releases to atomically update the local compiler and standard library |
env | xu env [options] [var...] | Print active toolchain runtime environment variables and effective build configurations |
help | xu help [command] | Display general help or detailed usage for a specific subcommand (or pass --help / -h) |
--version | xu --version (or --ver) | Display compiler version banner, Git identity, and host machine target |
1. Compilation & Execution (build / run / check)
Input Rules
- File input:
xu build main.xu. Single or multiple.xufiles are compiled directly. - Directory input:
xu build app/. The target directory must contain axu.xunmanifest; compiles every*.xuin that directory as one unified package (non-recursive). - Native archives: Pass
module.aormodule.xulibfor one-step native linking onmacos-arm64andmacos-x64. Other targets require--emit-obj, object conversion, and external linking; see native modules.
Cross-Compilation Targets (--target)
Every official xu compiler binary natively includes all backend architectures out of the box with zero external cross-compiler toolchain setups:
Target (--target) | Operating System & Architecture | Binary Output Format |
|---|---|---|
macos-arm64 | Apple Silicon macOS | Mach-O arm64 |
macos-x64 | Intel macOS | Mach-O x86_64 |
linux-arm64 | Linux aarch64 | ELF 64-bit aarch64 |
linux-x64 | Linux x86_64 | ELF 64-bit x86_64 |
linux-loongarch64 | Linux LoongArch64 | ELF 64-bit loongarch64 |
linux-riscv64 | Linux RISC-V 64 | ELF 64-bit riscv64 |
windows-x64 | Windows 64-bit x86_64 | PE32+ x86-64 |
windows-arm64 | Windows 64-bit ARM64 | PE32+ ARM64 |
wasm32-wasi | WebAssembly runtimes with WASI Preview 1 | .wasm module with WASI imports |
thumbv7em-none | Cortex-M4/M7 Microcontrollers | Bare-metal static ELF / firmware binary |
riscv32imac-none | 32-bit RISC-V Embedded Chips | Bare-metal firmware binary |
Build & Optimization Flags
xu build, xu run, and xu test optimize by default. Pass --no-opt to disable optimization. Xu 0.12.2 removed -O0 through -O3.
| Option | Description |
|---|---|
-o, --output <path> | Specify destination binary path. Windows automatically appends .exe. |
--pgo <file>, --pgo-file=<file> | Profile-Guided Optimization: loads the specified PGO profile file to drive cold-block out-of-line layout and hot-path fall-through reordering, substantially improving L1i cache locality. |
--no-opt | Disable compiler optimization. |
--debug-build | Unoptimized source build with full DWARF line tables and debug symbols. |
-g, --debug | Emit DWARF debug information with the selected optimization policy. |
--offline | Offline build: strictly resolves dependencies from local vendor/ or cache without network requests. |
--frozen | Frozen build: offline and requires exact matches with xu.lock; rejects any missing dependencies. |
--xacp | Embed XACP startup discovery and the stdio control hook. ./app --xacp-help prints the machine-readable summary (capabilities: stdio). Hosted native executables only. |
--xacp-port <PORT> | Also enables XACP. PORT is an integer from 0 through 65535 (--xacp-port=PORT is accepted). 0 disables TCP. A positive port is what <app> --xacp-tcp binds on 127.0.0.1. |
--desktop | Desktop packaging mode: invokes xu-desktop to produce macOS .app, Windows .exe, or Linux ELF bundles. Not combinable with --xacp. |
--phone | Generate a mobile application project. Pass a module directory and --target ios-arm64, ios-simulator-arm64 or android-arm64. -o selects a fresh project directory. |
--phone-profile <ui|game> | Select the mobile host profile for --phone: ui (default Canvas UI host) or game (native SDL GPU host with #app resource packaging). |
--bundle-id <ID> | Set the mobile application identifier for --phone, for example org.example.gallery. |
--www <dir> | Desktop packaging: specify an alternate static web asset directory to embed (overrides www/). |
--emit-obj | Emit native XUOBJ object files for external system linkers instead of final executables. |
Set XU_DUMP_MIR to a function label substring to print its final typed MIR after optimization and before machine code generation. Use * to print all functions.
Examples
# Compile with default optimization
xu build main.xu -o myapp
xu run main.xu -- --port 8080 --verbose
# Run with optimization disabled
xu run main.xu --no-opt -- --port 8080
# Compile for a WASI runtime
xu build src/calc.xu --target wasm32-wasi -o dist/calc.wasm
# Build from an existing lockfile in offline mode
xu build . --frozen -o release/server
XACP control (xu xacp / xu-xacp)
The #xacp API is published in the 0.16.0 SDK extract. This section follows the matching release source. xu xacp runs the sibling xu-xacp tool, built from source with make xu-xacp. Importing #xacp does not embed discovery or a control loop. The release source and smoke scripts define the contract; older example README/design notes can drift on framing, permissions, and timeouts. Native sessions and platform/UI runtime acceptance remain unverified.
xu --help summarizes the tool as “inspect, run, and debug”. xu xacp --help is the full mode list: inspect, run, debug, record, control, attach, and connect PORT.
Build and discovery
xu build --xacp examples/xacp/main.xu -o app
xu build --xacp-port 4321 examples/xacp/main.xu -o app
./app --xacp-help
--xacp-port implies --xacp. The generator accepts a hosted native executable only. Libraries, shared objects, test harnesses, embedded targets, and --desktop are rejected. --xacp-help prints and exits. It is not a control session. For port 0 the summary ends with tcp: disabled (port 0). A positive port prints tcp: enabled and bind: 127.0.0.1:PORT. capabilities stays stdio in both cases. Scanning stops at --, so a business argument --xacp-help after that mark does not print discovery.
Launcher modes
| Mode | What it does |
|---|---|
xu xacp inspect <program> | Runs <program> --xacp-help and prints the discovery text. No business arguments. The target is executed. |
xu xacp run <program> -- args... | Runs business main. Inserts an extra -- before the forwarded arguments. Does not read control stdin. |
xu xacp debug <program> -- args... | Inspects first, then runs with the same boundary. Not a breakpoint debugger. A failed inspect does not continue to run. |
xu xacp record <program> -- args... | Streams at most 1 MiB of stdout. Redirect it yourself. Stderr stays on the terminal. Unix only; Windows prints record is not available on Windows yet and exits 1. It is separate from bounded XAR1 UI sampling through ui.record. |
xu xacp control <program> | Spawns <program> --xacp-stdio and inherits the caller's stdin and stdout. No business arguments. Business main does not run. Hello negotiates INFO or host-token permissions before the request finishes. |
xu xacp attach <program> -- args... | Runs business main; the application must call attach_stdio, register a Screen, and poll from its owning coroutine. It owns protocol stdin/stdout; send logs to stderr. Runtime UI behavior is unverified. |
xu xacp connect PORT | Relays framed stdin/stdout to 127.0.0.1:PORT. One request, then its response. The target must already be listening with --xacp-tcp. PORT is 1..65535. Input frames use XACP/1\n<N>\n followed by exactly N body bytes. EOF at a frame boundary disconnects. |
Arguments for run, debug, record, and attach must follow the tool's --. inspect and control reject extra arguments. A failing child returns its exit status when the tool can read one.
Stdio and loopback TCP
Create control.xacp with the exact hello bytes (Python 3):
python3 - <<'PY'
from pathlib import Path
body = b"id: !i 1\nop: xacp.hello\nargs:\n ver: !ver 1.0.0\n nonce: docs-client\n"
Path("control.xacp").write_bytes(b"XACP/1\n" + str(len(body)).encode("ascii") + b"\n" + body)
PY
# stdio: pipe frames; business main is skipped
xu xacp control ./app < control.xacp
# TCP: build a positive port, listen, then connect from another terminal
xu build --xacp-port 4321 main.xu -o app
./app --xacp-tcp
xu xacp connect 4321 < control.xacp
Both transports use XACP/1\n<N>\n plus exactly N bytes of plain XUN. Count UTF-8 bytes, including body newlines; the prefix is excluded. There is no closing delimiter or extra separator. parse_frame receives only the body after transport decoding. The API guide gives a 69-byte hello and 109-byte response. The first --xacp-stdio or --xacp-tcp before -- wins; ordinary startup does not listen or read control stdin.
TCP listens on 127.0.0.1 only. There is no TLS and no other bind address. Each connection is its own session. Connections are handled one at a time. A bad peer ends that session; the listener keeps accepting. Stdio exits when its session ends. A half frame at EOF returns truncated_frame. A frame over 1 MiB returns frame_too_large and closes that session. Frame errors use id 0; schema errors use a valid id hint when available, otherwise 0.
Hello requires ver: !ver 1.0.0 and a non-empty nonce. Without XU_XACP_TOKEN on the host, permissions are capped at INFO. With a host token, a missing or mismatched client token closes the session with auth_failed; a matching token permits the requested subset of PERM_ALL (15). proc.status returns the pid under INFO. Output/UI operations need their permission bits and return not_implemented without adapters. Startup control has no registered Screen; UI attachment needs registration and polling. Its default request deadline is 5000 ms, configurable with XU_XACP_REQUEST_TIMEOUT_MS (1..600000). Callers still need process/I/O timeouts for stalled targets.
2. Automated Testing (test)
Pass one or more Xu source files to xu test. In 0.12.2, the temporary executable runs the supplied main function. Call your tests from that entry point. Save this example as test.example.xu.
@main
fn test_add() {
assert(1 + 1 == 2)
}
fn main() {
test_add()
}
xu test test.example.xu
xu test test.example.xu --no-opt
xu test test.example.xu -list
Use -list to list parameterless fn test_* declarations.
3. Project Initialization & Dependency Management (init / get / install)
The 0.8.x series delivers a reproducible, hermetic project management and package resolution model:
xu init [module]: Initialize Manifest & Entry
Quickly bootstrap a standardized Xu project in the current working directory:
# 1. Initialize using current directory name as module name
xu init
# 2. Explicitly specify module name
xu init myapp
- Automatic Manifest Generation: Generates a canonical
xu.xunfile with the current compiler version pinned (e.g.xu: !ver 0.16.0). Ifxu.xunalready exists, execution halts with an error to prevent overwriting. - Starter Entry Source: If
main.xuis absent in the directory, creates a clean starter Hello World file. - Ready to Run: Execute
xu run .immediately after initialization to compile and run in milliseconds.
xu get <module>@<version> (New in 0.8.12)
Explicitly add or update a dependency root in the current project:
xu get <module>@<version>
The command above is a syntax template: replace the placeholders with a real module and its published tag. For the official packages documented here, use the SDK bundle or matching fixed source commit with xu install.
- Explicit versions required: Must specify a strict SemVer tag (a verified release tag of the chosen module); rejects
@latestor open ranges to ensure reproducibility. - Transactional safety: Updates
require:inxu.xun, resolves dependencies, downloads sources tovendor/, verifies SHA-256 digests, and writesxu.lock. If network or checksum validation fails, it automatically rolls back with zero project corruption. - Offline resolution: Supports
xu get <module>@<version> --offlineusing existing local caches.
xu install [dir]
Populate and verify the entire vendor tree matching the project's xu.xun:
xu install # Install dependencies for current directory
xu install --offline # Offline mode: use local cache (~/.xu/pkg) only
See Official Packages Catalog and Modules and Dependency Specifications.
4. Code Quality & Documentation (fmt / doc / map)
xu fmt: Code Formatting
xu fmt src/main.xu -w # Rewrite single file in place
xu fmt src/ -w # Recursively format all .xu sources in src/
xu fmt main.xu # Emit formatted result to stdout without file writes
xu doc: API Extraction & Web Server
# 1. Extract public API signatures into Markdown
xu doc src/net --public -o docs/net.md
# 2. Launch built-in XUDOCS Web documentation preview (defaults to 127.0.0.1:6060)
xu doc src/ --serve --addr 127.0.0.1:8080
The --serve HTTP server provides interactive navigation at /, raw Markdown at /docs.md, and a /health probe endpoint.
xu map: Code Topologies & Call Graphs
# Generate Mermaid flowchart diagram
xu map src/main.xu -o flow.mmd
# Output machine-parseable node and edge data lines for custom visualizers
xu map src/ --graph
5. System Maintenance & Updates (doctor / setup / update)
xu doctor: Diagnostics
xu doctor # Check host linkers and toolchain health
xu doctor --desktop # Verify desktop packaging dependencies (WebKitGTK, GTK4, WebView2, MinGW)
xu setup: Native Installer
The companion xu-setup utility includes a self-rendering GUI installer and silent console modes:
xu setup -y # Silent automated install to global PATH and XU_ROOT
xu setup --prefix /opt/xu -y # Install into a custom target directory
xu setup --cli # Force CLI interactive mode on headless servers
xu up / xu update: Official Release Updates
Upgrade the xu toolchain and standard library atomically from official GitHub Releases:
xu up --check # Check if a new official release is available
xu up # Upgrade to the latest stable release
xu update --version 0.16.0 # Pin or downgrade to a specific version
xu update --force # Reinstall the current version
6. Native C Modules & Packaging (xu native)
The companion tool xu-native is integrated as a first-class subcommand xu native, providing native C bridge building, metadata injection, and multi-slice container bundling without external scripts:
# 1. Compile C sources and inject .xumeta into an archive slice (.a)
xu native compile --manifest native.json --target macos-arm64 bridge.c -o native/native_add-arm64.a
# 2. Bundle multi-target slices into a portable container (.xulib)
xu native pack --manifest native.json --slice macos-arm64=native/native_add-arm64.a --slice macos-x64=native/native_add-x64.a -o native/native_add.xulib
# 3. Inspect .xulib slice architectures, sizes, and SHA-256 digests
xu native inspect native/native_add.xulib
# 4. Extract a target slice from a .xulib container
xu native extract native/native_add.xulib --target macos-arm64 -o slice.a
7. Environment Variables (xu env)
Run xu env to inspect active toolchain configurations. Common control variables include:
| Variable | Default | Description & Usage |
|---|---|---|
XU_ROOT | ~/.xu | Root directory of the active Xu toolchain and compiler installation. |
XU_STDLIB_ROOT | $XU_ROOT/src | Explicit path to standard library sources. |
XUPATH | (empty) | Package search paths (: on Unix, ; on Windows). |
XU_CACHE | ~/.xu/pkg | Local cache directory for remote modules and tarball archives. |
XUPROXY | direct | Module proxy URL. Use , for 404 fallback and | for network error fallback. |
XUPRIVATE | (empty) | Glob pattern matching private module paths to bypass public proxies. |
XUSUMDB | direct | Checksum database server; set to off to keep trust-on-first-use (TOFU). |
XUOS | (host OS) | Default target OS when --target is omitted (linux, macos, windows, none). |
XUARCH | (host arch) | Default target arch when --target is omitted (arm64, x64, riscv64, etc.). |
8. Language Server Protocol & IDEs (xu lsp)
The companion tool xu-lsp implements the standard Language Server Protocol (JSON-RPC 2.0) over stdin/stdout, integrating with modern editors (VS Code, Cursor, Neovim, Helix, etc.):
# Start the LSP server daemon (usually managed by editor extensions)
xu lsp
# Show LSP options and flags
xu lsp --help
主な機能:リアルタイム構文・借用診断、F12 / Cmd+Click による定義へ移動、Markdown ホバーヒント、ドキュメントシンボルアウトライン(Cmd+Shift+O)、ワークスペースシンボル検索(workspace/symbol)、スマート補完、すべての参照の検索(Shift+F12)、シンボル名変更(F2)、およびクイックフィックス Code Action(textDocument/codeAction、非推奨の or エラーハンドラを >>> へ移行するアクションや可変性修正を含む)。詳細は VS Code / Cursor ガイドを参照してください。
9. Subcommand Help & Formatted Output (help & --help)
Xu adheres to strict CLI ergonomic conventions: all built-in subcommands and sibling tools natively support standard --help and -h, always exiting with status code 0:
| Help Invocation | Example | Behavior & Description |
|---|---|---|
| Subcommand Flag | xu build --help or xu build -h | Prints synopsis, argument list, and dedicated options for the subcommand |
| Hierarchical Help | xu help build, xu help native | Equivalent to --help, familiar to Go and Cargo users |
| Nested Subcommands | xu native compile --help | Secondary subcommands provide dedicated syntax and flag references |
| Sibling Tool Help | xu fmt --help, xu doctor --help | Gracefully prints formatted help even if sibling binaries are missing on PATH |
Running xu --help or xu help produces a clean, grouped, and beautifully aligned terminal layout:
$ xu --help
usage: xu <command> [arguments]
Build and execution commands:
build compile Xu source files into an executable or library
run compile and immediately execute a Xu program
test build and run test harness binaries (fn test_*)
check parse and type/borrow check without code generation
Package and module commands:
init initialize a new Xu module and create xu.xun manifest
get add or update a pinned module dependency in xu.xun
install download remote require: packages into vendor/
env print Xu toolchain and environment variables
Development and diagnostic tools:
fmt format Xu source files via sibling xu-fmt
doc render declarations as Markdown via sibling xu-doc
map visualize source architecture flowchart via sibling xu-map
doctor check host tools and dependencies via sibling xu-doctor
native compile, archive, pack, and inspect native C modules
xacp inspect, run, and debug XACP-enabled programs
lsp Language Server Protocol daemon via sibling xu-lsp
setup launch native installer via sibling xu-setup
Toolchain management:
up, update download latest release and update toolchain
help show help for xu or a specific subcommand
--ver, --version show toolchain version
Common build options:
-o, --output OUT output binary path (default a.out)
--target TARGET target platform (macos-arm64, linux-x64, wasm32-wasi, xtensa-esp32-none, ...)
--debug-build disable optimization and emit DWARF
-g, --debug emit DWARF
--emit-obj emit an application object (XUOBJ)
--desktop package a native desktop application
--webview include the WebView host in a desktop build
--no-webview use the Draw-only desktop host
--www DIR embed resources in a desktop build
--xacp embed XACP startup and discovery
--xacp-port PORT enable XACP TCP on loopback (0 = stdio only)
--no-opt disable optimization
--release select a release build (default)
--ra=1 select the default register allocator
--offline resolve dependencies using local sources, vendor, and cache
--frozen use locked dependencies without writes or downloads
-v, --verbose print the selected target and chip features
Use "xu <command> --help" or "xu help <command>" for more information.
Getting Started · Modules Specification · VS Code Guide · Installation Guide
Source debugging (0.10.5)
xu debug builds a DWARF-enabled executable and launches the host LLDB/GDB; install a debugger first. Use --break for a source-line or function breakpoint, --eval for a debugger command, --batch for batch operation, or --binary to inspect an existing executable.
xu debug --help
xu debug --break main.xu:8 --run main.xu
xu debug --binary ./app --batch --eval "image lookup -n main"
シンボル化バックトレースと DWARF 複合型(0.15.0)
- シンボル化されたパニックバックトレース:実行時パニックが発生すると、バックトレースウォーカーがフレームポインタチェーンを辿り、埋め込みシンボルテーブル(
__xu_symtab)が存在する場合はリターンアドレスを関数名とバイトオフセットに解決して出力します。存在しない場合は__xu_startからの生のオフセットにフォールバックします。 - DWARF 複合型の出力:
-g/--debug/--debug-build(およびxu debug)でビルドすると、スカラー型や行番号テーブルに加えて、構造体(フィールド名とバイトオフセットを含む)、列挙型、固定長配列、スライス、型付きポインタ/参照(&T、$&T、*raw T)などの複合型に対する DWARF デバッグ情報が出力されます。