Skip to content

migrate workspace XLS selection into a module extension#52

Merged
dank-openai merged 13 commits intomainfrom
dank/xls-toolchain-toml
Mar 13, 2026
Merged

migrate workspace XLS selection into a module extension#52
dank-openai merged 13 commits intomainfrom
dank/xls-toolchain-toml

Conversation

@dank-openai
Copy link
Collaborator

@dank-openai dank-openai commented Feb 28, 2026

Problem Solved

Public XLS artifact selection moves out of .bazelrc artifact-path flags and into a Bzlmod module extension. A workspace now chooses one or more named XLS bundles in MODULE.bazel, registers one default bundle, and consumes a narrower exported bundle contract instead of wiring tool, stdlib, driver, and runtime paths separately.

Review Focus

The module extension API, exported bundle labels, and whether artifact_source forms a stable downstream contract.

Mental Model

Each xls.toolchain(...) call materializes a named bundle repo. use_repo(...) exposes that repo, register_toolchains("@<name>//:all") makes one bundle the workspace default, and most DSLX rules use that default through normal toolchain resolution. Rules that must stay on another XLS stack can opt into a different bundle explicitly with xls_bundle = "@<name>//:bundle".

The existing TOML-plus-env_helpers execution path stays in place. What changed is where artifact selection lives: the workspace root chooses bundles, while rule actions keep consuming declared TOML inputs.

Non-goals

  • This does not remove the existing behavior settings such as warning knobs, dslx_path, type_inference_v2, or use_system_verilog.
  • This does not require every rule callsite to spell its bundle explicitly.
  • This does not make downstream consumers reach into generic bundle internals by hand.

Tradeoffs

  • More logic now lives in the module extension and bundle materialization path.
  • The public API is stricter: artifact selection is bundle-only, not a mix of bundle selection and .bazelrc artifact flags.
  • Download-backed bundle resolution requires rustup on the host performing module resolution.

Architecture

  • Add the xls module extension plus repository rule that materializes bundle repos from auto, eda_tools_only, download_only, or local_paths.
  • Export a stable repo surface for downstream consumers, including :bundle, :libxls_link, and the xlsynth_sys_* targets used by Bazel plus xlsynth-sys integration.
  • Keep per-action TOML generation and env_helpers as the runner boundary for Bazel actions.
  • Normalize the staged libxls runtime identity so native consumers can link and run against bundle-provided runtime files without wrapper staging.
  • Add explicit xls_bundle escape hatches on the supported leaf rules that truly need a non-default bundle.

Observability

  • Invalid artifact_source combinations fail during bundle materialization instead of surfacing later as action-environment drift.
  • Bundle metadata records the normalized libxls name and whether the selected driver supports enum-case naming.
  • The checked-in examples show both the normal workspace-default flow and the local_paths local-development flow.

Related PRs in the other repos

@dank-openai dank-openai force-pushed the dank/xls-toolchain-toml branch from c54d481 to 63aa861 Compare March 10, 2026 22:08
@dank-openai dank-openai requested review from cdleary and meheff March 11, 2026 00:14
Thread artifact-config TOML through Bazel actions, tighten env-helper flag handling, and gate enum-case naming for older drivers.
Add the bundle repository/materializer, wire workspace examples into presubmit, and fix runfile and staging fallout so the new bundle contract works end to end.
Make MODULE.bazel the only artifact-selection surface now that workspace bundle plumbing is in place.
Bootstrap download-backed driver installs, expose the runtime names consumers need, and extend explicit bundle selection across direct DSLX, ECO, and IR analysis rules.
Reuse validated download caches, package the xlsynth-sys and native runtime surfaces, normalize staged libxls identity, and hand installed-layout ownership to consumer-owned root prefixes.
@dank-openai dank-openai changed the title rules_xlsynth: migrate workspace XLS selection into a module extension migrate workspace XLS selection into a module extension Mar 11, 2026
@meheff
Copy link
Contributor

meheff commented Mar 11, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a139556ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

dank-openai added a commit to xlsynth/xlsynth-crate that referenced this pull request Mar 13, 2026
## Problem Solved

`xlsynth-sys` needed a Bazel-friendly way to receive the XLS DSO and
DSLX stdlib as one declared input instead of two separate environment
variables. It also needed a mode where `build.rs` records those artifact
paths without emitting its own native link directives, so an external
build system can own the final link step.

## Review Focus

`XLSYNTH_ARTIFACT_CONFIG` precedence, declared-link mode, and
compatibility with the legacy `XLS_DSO_PATH` + `DSLX_STDLIB_PATH`
override.

## Mental Model

`XLSYNTH_ARTIFACT_CONFIG` is now the preferred declared-input contract:
a TOML file with `dso_path` and `dslx_stdlib_path`. `build.rs` resolves
that config first, writes the selected paths into generated Rust
constants, and then either emits native link directives or only
publishes the DSO path depending on `XLSYNTH_SYS_LINK_MODE`.

If that config is absent, `build.rs` deliberately falls back to the
older paired `XLS_DSO_PATH` plus `DSLX_STDLIB_PATH` override, the local
workspace override, and the download fallback so existing users who
cannot or will not migrate immediately still keep working.

## Non-goals

- This does not change the public `xlsynth` Rust API.
- This does not remove the legacy paired environment-variable override.
- This does not make Cargo-only consumers adopt Bazel-specific wiring.

## Tradeoffs

- `build.rs` now owns more validation and precedence logic.
- `declared` link mode is stricter: it preserves artifact discovery but
leaves final native link ownership to the orchestrator.

## Architecture

- Add `XLSYNTH_ARTIFACT_CONFIG` parsing, precedence, and relative-path
resolution from an absolute config path.
- Keep generating `artifact_paths.rs` so Rust code still sees one
resolved artifact choice.
- Add `XLSYNTH_SYS_LINK_MODE={native,declared}` so managed and explicit
artifact paths can skip native `-l...` emission when the caller already
declares the link inputs.
- Continue emitting `cargo:DSO_PATH` so dependent build scripts can
consume the resolved runtime location through Cargo's normal
`DEP_XLSYNTH_DSO_PATH` mechanism.
- Preserve the existing paired env override and download-backed fallback
for non-Bazel callers.

## Observability

- `build.rs` now reports which artifact source won: config file, paired
env override, local workspace, or download.
- Bad config shapes fail with targeted messages, including
relative-config-path rejection and invalid shared-library-path
rejection.
- `XLSYNTH_SYS_LINK_MODE=declared` is explicit in the build output when
native link directives are intentionally skipped.

# Related PRs in the other repos
- `xlsynth/rules_xlsynth`: [PR
#52](xlsynth/rules_xlsynth#52)
- `xlsynth/xlsynth-crate`: [PR
#851](#851)
- `xlsynth/topstitch`: [PR
#141](xlsynth/topstitch#141)
@dank-openai dank-openai merged commit 0bab693 into main Mar 13, 2026
3 checks passed
@dank-openai dank-openai deleted the dank/xls-toolchain-toml branch March 13, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants