wa-lang.org/wazero@v1.0.2/internal/version/version.go (about) 1 package version 2 3 import ( 4 "runtime/debug" 5 "strings" 6 ) 7 8 // WazeroVersionKey is the key for holding wazero's version in context.Context. 9 type WazeroVersionKey struct{} 10 11 // GetWazeroVersion returns the current version of wazero in the go.mod. 12 // This assumes that users of wazero imports wazero as "wa-lang.org/wazero". 13 // To be precise, the returned string matches the require statement there. 14 // For example, if the go.mod has "require github.com/tetratelabs/wazero 0.1.2-12314124-abcd", 15 // then this returns "0.1.2-12314124-abcd". 16 // 17 // Note: this is tested in ./testdata/main_test.go with a separate go.mod to pretend as the wazero user. 18 func GetWazeroVersion() (ret string) { 19 ret = "dev" 20 info, ok := debug.ReadBuildInfo() 21 if ok { 22 for _, dep := range info.Deps { 23 // Note: here's the assumption that wazero is imported as github.com/tetratelabs/wazero. 24 if strings.Contains(dep.Path, "wa-lang.org/wazero") { 25 ret = dep.Version 26 } 27 } 28 } 29 return 30 }