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

goreleaser: add -static to LDFLAGS for windows build #5594

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ jobs:
- checkout
- run: iex ./scripts/install-dc2.ps1
# Check to make sure Windows binaries compile
- run: go install -mod vendor ./cmd/tilt
- run:
command: go install -mod vendor ./cmd/tilt
environment:
CGO_ENABLED: '1'
CGO_LDFLAGS: -static
- run: make shorttestsum
- run: iex ./scripts/install.ps1
- store_test_results:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ builds:
- amd64
env:
- CGO_ENABLED=1
- CGO_LDFLAGS=-static
Copy link
Member

Choose a reason for hiding this comment

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

maybe add it to every build to be consistent? i'd hate if we had a bug that only affected static builds. i guess in theory macos should always have glibc from xcode

Copy link
Contributor

@milas milas Mar 15, 2022

Choose a reason for hiding this comment

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

You actually can't statically link to the system libraries on macOS - they require you to dynamically link:

   ⨯ build failed after 181.83s error=failed to build for darwin_amd64: exit status 2: # runtime/cgo
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

And fwiw, for Linux, I think it's expected that you either dynamically link against glibc or statically link everything using musl.

Our current setup should be fine on those OSes as we don't have any implicit links to non-system libraries (e.g. we didn't apt-get install libusb-dev and then dynamically link against the system copy - the go-tree-sitter package vendors in the Tree-sitter code so it'll get compiled straight in)

From v0.26.0:

Linux

ldd $(which tilt)
	linux-vdso.so.1 (0x00007ffd56fc4000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f697ac6d000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f697ac67000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f697aa85000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f697a936000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f697a91b000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f697a729000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f697ac95000)

Darwin

$ otool -L $(which tilt)
/usr/local/bin/tilt:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1775.118.101)
	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 59754.100.106)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1122.33.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 905.6.0)

Copy link
Contributor

@milas milas Mar 15, 2022

Choose a reason for hiding this comment

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

That said, might be worth adding CGO_ENABLED=1 CGO_LDFLAGS=-static to the CircleCI build-windows job:

- run: go install -mod vendor ./cmd/tilt

Copy link
Member

Choose a reason for hiding this comment

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

ah ok!

Copy link
Member Author

Choose a reason for hiding this comment

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

There are also some interesting notes here, so maybe building static cross compiled binaries is a thing people want to do, and yet, I don't want to complicate things here too much.

- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
archives:
Expand Down