Skip to content
Snippets Groups Projects
Commit 62c3e546 authored by Elias Salam's avatar Elias Salam
Browse files

feat(build): add variable for go linker flags

parent 73819023
No related branches found
No related tags found
No related merge requests found
......@@ -68,6 +68,7 @@ These jobs use the following variable:
| Name | description | default value |
| ----------------------- | ---------------------------------------- | ----------------- |
| `GO_BUILD_FLAGS` | Flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) | `-mod=readonly` |
| `GO_BUILD_LINKER_FLAGS` | Linker flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) `-ldflags` | `-s -w` |
| `GO_BUILD_PACKAGES` | Packages to build with the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) | `./...` |
| `GO_TEST_FLAGS` | Flags used by the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages) | `-mod=readonly -v -race` |
| `GO_TEST_PACKAGES` | Packages to test with the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages) | `./...` |
......
......@@ -31,6 +31,12 @@
"default": "-mod=readonly",
"advanced": true
},
{
"name": "GO_BUILD_LINKER_FLAGS",
"description": "Linker flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) `-ldflags`",
"default": "-s -w",
"advanced": true
},
{
"name": "GO_BUILD_PACKAGES",
"description": "Packages to build with the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)",
......
......@@ -54,6 +54,9 @@ variables:
GO_BUILD_FLAGS: >-
-mod=readonly
# Default flags for go build linker
GO_BUILD_LINKER_FLAGS: "-s -w"
# Default packages for 'build' command
GO_BUILD_PACKAGES: >-
./...
......@@ -130,7 +133,7 @@ stages:
target_dir="$GOBIN/$GO_TARGET_OS/$GO_TARGET_ARCH"
mkdir -p "$target_dir"
# shellcheck disable=SC2086
GOOS="$GO_TARGET_OS" GOARCH="$GO_TARGET_ARCH" go build $GO_BUILD_FLAGS -o "$target_dir" $GO_BUILD_PACKAGES
GOOS="$GO_TARGET_OS" GOARCH="$GO_TARGET_ARCH" go build -ldflags="$GO_BUILD_LINKER_FLAGS" $GO_BUILD_FLAGS -o "$target_dir" $GO_BUILD_PACKAGES
}
function go_test() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment