diff --git a/sonar-go-plugin/build.gradle.kts b/sonar-go-plugin/build.gradle.kts index d870c8f6..96bf4306 100644 --- a/sonar-go-plugin/build.gradle.kts +++ b/sonar-go-plugin/build.gradle.kts @@ -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) } } diff --git a/sonar-go-to-slang/Makefile b/sonar-go-to-slang/Makefile deleted file mode 100644 index 5cf7a8c9..00000000 --- a/sonar-go-to-slang/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -GO_VERSION=1.21.1 -GO_BINARY=go$(GO_VERSION) - -all: goparser_generated.go - -install_go: - go install golang.org/dl/go"${GO_VERSION}@latest" - $(GO_BINARY) download - - -goparser_generated.go: generate_source.go install_go - $(GO_BINARY) run generate_source.go - GOOS=darwin GOARCH=amd64 $(GO_BINARY) build -o build/sonar-go-to-slang-darwin-amd64 - GOOS=linux GOARCH=amd64 $(GO_BINARY) build -o build/sonar-go-to-slang-linux-amd64 - GOOS=windows GOARCH=amd64 $(GO_BINARY) build -o build/sonar-go-to-slang-windows-amd64.exe - -test-report.out: install_go - $(GO_BINARY) test -json > test-report.out - - -clean: - rm -f goparser_generated.go - rm -f build/sonar-go-to-slang-* diff --git a/sonar-go-to-slang/build.gradle.kts b/sonar-go-to-slang/build.gradle.kts index ea11015e..ed4f8510 100644 --- a/sonar-go-to-slang/build.gradle.kts +++ b/sonar-go-to-slang/build.gradle.kts @@ -53,6 +53,7 @@ val compileGo by tasks.registering(Exec::class) { } ) outputs.dir("build/executable") + outputs.cacheIf { true } callMake("build") } diff --git a/sonar-go-to-slang/make.sh b/sonar-go-to-slang/make.sh index 2d11adc5..0c4f6acd 100755 --- a/sonar-go-to-slang/make.sh +++ b/sonar-go-to-slang/make.sh @@ -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() {