Skip to content

refactor: replace custom runtime with Go stdlib runtime/debug#2420

Merged
paganotoni merged 1 commit intomainfrom
refactor/runtime-to-stdlib
Mar 20, 2026
Merged

refactor: replace custom runtime with Go stdlib runtime/debug#2420
paganotoni merged 1 commit intomainfrom
refactor/runtime-to-stdlib

Conversation

@paganotoni
Copy link
Member

Summary

This PR modernizes the buffalo runtime package by replacing the custom build-time ldflags injection with Go's standard library runtime/debug package.

Changes

Breaking Changes

  • runtime.Version now defaults to 'dev' instead of hardcoded 'v1.1.0'
  • BuildInfo.Time now uses VCS commit time (vcs.time) instead of build time
  • The entire runtime package is now deprecated and will be removed in v2

Implementation Details

  • Removed underscore import of runtime package from buffalo.go
  • runtime.Build() now internally uses debug.ReadBuildInfo()
  • All public APIs marked as deprecated with migration instructions
  • Deleted runtime/version.go (content merged into build.go)
  • Added CHANGELOG.md with comprehensive migration guide

Backward Compatibility

✅ The runtime package API remains fully backward compatible:

  • runtime.Build() works the same way
  • runtime.Version is still accessible
  • runtime.SetBuild() still exists (though now a no-op after first Build() call)

Migration Path

Users can modernize their code to use runtime/debug directly:

// Old way (still works, but deprecated)
import "github.com/gobuffalo/buffalo/runtime"
info := runtime.Build()

// New recommended way
import "runtime/debug"
info, ok := debug.ReadBuildInfo()
if ok {
    version := info.Main.Version
    // Access VCS info via info.Settings
    for _, s := range info.Settings {
        switch s.Key {
        case "vcs.revision":
            // commit hash
        case "vcs.time":
            // commit timestamp
        case "vcs.modified":
            // "true" if working tree had uncommitted changes
        }
    }
}

Testing

All existing tests pass:

  • go build ./... - successful
  • go test ./... -short - all packages pass

Requirements

  • Go 1.18+ (for VCS information embedding)
  • Binary must be built with module support

Related

This change eliminates the vendoring workaround that required the blank import in buffalo.go, modernizing the codebase to use standard Go practices.

@paganotoni paganotoni requested a review from a team as a code owner March 20, 2026 16:25
Replace the custom runtime package implementation that relied on
build-time ldflags injection with Go's standard library runtime/debug
package. This change:

- Removes the underscore import of runtime package from buffalo.go
- Updates runtime.Build() to use debug.ReadBuildInfo() internally
- Maintains backward compatibility with existing API
- Deprecates all runtime package functions with migration instructions
- Removes runtime/version.go (merged into build.go)

This modernization leverages Go 1.18+'s built-in VCS information
embedding and eliminates the vendoring workaround that required
the blank import.

Breaking changes:
- runtime.Version defaults to 'dev' instead of 'v1.1.0'
- BuildInfo.Time now uses vcs.time (commit time) instead of build time
- The runtime package is now deprecated and will be removed in v2
@paganotoni paganotoni force-pushed the refactor/runtime-to-stdlib branch from 781376a to 66eeab9 Compare March 20, 2026 16:26
@paganotoni paganotoni merged commit a6151ac into main Mar 20, 2026
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.

1 participant