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

snapcraft: go build -trimpath #180

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

simondeziel
Copy link
Member

https://go.dev/doc/go1.13#go-command:

The new go build flag -trimpath removes all file system paths
from the compiled executable, to improve build reproducibility.

Another benefit is the resulting snap is smaller:

# df -ha | grep -wF /snap/lxd
/dev/loop5      152M  152M     0 100% /snap/lxd/25899  # latest-edge
/dev/loop0      149M  149M     0 100% /snap/lxd/x2        # snap from this PR

Some of those ~3M saved are due to not including the path to go's snap nor the build directory:

# strings /snap/lxd/25899/bin/lx* | grep -E '^/(snap|build/lxd)/' | sort -R | tail
/snap/go/10339/src/internal/poll/sendfile_linux.go
/snap/go/10339/src/internal/poll/sendfile_linux.go
/snap/go/10339/src/internal/poll/sendfile_linux.go
/snap/go/10339/src/internal/poll/sendfile_linux.go
/snap/go/10339/src/internal/poll/sendfile_linux.go
/snap/go/10339/src/internal/poll/sendfile_linux.go
/snap/go/10339/src/internal/poll/sendfile_linux.go
/build/lxd/parts/lxd-migrate/build/.go/pkg/mod/golang.org/x/[email protected]/internal/poly1305/sum_generic.go
/build/lxd/parts/lxd/src/lxd/db/cluster/snapshots.mapper.go
/build/lxd/parts/lxd/src/lxd/db/cluster/snapshots.mapper.go

# ll /snap/lxd/{25899,x2}/bin/lx{c,d} | sort
-rwxr-xr-x 1 root root 16111912 Oct  6 02:42 /snap/lxd/x2/bin/lxc*
-rwxr-xr-x 1 root root 16144880 Oct  5 13:58 /snap/lxd/25899/bin/lxc*
-rwxr-xr-x 1 root root 44666280 Oct  6 02:42 /snap/lxd/x2/bin/lxd*
-rwxr-xr-x 1 root root 44736112 Oct  5 13:58 /snap/lxd/25899/bin/lxd*

# strings /snap/lxd/25899/bin/lx* | grep -E '^/(snap|build/lxd)/' | wc -c
687812

# strings /snap/lxd/x2/bin/lx* | grep -E '^/(snap|build/lxd)/' | wc -c
0

https://go.dev/doc/go1.13#go-command:
> The new go build flag -trimpath removes all file system paths
> from the compiled executable, to improve build reproducibility.

Signed-off-by: Simon Deziel <[email protected]>
@simondeziel simondeziel marked this pull request as ready for review October 6, 2023 06:06
@simondeziel simondeziel requested a review from tomponline October 6, 2023 06:06
@tomponline
Copy link
Member

Can you do this on MicroCloud too please @simondeziel

Thanks

@tomponline tomponline merged commit 2536a2d into canonical:latest-edge Oct 6, 2023
1 check passed
@simondeziel simondeziel deleted the trimpath branch October 6, 2023 14:04
@simondeziel
Copy link
Member Author

Can you do this on MicroCloud too please @simondeziel

canonical/microcloud-pkg-snap#2

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