XU XUv0.16.0

Get started

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.

End-to-End 4-Step Quickstart Pipeline
A standardized engineering workflow from installation and project initialization to coding, testing, and production builds
1
Install the SDK & verify your compiler
Use Quick Install or download the compiler, then run xu --version to verify it. You can also try the WebAssembly Playground in your browser.
2
Initialize the project manifest & layout
Create and enter the project directory, then run xu init myapp to generate xu.xun and main.xu there
3
Write entrypoint & business logic
Start with @main on line 1, import stdlib #fmt or external drivers, and write your functions
4
Run, test & optimize for release
xu run . for instant execution · xu test test.example.xu for test suites · xu build . for release binaries

1. Installation & Environment Setup

Quick Install via Terminal
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: