Does go have OS-specific packages that cannot be used on another OS?

417 Views Asked by At

I cannot call myself an absolute beginner in go, and I'm definitively not an expert.

Today, I noticed something VERY confusing. I was experimenting with Unix sockets and Windows named pipes, and from my research, there are 2 packages that support Windows named pipes:

My OS is Linux, and I decided to give it a go: go get the package(s), and write the code to later test on a Windows machine, but, to my surprise, at least in VSCode, those packages are not recognized by the tooling.

When I look at npipe for example, I see it only has npipe_windows.go, which, if I'm not mistaken, is supposed to automatically be used on Windows.

So, I think there is the concept of OS-specific packages in Go, right? And if so, does it mean that I cannot use, for example, VSCode's go tools to code against Windows packages on Linux?

That, in my opinion, would be extremely inconvenient to have to switch systems in order to write something that works both on Linux and Windows... Although I guess that's only true if we're developing on Linux, and Windows should cover both.

But for me, it doesn't make sense NOT to be able to develop something on Linux; the best environment to develop on IMHO (except Apple-related code of course)

Am I missing something here?

Thank you

1

There are 1 best solutions below

0
On

So, I think my question actually involves more the tooling rather than the go language itself. gopls is the tool used by VSCode if you choose to use the go language server.

As thre README says, it's in alpha and not stable, and there are known issues listed on the repo, which seem to be the source of my confusions.

I think the main issue that's related to what I'm seeing is:

x/tools/gopls: does not handle build tags