Skip to content

Commit

Permalink
SONARGO-57 Reduce the size of the Go binary (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr authored Jan 6, 2025
1 parent e869f93 commit bd17952
Show file tree
Hide file tree
Showing 4 changed files with 10 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.

2 changes: 2 additions & 0 deletions sonar-go-to-slang/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ val compileGo by tasks.registering(Exec::class) {
exclude("build/**", "*_generated.go")
}
)
outputs.file("goparser_generated.go")
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)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-amd64 "${GO_FLAGS[@]}"
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-arm64 "${GO_FLAGS[@]}"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-linux-amd64 "${GO_FLAGS[@]}"
CGO_ENABLED=0 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 bd17952

Please sign in to comment.