Skip to content

hack/make/.binary: don't use "netgo" when building Windows binaries#45603

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:windows_notgo
May 24, 2023
Merged

hack/make/.binary: don't use "netgo" when building Windows binaries#45603
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:windows_notgo

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented May 24, 2023

Starting with go1.19, the Go runtime on Windows now supports the netgo build- flag to use a native Go DNS resolver. Prior to that version, the build-flag only had an effect on non-Windows platforms. When using the netgo build-flag, the Windows's host resolver is not used, and as a result, custom entries in etc/hosts are ignored, which is a change in behavior from binaries compiled with older versions of the Go runtime.

From the go1.19 release notes: https://go.dev/doc/go1.19#net

Resolver.PreferGo is now implemented on Windows and Plan 9. It previously
only worked on Unix platforms. Combined with Dialer.Resolver and Resolver.Dial,
it's now possible to write portable programs and be in control of all DNS name
lookups when dialing.

The net package now has initial support for the netgo build tag on Windows.
When used, the package uses the Go DNS client (as used by Resolver.PreferGo)
instead of asking Windows for DNS results. The upstream DNS server it discovers
from Windows may not yet be correct with complex system network configurations,
however.

Our Windows binaries are compiled with the "static" (make/binary-daemon) script, which has the netgo option set by default. This patch unsets the netgo option when cross-compiling for Windows.

- What I did

- How I did it

- How to verify it

- Description for the changelog

  • Fix a failure to respect the hosts file and other components of the native DNS stack on Windows.

- A picture of a cute animal (not mandatory but encouraged)

@neersighted
Copy link
Copy Markdown
Member

The first version of this PR didn't successfully disable the buildtag; I have updated the PR to do so.

Copy link
Copy Markdown
Member Author

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM on fixing up :)

@thaJeztah
Copy link
Copy Markdown
Member Author

We may still update the comment to link to the Golang issue about etc/hosts not being supported (turned out it's a 'TODO' that wasn't mentioned 🤦)

Starting with go1.19, the Go runtime on Windows now supports the `netgo` build-
flag to use a native Go DNS resolver. Prior to that version, the build-flag
only had an effect on non-Windows platforms. When using the `netgo` build-flag,
the Windows's host resolver is not used, and as a result, custom entries in
`etc/hosts` are ignored, which is a change in behavior from binaries compiled
with older versions of the Go runtime.

From the go1.19 release notes: https://go.dev/doc/go1.19#net

> Resolver.PreferGo is now implemented on Windows and Plan 9. It previously
> only worked on Unix platforms. Combined with Dialer.Resolver and Resolver.Dial,
> it's now possible to write portable programs and be in control of all DNS name
> lookups when dialing.
>
> The net package now has initial support for the netgo build tag on Windows.
> When used, the package uses the Go DNS client (as used by Resolver.PreferGo)
> instead of asking Windows for DNS results. The upstream DNS server it discovers
> from Windows may not yet be correct with complex system network configurations,
> however.

Our Windows binaries are compiled with the "static" (`make/binary-daemon`)
script, which has the `netgo` option set by default. This patch unsets the
`netgo` option when cross-compiling for Windows.

Co-authored-by: Bjorn Neergaard <[email protected]>
Signed-off-by: Bjorn Neergaard <[email protected]>
Copy link
Copy Markdown
Member

@neersighted neersighted left a comment

Choose a reason for hiding this comment

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

Applying @thaJeztah's LGTM 🙈

@thaJeztah
Copy link
Copy Markdown
Member Author

All green; let's bring this one in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker pull not resolving private registry address that's been set in the host file

4 participants