Skip to content

feat: declare target platforms in dbc.toml - #608

Merged
eitsupi merged 4 commits into
mainfrom
feat/declared-platforms
Nov 24, 2026
Merged

eitsupi merged 4 commits into
mainfrom
feat/declared-platforms

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Close #592, and the project-side answer to the first review point of #584: instead of falling back to an older version that has a build for the machine running the command, a project can declare the platforms its drivers must support.

platforms = ["linux_amd64", "macos_arm64", "macos_amd64"]
  • Selection. dbc add, dbc lock and dbc sync choose the newest allowed version with a build for every listed platform, on every machine. A missing build does not trigger registry fallback. If the selected version lists more than one package for a listed platform that needs an artifact, dbc reports an error instead of selecting an older version. The list must contain at least one valid, distinct platform (an alias such as darwin_arm64 counts as a duplicate), and the current platform is not added implicitly. dbc sync requires the current platform to be listed.
  • Lockfile. dbc.lock records the declaration and an artifact for each listed platform. A listed platform is handled like the current one: for a new artifact, dbc records the published hash when available, and otherwise downloads the archive, checks it with the installation's extraction safeguards, verifies its signature unless --no-verify is set, and records the measured hash. Other platforms are still recorded from published hashes.
  • Changes. When the declaration is added or changed, dbc fills missing listed platforms from the locked version and registry. If all are already recorded, it skips the index. Extending an entry keeps every recorded artifact, even if the registry no longer lists it. This follows normal lock replay, much like Cargo keeps using locked crates after a yank. If the locked version lacks a build needed to extend the entry, dbc resolves the driver again and warns if its version or registry changes. Completion fails if the locked registry uses a query string or no longer lists the driver. Removing the declaration returns to normal lock replay.
  • Warnings. dbc lock warns once when the current platform is not listed, because dbc sync will refuse it. It also warns when a v1 pin is dropped because its version lacks a listed platform, even if there was no checksum.

Without platforms, the implicit platform means two different things, on purpose:

Treating the undeclared case as "every platform" would download every platform's archive to measure the hashes a registry does not publish; treating it as "the current platform" for selection would make the locked version depend on the machine. dbc add now also accepts a version without a build for the current platform.

dbc install, dbc search -v, dbc info and dbc list ignore platforms: install picks the newest version with a build for the current platform (#584), search -v lists the versions available for it, info shows the latest version's packages for every platform, and list shows installed drivers.

@eitsupi
eitsupi added this pull request to stack #609 November 23, 2026 23:27
@eitsupi
eitsupi requested review from amoeba and zeroshade November 23, 2026 23:30
@eitsupi
eitsupi marked this pull request as ready for review November 23, 2026 23:31
@eitsupi eitsupi changed the title feat: declare the platforms that drivers are resolved for feat: declare target platforms in dbc.toml Nov 23, 2026

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice design overall: matching on canonical targets with alias duplicates rejected, older-version fallback only as an explicit opt-in via platforms (so #584's default is unchanged), a missing build as a plain error rather than ErrPackageMiss, platforms in the lock file kept canonical, unique and enforced per driver, and measureDeclared checking extraction and signature before recording a measured hash. go vet and go test ./cmd/dbc/ ./ pass on the head.

Requesting changes for the first inline comment: relock re-resolves silently in cases where fromLock refuses, so changing platforms can move a driver to another version or registry without any message. The other comments are non-blocking.

Before merge: the base is feat/lock-without-host-build, so this needs retargeting once #607 lands, and it conflicts with #601's new ResolvePackage(drivers, indexErr, …) signature in both add.go and syncPlanner.resolve.

Comment thread cmd/dbc/sync_plan.go Outdated
}
if bound.HasQuery {
// Artifacts cannot be added from it (see fromLock).
return plannedDriver{}, false, nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking: when the locked registry URL has a query string, this returns kept=false and the driver is resolved again from the merged index, which can change its version and registry just because platforms changed. Only the signer check (oldSigner) guards it. fromLock refuses the same situation with "cannot be completed; delete the driver's entry from the lock file…". Could relock return that error too (or at least emit a warning that the entry was re-resolved)?

Comment thread cmd/dbc/sync_plan.go Outdated
d.Source.URL, name, redactRegistryError(err, p.registries, bound.BaseURL))
}
drv, err := findDriver(name, drivers)
if err != nil || !coversPlatforms(drv, v, p.platforms) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking (same issue): a findDriver error, meaning the driver is no longer in its locked registry, is swallowed here and the driver silently re-resolved elsewhere. !coversPlatforms falling through to re-resolution is the intended behaviour, but a missing driver should be an error, as it is in fromLock.

Comment thread cmd/dbc/sync_plan.go
if err != nil {
return plannedDriver{}, false, fmt.Errorf("driver %s: %w", name, redactRegistryError(err, p.registries, bound.BaseURL))
}
d.Artifacts = artifacts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: this replaces all artifacts with the declared ones plus whatever the current index publishes. Hashes for platforms that are not listed, measured earlier because the registry publishes none, are lost, and published ones are silently replaced from the current index. The impact is limited while platforms is declared, since sync refuses unlisted hosts, but it shows up once the declaration is removed. Keeping existing artifacts for unlisted targets would avoid that.

Comment thread cmd/dbc/sync.go Outdated
}
// The copy shares the artifacts of the entry, so the measured hash is
// recorded there. The library proof only applies to the current target.
other := plannedDriver{Name: pd.Name, Entry: pd.Entry, Package: pkg, ArchiveSize: pd.Entry.Artifacts[i].Size, Signer: pd.Signer}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: the measured hash only reaches pd.Entry because checkDownloadedArchive writes through &pd.Entry.Artifacts[i] into the backing array the copy shares. Any future append/clone there would silently drop it. Writing the digest back to pd.Entry.Artifacts[i] explicitly after the download would make this robust.

Comment thread cmd/dbc/platforms.go Outdated

// eligibleVersion reports whether v may be selected for spec without a pin,
// like Driver.GetLatestVersionAnyPlatform does.
func eligibleVersion(spec driverSpec, v *semver.Version) bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: this repeats the eligibility rules of Driver.GetLatestVersionAnyPlatform (constraint decides prerelease eligibility, otherwise prerelease = 'allow'). A shared helper would keep them from drifting apart.

Comment thread cmd/dbc/platforms.go
// platformPackage returns the one package of version v for target t. A
// missing package and several packages for the same target (aliases or
// duplicates) are errors.
func platformPackage(d dbc.Driver, v *semver.Version, t resolution.Target) (dbc.PackageInfo, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: coversPlatforms counts a version with two packages for the same target as covered, so newestCoveringVersion selects it and this then hard-errors without trying an older version that would work. Erroring is defensible for a required platform, but the docs or the message could say so.

Comment thread cmd/dbc/sync_plan.go Outdated
if hadLock && pd.Entry.Signer != oldSigner {
return nil, nil, signerChangedError(name, oldSigner)
}
if proof != "" && pd.Package.Version.String() != pin.String() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: a dropped v1 pin is reported only when a checksum was recorded. Without one, the locked version changes with no message. A warning whenever the pin is dropped for not covering platforms would make that visible.

@eitsupi

eitsupi commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

I rebased onto the updated #607 branch and addressed the review in d2561d6 and 816ba91.

  • relock. As in fromLock, completing an entry fails if the locked registry URL has a query string or the registry no longer lists the driver. If the locked version lacks a build for an unrecorded required platform, dbc resolves it again and warns if the version or registry changes.
  • Kept artifacts. When extending the same version from the same registry, relock keeps every recorded artifact and checks coverage only for declared platforms missing from the entry. A recorded artifact still counts even if the registry no longer lists it, consistent with normal lock replay. This goes a bit beyond your comment; the PR description explains why.
  • Measured hash. measureDeclared writes the verified digest back explicitly. The temporary plan has its own package and carries no lock entry.
  • Eligibility. eligiblePackages and newestCoveringVersion now share resolution.VersionEligible.
  • Duplicate packages. The selected version still fails if a required build is ambiguous, so broken metadata does not silently select an older version. The error and docs now explain that behavior.
  • Dropped v1 pin. dbc warns when it drops a pin for missing platform coverage, with or without a checksum.

dbc lock also warns once if the current platform is not in platforms, since dbc sync refuses to run there. I'll retarget after #607 lands and handle the #601 conflict when that PR lands.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, d2561d6 and 816ba91 address everything: relock now fails like fromLock for a registry URL with a query string or a driver the registry no longer lists, and warns when re-resolution changes the version or registry. It keeps recorded artifacts and checks coverage only for missing declared platforms. measureDeclared writes the measured digest back explicitly. Eligibility is shared through resolution.VersionEligible. Ambiguous builds are documented, and a dropped v1 pin is always reported. The single warning for an undeclared platform in dbc lock is a nice touch. go vet ./... and the cmd/dbc, root and internal/resolution tests pass on the head.

Remaining before merge, as you noted: retarget to main after #607 lands, and resolve the #601 ResolvePackage conflict.

Base automatically changed from feat/lock-without-host-build to main November 24, 2026 23:16
A top-level `platforms` list in dbc.toml selects, for dbc add, dbc lock
and dbc sync, the newest allowed version that has a build for every
listed platform. A missing build is not a package miss, so it never
makes another registry serve the driver.

A declared platform is handled like the current one: its archive is
recorded with the hash the registry publishes, or downloaded, checked
(safe extraction and, unless --no-verify is set, the signature) and
measured. As before, other platforms with a published hash are recorded
too. dbc sync fails on a platform that is not declared.

dbc.lock records the declaration, and every driver has an artifact for
each declared platform. A new or changed declaration resolves the
drivers again, keeping the locked source, version and archive hashes
where the version has a build for every declared platform; removing it
keeps the lock entries.

Without platforms, dbc add no longer needs a build of the selected
version for the current platform either.
An entry that already records every declared platform is replayed as it
is, without fetching any index, so a changed declaration cannot move a
driver to another registry or change its hashes just because its
registry no longer lists the locked version. An entry that is extended
keeps the locked archive size of the current platform for the download
check, as a replayed entry does.

The lock reference now describes the cases without and with declared
platforms separately.
- relock keeps every recorded artifact, declared or not, and checks only
  the declared platforms the entry does not record yet.
- A locked registry with a query string or without the driver is an
  error, as in fromLock, instead of a silent re-resolution.
- Warn when re-resolution or a dropped v1 pin selects another version or
  registry, and once when dbc lock runs on an undeclared platform.
- Write the measured hash of a declared platform back explicitly.
- Share version eligibility through internal/resolution.VersionEligible.
- Name an ambiguous platform build in the error.
eitsupi added a commit that referenced this pull request Nov 24, 2026
Part of #592. As noted in the review of #575, `dbc lock` required a
build for the current platform, so a Linux CI runner could not lock a
macOS-only driver.

If the selected version has no build for the current platform, `dbc
lock` records builds with published archive hashes. It downloads no
archives for other platforms and fails if it cannot record any. If an
existing entry lacks an artifact for the current platform and the locked
version has no build for it, `dbc lock` keeps the entry.

Version and registry selection remain independent of the current
platform (#584). If the selected version lacks a build for that
platform, `dbc sync` fails without switching versions or registries.
Upgrading a v1 entry also fails if its library checksum was recorded for
the current platform and there is no build to check it against.

#608 adds declared platforms to `dbc.toml`.
@eitsupi
eitsupi force-pushed the feat/declared-platforms branch from 816ba91 to 9338096 Compare November 24, 2026 23:16
@eitsupi
eitsupi merged commit 728e139 into main Nov 24, 2026
31 checks passed
@eitsupi
eitsupi deleted the feat/declared-platforms branch November 24, 2026 23:26

This branch was previously deployed

1 inactive deployment
snapshot — 9338096c Deployed Nov 24, 2026 by eitsupi via snapshot #1352
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.

proposal: make project locking host-independent and clarify install/lock/sync resolution

2 participants