From 33f76d1c2e914bd477bb19060670ae5c3608cf41 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 6 Apr 2021 16:06:12 +0200 Subject: main: implement -ldflags="-X ..." This commit implements replacing some global variables with a different value, if the global variable has no initializer. For example, if you have: package main var version string you can replace the value with -ldflags="-X main.version=0.2". Right now it only works for uninitialized globals. The Go tooling also supports initialized globals (var version = "") but that is a bit hard to combine with how initialized globals are currently implemented. The current implementation still allows caching package IR files while making sure the values don't end up in the build cache. This means compiling a program multiple times with different values will use the cached package each time, inserting the string value only late in the build process. Fixes #1045 --- compileopts/options.go | 1 + 1 file changed, 1 insertion(+) (limited to 'compileopts/options.go') diff --git a/compileopts/options.go b/compileopts/options.go index a12a92cd9..7570fefe5 100644 --- a/compileopts/options.go +++ b/compileopts/options.go @@ -30,6 +30,7 @@ type Options struct { PrintStacks bool Tags string WasmAbi string + GlobalValues map[string]map[string]string // map[pkgpath]map[varname]value TestConfig TestConfig Programmer string } -- cgit v1.2.3