Weld logo

Weld

GitHub MIT License

Weld is a deterministic projection and release-preparation tool for Elixir repositories.

Multi-project Elixir workspaces often split code across internal Mix projects for fast isolated testing, boundary enforcement, or optional extensions, while downstream consumers want a single ordinary Mix dependency or Hex package. Weld bridges that gap without turning generated output into a second hand-maintained source tree: it reads a repo-local manifest, resolves the workspace dependency graph, projects a standalone Mix project under .weld/, verifies that generated project with standard Mix commands, and prepares content-addressed release bundles and optional Git projection snapshots.

When To Use Weld

Use Weld when maintainers want to:

Consumers of a root Mix project, a generated projection, a projection/<package_name> branch, or a published Hex package use ordinary mix commands (path:, git:/github:, or Hex) and never need to install Weld.

Relationship To Ordinary Mix Workflows

Projection Modes And Lifecycle

Weld supports three artifact composition modes declared per artifact in the manifest:

Mode What the artifact builds
:package_projection (default) Composes a selected Mix dependency closure under components/ and generates one Mix project.
:monolith Merges selected sources, assets, migrations, configuration, and tests into a flat Mix project.
:source_project Preserves the existing Mix project at one workspace root or subdirectory, including its own package metadata and compiler inputs.

Every mode supports two projection kinds:

Installation For Maintainers

These examples target Weld 0.16.0. Resolve the Hex dependency once that version is published. Add it to the workspace mix.exs or to a dedicated maintainer project such as tools/maintainer/mix.exs.

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

Initialize the repository's .weld/ directory and .gitignore rule before running clean-tree release preparation:

mix weld.setup

Core Commands

When [manifest_path] is omitted, Weld auto-discovers build_support/weld.exs, then build_support/weld_contract.exs, then a single packaging/weld/*.exs:

mix weld.setup
mix weld.inspect
mix weld.graph --format dot
mix weld.query deps runtime/local
mix weld.project
mix weld.project --live
mix weld.verify
mix weld.agents.verify
mix release.prepare
mix release.track
mix release.archive
mix weld.affected --task verify.all --base main --head HEAD

Pass an explicit manifest path (and --artifact <name> when a manifest defines multiple artifacts) when running from a nested maintainer project or a repo with multiple manifests.

Repository-Root .weld/ Layout

All Weld-managed state lives under <checkout_root>/.weld/, serialized by an exclusive checkout lock (.weld/.lock) and guarded by ownership markers (.owner):

.weld/
  .owner                              # ownership marker ("weld-output/v1")
  .lock/owner                         # active writer PID and node while mutating
  live/<artifact>/                    # symlinked live view
  full/<artifact>/project/            # standalone full Mix project + provenance/lock
  cache/<projection_id>/<toolchain>/  # warm Mix deps/ and build/ for verification
  releases/<artifact>/
    CURRENT                           # pointer to the latest verified <identity>
    <identity>/                       # immutable release.json, project/, docs/, *.tar
  archive/<artifact>/<identity>/      # archived post-release bundle copy
  staging/                            # atomic staging directories during mutation
  smoke/                              # temporary consumer smoke-test projects
  worktrees/                          # temporary Git worktrees during release.track

Weld rejects symlinks along managed output roots, refuses to overwrite unmanaged directories, and preserves any legacy dist/ directories untouched for manual migration.

Compose Two Artifacts From One Workspace

Suppose core/engine owns the reusable engine and apps/console declares {:engine, path: "../../core/engine"}. Add build_support/weld.exs in the workspace root:

[
  workspace: [root: "..", project_globs: ["core/*", "apps/*"]],
  artifacts: [
    engine_bundle: [
      roots: ["core/engine"],
      package: [name: "engine_bundle", otp_app: :engine_bundle, version: "0.1.0"]
    ],
    console_bundle: [
      roots: ["apps/console"],
      package: [name: "console_bundle", otp_app: :console_bundle, version: "0.1.0"]
    ]
  ]
]

Weld follows the console's declared dependency and includes both projects in console_bundle. engine_bundle includes only the engine. Use each artifact as an alternative package, since both contain the engine's modules. If console should depend on a separately released engine, declare an artifact-local boundary as described in the manifest reference.

mix weld.setup build_support/weld.exs
mix weld.project build_support/weld.exs --artifact console_bundle --live
mix weld.project build_support/weld.exs --artifact console_bundle
mix weld.project build_support/weld.exs --artifact engine_bundle

In a sibling consumer, declare {:console_bundle, path: "../workspace/.weld/live/console_bundle"} and run mix deps.get and mix compile. Use the corresponding full project for a portable copy and a prepared project for an immutable input. The getting started guide covers artifact verification and release preparation.

Verification And Release Lifecycle

mix weld.verify regenerates .weld/full/<artifact>/project/ and runs a mode-specific verification gate using isolated build/dependency caches under .weld/cache/:

Set verify: [hex_build: false] for internal artifacts that intentionally use non-Hex Git dependencies, or verify: [hex_publish: false] to build a Hex tarball without running hex.publish --dry-run.

The standard release flow separates deterministic bundle preparation from credentialed publication:

  1. Run the source workspace's own test and quality gates on a clean Git working tree.
  2. Run mix release.prepare to verify and write .weld/releases/<artifact>/<identity>/.
  3. Optionally run mix release.track to update the orphan projection/<package_name> branch (and optionally --tag / --push).
  4. When publishing to Hex, run mix hex.publish from the prepared bundle's project/ directory.
  5. Run mix release.archive to preserve the verified bundle under .weld/archive/<artifact>/<identity>/.

Prepared project/ trees and tracked Git projections retain weld.provenance.json and projection.lock.json for auditability; Hex tarballs omit projection.lock.json.

Guides

License

This project is licensed under the MIT License. See LICENSE for details.