Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARGO-57 Reduce the size of the Go binary #68

Merged
merged 2 commits into from
Jan 6, 2025
Merged

SONARGO-57 Reduce the size of the Go binary #68

merged 2 commits into from
Jan 6, 2025

Conversation

petertrr
Copy link
Contributor

@petertrr petertrr commented Dec 30, 2024

@petertrr petertrr force-pushed the SONARGO-57 branch 4 times, most recently from 15a7b26 to ce70260 Compare January 6, 2025 11:07
@petertrr petertrr changed the title SONARGO-57 Setup static linking with musl for the Go binary SONARGO-57 Reduce the size of the Go binary Jan 6, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile was unused in scripts and not mentioned in the readme 🤷‍♀️

@petertrr petertrr marked this pull request as ready for review January 6, 2025 11:23
GOOS=darwin GOARCH=arm64 ${path_to_binary} build -o build/executable/sonar-go-to-slang-darwin-arm64 "${GO_FLAGS[@]}"
if command -v musl-gcc &> /dev/null; then
# This should be run on CI; for a dev environment, this is not essential
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"'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main reduction (and for all platfroms) is achieved with -ldflags="-s -w" which removes debug info from the binary. However, static linking almost doesn't affect the size (2.3M -> 2.4M) and should make the Linux executable run on wider selection of platforms

@petertrr petertrr requested a review from mstachniuk January 6, 2025 11:26
Copy link

sonarqube-next bot commented Jan 6, 2025

Quality Gate passed Quality Gate passed for 'Go'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube

@petertrr petertrr merged commit bd17952 into master Jan 6, 2025
8 checks passed
@petertrr petertrr deleted the SONARGO-57 branch January 6, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants