Files
base/modernc_versions_check.go
zeekay cf0252a28e Merge remote-tracking branch 'upstream/master'
# Conflicts:
#	apis/record_auth_with_otp.go
#	core/base_backup.go
#	go.mod
#	go.sum
#	plugins/jsvm/internal/types/generated/types.d.ts
#	tools/router/rereadable_read_closer_test.go
#	ui/dist/assets/AuthMethodsDocs-C2aSYmNv.js
#	ui/dist/assets/AuthRefreshDocs-BapWJLRK.js
#	ui/dist/assets/AuthWithOAuth2Docs-Ck_pnbL8.js
#	ui/dist/assets/AuthWithOtpDocs-D8uWq_C5.js
#	ui/dist/assets/AuthWithPasswordDocs-BQyMhAeO.js
#	ui/dist/assets/BatchApiDocs-rvUuWLZE.js
#	ui/dist/assets/CodeEditor-DrMyw8z_.js
#	ui/dist/assets/CreateApiDocs-XWzcGuMB.js
#	ui/dist/assets/DeleteApiDocs-CScE0aw3.js
#	ui/dist/assets/EmailChangeDocs-CxOtrB4s.js
#	ui/dist/assets/FieldsQueryParam-BzNUQIb5.js
#	ui/dist/assets/FilterAutocompleteInput-Dm2G2coC.js
#	ui/dist/assets/Leaflet-DyumpnOc.js
#	ui/dist/assets/ListApiDocs-CdOzMZnr.js
#	ui/dist/assets/PageInstaller-vIXdffAJ.js
#	ui/dist/assets/PageOAuth2RedirectFailure-ClpyaW_B.js
#	ui/dist/assets/PageOAuth2RedirectSuccess-BLZml1eK.js
#	ui/dist/assets/PageRecordConfirmEmailChange-Cm3O2YD1.js
#	ui/dist/assets/PageRecordConfirmPasswordReset-D0XfuL45.js
#	ui/dist/assets/PageRecordConfirmVerification-CYyNYH_v.js
#	ui/dist/assets/PageSuperuserConfirmPasswordReset-BvlQ0_9t.js
#	ui/dist/assets/PageSuperuserRequestPasswordReset-gUPMclJZ.js
#	ui/dist/assets/PasswordResetDocs-DMF1vqE0.js
#	ui/dist/assets/RealtimeApiDocs-CNVij_C2.js
#	ui/dist/assets/UpdateApiDocs-CwQ3ZhFQ.js
#	ui/dist/assets/VerificationDocs-DUeWWjrS.js
#	ui/dist/assets/ViewApiDocs-gocWxbTE.js
#	ui/dist/assets/index-CWGqJiyp.js
#	ui/dist/index.html
2026-03-01 19:27:21 -07:00

84 lines
2.8 KiB
Go

package base
import (
"fmt"
"log/slog"
"runtime/debug"
"github.com/fatih/color"
"github.com/hanzoai/base/core"
)
const (
expectedDriverVersion = "v1.46.2"
expectedLibcVersion = "v1.70.0"
// ModerncDepsCheckHookId is the id of the hook that performs the modernc.org/* deps checks.
// It could be used for removing/unbinding the hook if you don't want the checks.
ModerncDepsCheckHookId = "baseModerncDepsCheck"
)
// checkModerncDeps checks whether the current binary was built with the
// expected and tested modernc driver dependencies.
//
// This is needed because modernc.org/libc doesn't follow semantic versioning
// and using a version different from the one in the go.mod of modernc.org/sqlite
// could have unintended side-effects and cause obscure build and runtime bugs
// (https://github.com/hanzoai/base/issues/6136).
func checkModerncDeps(app core.App) {
info, ok := debug.ReadBuildInfo()
if !ok {
return // no build info (probably compiled without module support)
}
var driverVersion, libcVersion string
for _, dep := range info.Deps {
switch dep.Path {
case "modernc.org/libc":
libcVersion = dep.Version
case "modernc.org/sqlite":
driverVersion = dep.Version
}
// no need to further search if both deps are located
if driverVersion != "" && libcVersion != "" {
break
}
}
// not using the default driver
if driverVersion == "" {
return
}
var msg string
if driverVersion != expectedDriverVersion {
msg = fmt.Sprintf(
"You are using modernc.org/sqlite %s which differs from the expected and tested %s.\n"+
"Make sure to either manually update in your go.mod the dependency version to the expected one OR if you want to keep yours "+
"ensure that its indirect modernc.org/libc dependency has the same version as in the https://gitlab.com/cznic/sqlite/-/blob/master/go.mod, "+
"otherwise it could result in unexpected build or runtime errors.",
driverVersion,
expectedDriverVersion,
)
app.Logger().Warn(msg, slog.String("current", driverVersion), slog.String("expected", expectedDriverVersion))
} else if libcVersion != expectedLibcVersion {
msg = fmt.Sprintf(
"You are using modernc.org/libc %s which differs from the expected and tested %s.\n"+
"Please update your go.mod and manually set modernc.org/libc to %s, otherwise it could result in unexpected build or runtime errors "+
"(you may have to also run 'go clean -modcache' to clear the cache if the warning persists).",
libcVersion,
expectedLibcVersion,
expectedLibcVersion,
)
app.Logger().Warn(msg, slog.String("current", libcVersion), slog.String("expected", expectedLibcVersion))
}
// ensure that the message is printed to the default stderr too
// (when in dev mode this is not needed because we print all logs)
if msg != "" && !app.IsDev() {
color.Yellow("\nWARN " + msg + "\n\n")
}
}