Modules and dependencies
A directory-based project uses xu.xun in the root directory as its module manifest. In this file: module: declares the module's identity and namespace, version: defines its project version, and xu: declares the targeted Xu compiler version. External imports require an explicit alias and a corresponding root module under require:.
1. Declare & Install Dependencies (xu get / xu install)
For the API documented on this site, use the packages bundled with the selected SDK or the matching immutable source commit. A module version in xu.xun does not imply that a Git tag with that version exists.
Method A: Use the SDK bundle
With your project beside the extracted SDK, add this to xu.xun. Adjust the local path for your installation:
module: app
version: !ver 0.1.0
xu: !ver 0.16.0
require:
"github.com/xulang-org/packages": file:../xu-v0.16.0/packages
Method B: Fetch the matching source commit
Replace the local locator above with this SDK source snapshot:
require:
"github.com/xulang-org/packages": git:https://github.com/xulang-org/packages.git@96693e6cce8d51eba45e4f68dc12ce06f7a2336b
Then run from your project directory:
xu install
For modules with a verified published SemVer tag, xu get <module>@<version> adds or updates the dependency, installs sources, and updates xu.lock. Replace both placeholders with that module's actual identity and release tag. See official packages for SDK compatibility and native bridge preparation.
Importing Packages in Source Code with Explicit Aliases
Import sub-packages in your .xu source files using explicit namespace aliases:
@main
#fmt
mysql #github.com/xulang-org/packages/mysql
fn main() int {
_ := mysql.driver()
fmt.println("MySQL driver loaded successfully.")
<< 0
}
You declare the root repository github.com/xulang-org/packages under require:, then import concrete sub-packages in code (such as mysql, redis, postgres, s3). See the full package catalog in Official External Packages.
2. Version Selection & Alternate Locators
In addition to SemVer releases, you can pin to a reviewed immutable Git commit or use a relative path for local co-development:
# Option A: Pin to a reviewed Git commit
require:
"github.com/xulang-org/packages": git:https://github.com/xulang-org/packages.git@<commit>
# Option B: Local workspace co-development (app placed beside packages)
require:
"github.com/xulang-org/packages": file:../packages
Xu uses the MVS (Minimal Version Selection) algorithm, reading all reachable version manifests to select the highest minimum requirement for each module. MVS never queries latest or interprets floating version ranges. Modules with major version v2 or higher use a matching /vN path suffix. Explicit file, Git, and tar sources remain natively supported; conflicting sources result in explicit compiler errors.
3. Install, Lock, and Offline/Frozen Builds
For production CI/CD pipelines and enterprise deployments, Xu guarantees deterministic locking and reproducible offline builds:
# 1. Resolve and download dependencies during development
xu install
# 2. Check types and borrow rules offline (no downloads permitted)
xu check main.xu --offline
# 3. Completely frozen production release build (strictly pins existing lock)
xu build main.xu --frozen --output app
| Build Mode | Network & Compiler Behavior Specification |
|---|---|
| Default Mode | Allows downloading and establishing lock entries; existing content hash mismatches immediately fail. |
--offline |
Forbids network calls; uses only local sources, verified cache, or vendor/; may create lock entries locally. |
--frozen |
Implies offline mode. Requires an exact matching lock entry; strictly forbids cache or lock writes; local file: dependencies must be pre-installed as vendor/ snapshots. |
We recommend committing xu.lock to version control. Explicit sources use v2 locks; version graphs use v3 locks. xu install retains all reachable version snapshots in vendor/ for offline MVS graph replay. Frozen dependency mode does not freeze your application sources or build outputs.
4. Proxy Servers and Private Modules (XUPROXY / XUPRIVATE)
# Configure proxy mirror with direct fallback
XUPROXY='https://proxy.example.com,direct' xu install
# Configure enterprise private module patterns (bypassing public proxy and sumdb)
XUPRIVATE='example.com/private/*' xu install
XUPROXY accepts HTTP(S), absolute file:// URLs, direct, and off; default is direct. A comma falls back only on 404/410; a vertical bar allows fallback on any request errors. Identity or integrity mismatches always fail immediately. Direct version discovery natively supports GitHub repositories; other code hosts require an explicit source or a configured Xu proxy.
XUPRIVATE is a comma-separated list of module-prefix globs; XUNOPROXY defaults to it and controls proxy bypass. Xu does not assume a public proxy is running; Go module proxy manifests cannot be parsed as Xu manifests.
5. Checksum Verification & Append-Only Logs (XUSUMDB)
Since 0.8.4, Xu includes a cryptographic transparency checksum verification system. XUSUMDB accepts a trusted Ed25519 verifier key and optional service URL. For SemVer modules, the client verifies the signed tree head, module digest, inclusion proof, and append consistency before accepting dependencies. When unset or set to off, trust-on-first-use remains in effect. XUNOSUMDB controls checksum bypass independently and defaults to XUPRIVATE.
6. Native C/C++ Modules & .xulib Support
Beyond pure source packages, Xu supports native C/C++ libraries declared via the native: section in xu.xun. The compiler supports both standard generic .a archives and portable .xulib multi-target slice containers. For full specifications, see Native Modules & .xulib Specification.
7. Migrating from Older Versions
Legacy dotted package paths have been modernized to standard slash (/) paths; dots are preserved in domain names, version numbers, and struct field/method access. When module identities or old lock formats change, re-run xu install after review to refresh the lockfile. Never delete xu.lock solely to suppress a checksum mismatch.
Related Reading: Official External Packages Guide · Native Modules & .xulib Specification · CLI Command Reference