Chore: Disable cgo by default for local builds (#111807)

* disable cgo by default for local builds, also set cgo variable in either case

* actually do not set the default value

* disable cgo for darwin, display sqlite driver in logs

* fix linter warning, although I do not fully agree with it
This commit is contained in:
Serge Zaitsev
2025-09-30 23:06:40 +02:00
committed by GitHub
parent 901dd9506f
commit 174e924e15
5 changed files with 22 additions and 8 deletions
+9 -5
View File
@@ -18,6 +18,7 @@ import (
const (
GoOSWindows = "windows"
GoOSLinux = "linux"
GoOSDarwin = "darwin"
BackendBinary = "grafana"
ServerBinary = "grafana-server"
@@ -288,8 +289,9 @@ func setBuildEnv(opts BuildOpts) error {
}
}
if opts.goarch != "amd64" || opts.goos != GoOSLinux {
// needed for all other archs
if (opts.goos != GoOSLinux || opts.goarch != "amd64") &&
opts.goos != GoOSDarwin {
// needed for archs other than linux/amd64 and darwin/arm64 + darwin/amd64
opts.cgo = true
}
@@ -307,10 +309,12 @@ func setBuildEnv(opts BuildOpts) error {
}
}
cgoEnabled := "0"
if opts.cgo {
if err := os.Setenv("CGO_ENABLED", "1"); err != nil {
return err
}
cgoEnabled = "1"
}
if err := os.Setenv("CGO_ENABLED", cgoEnabled); err != nil {
return err
}
if opts.gocc == "" {
+4
View File
@@ -16,6 +16,7 @@ import (
_ "github.com/lib/pq"
"github.com/prometheus/client_golang/prometheus"
"github.com/grafana/grafana/pkg/util/sqlite"
"github.com/grafana/grafana/pkg/util/xorm"
"github.com/grafana/grafana/pkg/util/xorm/core"
@@ -248,6 +249,9 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
}
ss.log.Info("Connecting to DB", "dbtype", ss.dbCfg.Type)
if ss.dbCfg.Type == migrator.SQLite {
ss.log.Info("Using SQLite driver", "driver", sqlite.DriverType())
}
if ss.dbCfg.Type == migrator.SQLite && strings.HasPrefix(ss.dbCfg.ConnectionString, "file:") &&
!strings.HasPrefix(ss.dbCfg.ConnectionString, "file::memory:") {
exists, err := fs.Exists(ss.dbCfg.Path)
+4 -3
View File
@@ -35,12 +35,13 @@ func IsUniqueConstraintViolation(err error) bool {
}
func ErrorMessage(err error) string {
if err == nil {
return ""
}
var sqliteErr sqlite3.Error
if errors.As(err, &sqliteErr) {
return sqliteErr.Error()
}
return err.Error()
}
func DriverType() string {
return "mattn/go-sqlite3 (CGO enabled)"
}
+4
View File
@@ -112,6 +112,10 @@ func init() {
sql.Register("sqlite3", &moderncDriver{Driver: &Driver{}})
}
func DriverType() string {
return "modernc.org/sqlite (CGO disabled)"
}
func IsBusyOrLocked(err error) bool {
var sqliteErr *sqlite.Error
if errors.As(err, &sqliteErr) {