Get started
- Build a freestanding kernel and explore hardware interfaces in the operating system development guide.
- Run a model on the development CPU engine and inspect its tensor optimizations in the AI development guide.
Xu is a modern, high-performance systems programming language without runtime garbage collection (GC-free). It combines a thin, intuitive syntax, deterministic compile-time ownership and borrow checking, and fast static AOT native compilation. Xu source files use standard UTF-8 encoding with the .xu extension.
1. Installation & Environment Setup
curl -fsSL https://xulang.org/install.sh | bash -s -- --online --version 0.16.0 --yes
& ([scriptblock]::Create((irm https://xulang.org/install.ps1))) -Online -Version "0.16.0"
You can also download the compiler and choose a native installer or SDK archive for your platform. See the Installation Guide for setup and environment variables.
After installation, open a new terminal and run these commands to verify the toolchain:
# Verify compiler version and target build metadata
xu --version
# View categorized subcommands and formatted help manual
xu --help
Zero-Install Web Trial: If you prefer to explore Xu before installing locally, try the WebAssembly Interactive Playground to write, compile, and run Xu programs right in your browser.
2. Create Your First Project (xu init)
Xu organizes projects using directories as module boundaries. Create and enter a directory, then use xu init to initialize the module there. The command writes xu.xun and main.xu in the current directory; it does not create a subdirectory:
# Create a directory, then initialize the module in the current directory
mkdir myapp && cd myapp
xu init myapp
The standard project directory layout created by initialization:
| File / Directory | Type | Responsibility & Role |
|---|---|---|
xu.xun |
Project Manifest | Declares module identity, project version, minimum Xu compiler version, and external dependencies under require: |
main.xu |
Executable Entrypoint | Primary program source code, starting with @main on line 1 and containing the fn main() function |
xu.lock |
Deterministic Lockfile | Automatically generated after running xu get or xu install; pins the exact dependency graph and SHA-256 digests |
vendor/ |
Local Dependency Snapshot | Local source snapshot cache of external packages, enabling 100% offline reproducible builds (--offline / --frozen) |
3. Writing Code & Quick Tour
Open main.xu in your project and write a greeting program with basic error handling:
@main
#fmt
#errors
fn calculate_ratio(a int, b int) int {
if b == 0 {
// Use >> to throw structured errors
>> errors.new("division by zero")
}
// Use << to return computed results
<< a / b
}
fn main() int {
fmt.println("Hello, Xu World!")
// Call functions that may error, using >>> (err) to catch and handle
val := calculate_ratio(10, 2) >>> (err) {
fmt.println("Error:", err.msg())
<< 1
}
fmt.println("Result:", val)
<< 0
}
4. Statement Symbols You Will Recognize
Xu replaces boilerplate keywords with concise, expressive statement symbols:
| Symbol / Syntax | Category | Semantics & Design |
|---|---|---|
<< / << expr |
Control Flow | Return statement. Returns void when bare, or returns the operand value. |
>> expr |
Error Handling | Throws an errors.Error structured error object. |
>>> (err) { ... } |
Error Recovery | Trailing error handler block (Catch) that executes when an expression yields an error. |
<<< expr |
Process Control | Immediate process termination (Exit), returning an integer status code to the OS. |
<- |
Loop Control | Breaks out of the enclosing loop (statement start, no operand). |
-> |
Loop Control | Continues to the next loop iteration. |
$name := val |
Ownership Binding | Declares a mutable variable (variable bindings are immutable by default). |
xu f(args) |
Lightweight Concurrency | Spawns a lightweight coroutine executing f, scheduled by the zero-overhead runtime. |
chan T |
Concurrency Channel | Typed communication channel (e.g. chan int{cap: N}), paired with ch <- val to send and val := <-ch to receive. |
@main |
Package Identity | Marks the file as an executable entrypoint on line 1, generating the top-level main symbol. |
#pkg / alias #pkg |
Module Imports | Prefix with # for official standard libraries; external packages use alias #full/module/path. |
5. Modules & Packages (xu get / xu install)
For database drivers and service clients, declare the matching SDK source snapshot under require: in xu.xun:
module: myapp
version: !ver 0.1.0
xu: !ver 0.16.0
require:
"github.com/xulang-org/packages": git:https://github.com/xulang-org/packages.git@96693e6cce8d51eba45e4f68dc12ce06f7a2336b
Install the declared sources, or use the SDK bundle as a local dependency:
xu install
Import specific sub-packages directly in your source code using explicit aliases (such as mysql, redis, s3):
@main
#fmt
mysql #github.com/xulang-org/packages/mysql
fn main() int {
_ := mysql.driver()
fmt.println("MySQL driver initialized.")
<< 0
}
6. Common Daily CLI Workflows
Xu provides a comprehensive, modern command-line toolchain for every stage of development:
| Command | Workflow Stage | Description |
|---|---|---|
xu run . |
Development | Analyzes dependencies, quickly compiles, and executes in memory for rapid iteration. |
xu check . |
Diagnostics | Performs syntax, borrow-check, and type analysis without binary emission for millisecond feedback. |
xu test test.example.xu |
Quality Assurance | Recursively discovers and runs all test_* unit tests and benchmark assertions in parallel. |
xu fmt . |
Code Style | Automatically formats all .xu sources following official style conventions. |
xu build . -o bin/app |
Release Build | Enables full machine code optimizations and produces a standalone native binary. |
xu lsp |
Editor Integration | Launches the self-hosted Language Server daemon to power VS Code, Cursor, and other IDEs. |
7. Next Steps & Learning Paths
Once you are comfortable with the basics, explore the following topics:
- Step-by-step tutorials: Follow Tutorials 01–16 to master data types, ownership, borrow checking, and coroutine channels.
- Set up your editor: See the VS Code / Cursor Integration Guide to enable autocompletion, go-to-definition (F12), and format on save.
- Explore external drivers: Browse Official External Packages for 29 service integrations, import examples, and each package's protocol and platform limits.
- Native C/C++ interop: Check the Native Modules & .xulib Specification to link standard
.aarchives or portable slices. - XACP control channel: Read the CLI reference and the
#xacpAPI.xu build --xacpembeds discovery; importing#xacpalone does not open stdio or loopback TCP. The API is included in the matching published SDK; native control sessions and UI runtime acceptance remain unverified. - Formal language rules: Review the Language Specification and the 102 Benchmark Groups / 121 Measured Variants.