> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ubx compile

> Generate code from .xcl files without deploying.

`ubx compile` runs the full XCL pipeline (lex → parse → typecheck → IR → plugin Compile RPC) and writes the generated code artifact — but does not deploy. It's useful for previewing generated output, artifact caching in CI, and debugging.

## Usage

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
ubx compile [path] [flags]
```

## Flags

| Flag                 | Description                                                  |
| -------------------- | ------------------------------------------------------------ |
| `--all`              | Compile all stacks in the workspace (topology order)         |
| `--out <dir>`        | Write output to this directory instead of `.ubx/`            |
| `--plan`             | Write an `--out`-style plan JSON alongside the artifact      |
| `--target <binding>` | Limit compilation to specific resource bindings (repeatable) |

## Examples

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
ubx compile                        # compile current stack
ubx compile --all                  # compile all stacks
ubx compile --out ./artifacts      # write to custom directory
ubx compile --target networking.vpc  # compile with only specific targets
ubx compile --plan                 # write plan JSON alongside artifact
```

## Generated artifacts

For `pulumi` + `python` engine, `ubx compile` writes to `.ubx/`:

```
.ubx/
├── __main__.py        # Pulumi Python program
├── requirements.txt   # pulumi>=3.0.0,<4.0.0 + provider packages
└── Pulumi.yaml        # project metadata (stack name from dir name)
```

The stack name in `Pulumi.yaml` is derived from `filepath.Base(dir)`.

`requirements.txt` format:

```
pulumi>=3.0.0,<4.0.0
pulumi-aws>=1.0.0
pulumi-kubernetes>=1.0.0
```

For `terraform`/`opentofu` engine:

```
.ubx/
└── main.tf
```

## Workspace vs single-stack

* Without `--all`: single-stack path — invokes the plugin's `Compile` RPC
* With `--all`: workspace path — compiles all stacks in topological order; native engine stacks use in-process codegen

## Exit codes

| Code | Meaning                                         |
| ---- | ----------------------------------------------- |
| `0`  | Compilation succeeded                           |
| `1`  | Parse errors, typecheck errors, or plugin error |
