diff options
author | ZauberNerd <[email protected]> | 2022-03-04 14:58:40 +0000 |
---|---|---|
committer | Ayke <[email protected]> | 2022-03-19 15:36:44 +0100 |
commit | 2fdcabdcceabe25a43073079db7785acf66538d7 (patch) | |
tree | 7629b2098340f5cee129583460372ed39c111a0b /builder | |
parent | d066b5c2323af9667a57897e0bf2e0778abf3e9e (diff) | |
download | tinygo-2fdcabdcceabe25a43073079db7785acf66538d7.tar.gz tinygo-2fdcabdcceabe25a43073079db7785acf66538d7.zip |
src/runtime: add runtime.Version()
This adds the `Version()` function of the `runtime` package which embeds
the go version that was used to build tinygo.
For programs that are compiled with tinygo the version can be overriden
via the:
`tinygo build -ldflags="-X 'runtime.buildVersion=abc'"` flag.
Otherwise it will continue to use the go version with which tinygo was
compiled.
Diffstat (limited to 'builder')
-rw-r--r-- | builder/build.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/builder/build.go b/builder/build.go index 3dfca4e4a..45e03875b 100644 --- a/builder/build.go +++ b/builder/build.go @@ -204,6 +204,21 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil var packageJobs []*compileJob packageBitcodePaths := make(map[string]string) packageActionIDs := make(map[string]string) + + if config.Options.GlobalValues["runtime"]["buildVersion"] == "" { + version := goenv.Version + if strings.HasSuffix(goenv.Version, "-dev") && goenv.GitSha1 != "" { + version += "-" + goenv.GitSha1 + } + if config.Options.GlobalValues == nil { + config.Options.GlobalValues = make(map[string]map[string]string) + } + if config.Options.GlobalValues["runtime"] == nil { + config.Options.GlobalValues["runtime"] = make(map[string]string) + } + config.Options.GlobalValues["runtime"]["buildVersion"] = version + } + for _, pkg := range lprogram.Sorted() { pkg := pkg // necessary to avoid a race condition |