Current section

Files

Jump to
weld guides getting_started.md
Raw

guides/getting_started.md

# Getting Started

Install Weld in the workspace root project or a dedicated maintainer project
such as `tools/maintainer/mix.exs`. Consumers use ordinary Mix dependencies for
source projects, generated projections, `projection/*` branches, and Hex
packages.

## 1. Add The Maintainer Dependency

```elixir
def deps do
  [
    {:weld, "~> 0.19.0", only: [:dev, :test], runtime: false}
  ]
end
```

Resolve this Hex dependency after Weld 0.19.0 is published. To try a release
candidate, point a disposable maintainer Mix project at the candidate checkout
with a Weld path dependency and pass your manifest's absolute path to the tasks
below.

## 2. Add A Repo-Local Manifest

Store your manifest in one of Weld's auto-discovered locations (`build_support/weld.exs`, `build_support/weld_contract.exs`, or a single `packaging/weld/*.exs`).

For example, `packaging/weld/my_bundle.exs` in default package-projection mode:

```elixir
[
  workspace: [
    root: "../..",
    project_globs: ["core/*", "runtime/*"]
  ],
  dependencies: [
    external_lib: [
      requirement: "~> 1.2",
      opts: []
    ]
  ],
  artifacts: [
    my_bundle: [
      roots: ["runtime/local"],
      package: [
        name: "my_bundle",
        otp_app: :my_bundle,
        version: "0.1.0",
        docs: [
          logo: "assets/my_bundle.svg",
          source_url: "https://github.com/example/my_bundle",
          source_ref: "v0.1.0",
          extra_titles: %{"README.md" => "Overview"},
          groups_for_extras: [
            {"Start Here", ["README.md", "guides/architecture.md"]},
            {"Release", ["CHANGELOG.md", "LICENSE"]}
          ]
        ]
      ],
      output: [
        docs: ["README.md", "guides/architecture.md", "CHANGELOG.md", "LICENSE"],
        assets: ["assets/my_bundle.svg"]
      ],
      verify: [
        artifact_tests: ["packaging/weld/my_bundle/test"],
        hex_build: true,
        hex_publish: true
      ]
    ]
  ]
]
```

Key manifest concepts:

- `workspace.root` resolves relative to the manifest file (`"../.."` from `packaging/weld/my_bundle.exs`, or `".."` from `build_support/weld.exs`).
- **Choose the composition mode that matches your repo:**
  - `:package_projection` *(default)* stages the selected dependency closure under `components/` and synthesizes a root `mix.exs` (and a merged `Application` module when selected projects start OTP children).
  - `:monolith` merges `lib/`, `priv/`, migrations, configs, and declared `:test_paths` into a single flat Mix project. Declare any non-selected test helpers explicitly in `monolith_opts[:test_support_projects]`.
  - `:source_project` preserves the existing `mix.exs` of one selected project and its declared `source_project[:files]` inventory. Use `roots: ["."]` for the repository root or a discovered project ID for a nested package. See [Source-Project Artifacts](source_projects.md).
- The graph modes include every declared `output.docs` and `output.assets` entry in the projected project and its Hex `package.files` allowlist.
- Declare `dependencies` when a selected workspace project uses `:path`, `:git`, or `:github` for an external dependency that must be rewritten to a canonical Hex requirement (or canonical Git spec) in the projected package.
- Declare `external_projects` on an artifact when an otherwise discoverable workspace dependency should remain a separately installed package.

## 3. Initialize `.weld/` And Inspect The Graph

```bash
mix weld.setup
mix weld.inspect
mix weld.graph --format dot
```

`mix weld.setup` initializes `<checkout_root>/.weld/` and ensures `.weld/` is present in `.gitignore`. Commit any `.gitignore` change before preparing releases from a clean Git working tree.

Use `weld.inspect` and `weld.graph` to confirm project discovery, classifications, selected closures, and zero boundary violations before projecting.

## 4. Generate Projections

```bash
# Portable full projection under .weld/full/<artifact>/project/
mix weld.project

# Symlinked live view under .weld/live/<artifact>/
mix weld.project --live
```

For a manifest with multiple artifacts, pass `--artifact <name>` to each
artifact command. A nested maintainer project can pass the manifest path
explicitly, for example `mix weld.project ../../build_support/weld.exs --artifact my_bundle --live`.

Full projections contain regular files, `weld.provenance.json` (`kind: "full"`
and content-addressed `artifact_id`), and `projection.lock.json`. Live
projections use the same composition and link back to the checkout. Edits
inside linked source directories take effect at the next build. A live
monolith links individual files, so additions, removals, and remaps require
refresh. The generated Mix project prints the refresh command when its
layout inputs change.

## 5. Verify The Projected Artifact

```bash
mix weld.verify
```

**Package-projection and source-project modes** run:

- `mix deps.get`
- `mix deps.compile`
- `mix compile --warnings-as-errors --no-compile-deps`
- `mix test`
- `mix docs --warnings-as-errors --output doc`
- optional consumer smoke-app compilation when `verify.smoke.enabled` is `true`
- `mix hex.build` (when `verify.hex_build` is `true`)
- `mix hex.publish --dry-run --yes` (when both `hex_build` and `hex_publish` are `true`)

Package projections run artifact tests by default. Set
`verify: [component_tests: true]` to include declared component suites along
with any artifact test roots.

**Monolith mode** runs:

- per-package test baseline across each selected workspace project
- `mix deps.get`
- `mix compile --warnings-as-errors`
- `mix test` (asserting the merged test count is at least the baseline sum)
- `mix docs --warnings-as-errors --output doc`
- `mix hex.build` (when `verify.hex_build` is `true`)
- `mix hex.publish --dry-run --yes` (when both `hex_build` and `hex_publish` are `true`)

Set `verify: [hex_build: false]` for internal artifacts with non-Hex Git dependencies, or `verify: [hex_publish: false]` to verify tarball creation without running the dry-run publish check.

## 6. Prepare, Track, Publish, And Archive

From a clean committed Git tree:

```bash
mix release.prepare
mix release.status
mix release.track --identity <sha> --tag-release --push
mix release.publish --identity <sha> --tag <tag>
mix release.archive --identity <sha>
```

`mix release.prepare` writes an immutable, integrity-checked bundle to `.weld/releases/<artifact>/<identity>/` (with `project/`, rendered HTML/Markdown `docs/`, `release.json`, and optional tarball) and updates `.weld/releases/<artifact>/CURRENT`.

`mix release.track` syncs the prepared `project/` onto an orphan `projection/<package_name>` branch so Git consumers can pin projected snapshots without touching `main`. `mix release.archive` copies the verified bundle to `.weld/archive/<artifact>/<identity>/`.