Skip to content

xlsynth-sys: support XLSYNTH_ARTIFACT_CONFIG#851

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

xlsynth-sys: support XLSYNTH_ARTIFACT_CONFIG#851
dank-openai merged 5 commits intomainfrom
dank/xls-toolchain-toml

Conversation

@dank-openai
Copy link
Contributor

@dank-openai dank-openai commented Feb 28, 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

@dank-openai dank-openai force-pushed the dank/xls-toolchain-toml branch 5 times, most recently from 824d867 to 4aee06f Compare March 1, 2026 01:26
Resolve relative artifact-config paths against the config file directory,
cover that contract in the nested cargo smoke test, and document that
XLS_DSO_PATH may be either a file path or a directory depending on how the
DSO was materialized.
Copy link
Contributor

@meheff meheff left a comment

Choose a reason for hiding this comment

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

Nice!

@meheff
Copy link
Contributor

meheff commented Mar 11, 2026

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ 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 dank-openai merged commit bc173bd into main Mar 13, 2026
23 of 24 checks passed
@dank-openai dank-openai deleted the dank/xls-toolchain-toml branch March 13, 2026 16:42
dank-openai added a commit to xlsynth/rules_xlsynth that referenced this pull request Mar 13, 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
- `xlsynth/rules_xlsynth`: [PR
#52](#52)
- `xlsynth/xlsynth-crate`: [PR
#851](xlsynth/xlsynth-crate#851)
- `xlsynth/topstitch`: [PR
#141](xlsynth/topstitch#141)
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