summaryrefslogtreecommitdiff
path: root/hack/lib/golang.sh
diff options
context:
space:
mode:
authorDave Chen <dave.jungler@gmail.com>2020-08-20 15:47:00 +0800
committerDave Chen <dave.jungler@gmail.com>2020-09-04 14:56:19 +0800
commit804698b610fee0ad90c8b320df4db909c2aafec5 (patch)
treeda85ddbf03c6d135a3ecdbe531816bd1f038c4c4 /hack/lib/golang.sh
parentMerge pull request #2077 from daixiang0/add-binary-links (diff)
downloadkubeedge-804698b610fee0ad90c8b320df4db909c2aafec5.tar.gz
Add the build option to make the binaries debuggable
By default, the debug info will be stripped for the binaries, `cloudcore` for example, to keep the binary as small as possible. This behavior can be overwritten by adding the options `GOLDFLAGS` or `GOGCFLAGS` when building the binaries. As a example, the binary `cloudcore` built with the below command will have DWARF and symbol table kept, the optimizations and inline will also been disabled, this is helpful when you want to use the debugging tools like `delve`. `make all WHAT=cloudcore GOLDFLAGS="" GOGCFLAGS="-N -l"` Signed-off-by: Dave Chen <dave.chen@arm.com>
Diffstat (limited to 'hack/lib/golang.sh')
-rw-r--r--hack/lib/golang.sh8
1 files changed, 5 insertions, 3 deletions
diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 8a9a13fb7..780e7dfee 100644
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -202,15 +202,17 @@ kubeedge::golang::build_binaries() {
local -a binaries
while IFS="" read -r binary; do binaries+=("$binary"); done < <(kubeedge::golang::binaries_from_targets "${targets[@]}")
- local ldflags
- read -r ldflags <<< "$(kubeedge::version::ldflags)"
+ local goldflags gogcflags
+ # If GOLDFLAGS is unset, then set it to the a default of "-s -w".
+ goldflags="${GOLDFLAGS=-s -w -buildid=} $(kubeedge::version::ldflags)"
+ gogcflags="${GOGCFLAGS:-}"
mkdir -p ${KUBEEDGE_OUTPUT_BINPATH}
for bin in ${binaries[@]}; do
echo "building $bin"
local name="${bin##*/}"
set -x
- go build -o ${KUBEEDGE_OUTPUT_BINPATH}/${name} -ldflags "$ldflags" $bin
+ go build -o ${KUBEEDGE_OUTPUT_BINPATH}/${name} -gcflags="${gogcflags:-}" -ldflags "${goldflags:-}" $bin
set +x
done