mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
go.*,gpu: don't (badly) re-implement Go module versioning
Changes to the gioui.org/shader module are generally breaking changes, which means that a particular version of gioui.org must be build with a particular version of gioui.org/shader. Until now, the gpu package checked the module version against an expected version and would fail at runtime if there's a mismatch. This change replaces all that complexity with a simple procedural change: bump the module major version of gioui.org/shader at each such incompatible change. It doesn't matter that we'll eventually reach gioui.org/v1234/shader; the module is internal and won't break clients. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
-26
@@ -9,14 +9,12 @@ package gpu
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
@@ -134,10 +132,6 @@ type imageOp struct {
|
||||
place placement
|
||||
}
|
||||
|
||||
// shaderModuleVersion is the exact version of gioui.org/shader expected by
|
||||
// this package. Shader programs are not backwards or forwards compatible.
|
||||
const shaderModuleVersion = "v0.0.0-20210821080300-98542fa6d725"
|
||||
|
||||
func decodeStrokeOp(data []byte) clip.StrokeStyle {
|
||||
_ = data[4]
|
||||
if opconst.OpType(data[0]) != opconst.TypeStroke {
|
||||
@@ -358,9 +352,6 @@ const (
|
||||
)
|
||||
|
||||
func New(api API) (GPU, error) {
|
||||
if err := verifyShaderModule(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d, err := driver.NewDevice(api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -387,23 +378,6 @@ func newGPU(ctx driver.Device) (*gpu, error) {
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func verifyShaderModule() error {
|
||||
mod, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
// No module support; hopefully the version matches.
|
||||
return nil
|
||||
}
|
||||
for _, m := range mod.Deps {
|
||||
if m.Path == "gioui.org/shader" {
|
||||
if got := m.Version; got != shaderModuleVersion {
|
||||
return fmt.Errorf("gpu: module gioui.org/shader is version %q, expected %q", got, shaderModuleVersion)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("gpu: module version for gioui.org/shader not found")
|
||||
}
|
||||
|
||||
func (g *gpu) init(ctx driver.Device) error {
|
||||
g.ctx = ctx
|
||||
g.renderer = newRenderer(ctx)
|
||||
|
||||
Reference in New Issue
Block a user