Skip to content

Commit

Permalink
SONARGO-57 Setup static linking with musl for the Go binary
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr committed Jan 6, 2025
1 parent 89915f6 commit 15a7b26
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion sonar-go-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ tasks.shadowJar {
exclude("spotless/**")
}
doLast {
enforceJarSizeAndCheckContent(tasks.shadowJar.get().archiveFile.get().asFile, 9_000_000L, 9_500_000L)
enforceJarSizeAndCheckContent(tasks.shadowJar.get().archiveFile.get().asFile, 5_000_000L, 5_500_000L)
}
}

Expand Down
23 changes: 0 additions & 23 deletions sonar-go-to-slang/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions sonar-go-to-slang/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ val compileGo by tasks.registering(Exec::class) {
}
)
outputs.dir("build/executable")
outputs.cacheIf { true }

callMake("build")
}
Expand Down
11 changes: 7 additions & 4 deletions sonar-go-to-slang/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ compile_binaries() {
path_to_binary=$(install_go "${GO_VERSION}")
# Build
bash -c "${path_to_binary} run generate_source.go"

mkdir -p build/executable
bash -c "GOOS=darwin GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-amd64"
bash -c "GOOS=darwin GOARCH=arm64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-arm64"
bash -c "GOOS=linux GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-linux-amd64"
bash -c "GOOS=windows GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-windows-amd64.exe"
# Note: -ldflags="-s -w" is used to strip debug information from the binary and reduce its size.
GO_FLAGS=(-ldflags='-s -w' -buildmode=exe)
GOOS=darwin GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-amd64 "${GO_FLAGS[@]}"
GOOS=darwin GOARCH=arm64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-arm64 "${GO_FLAGS[@]}"
GOOS=linux GOARCH=amd64 CC=musl-gcc ${path_to_binary} build -o build/executable/sonar-go-to-slang-linux-amd64 "${GO_FLAGS[@]}" -ldflags '-linkmode external -extldflags "-s -w -static"'
GOOS=windows GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-windows-amd64.exe "${GO_FLAGS[@]}"
}

generate_test_report() {
Expand Down

0 comments on commit 15a7b26

Please sign in to comment.