-4

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

Farzad
  • 1,770
  • 4
  • 26
  • 48
  • 4
    See [build constraints](https://golang.org/pkg/go/build/#hdr-Build_Constraints) for conditionally compiling files on different platforms. See [Windows Cross Compiling](https://github.com/golang/go/wiki/WindowsCrossCompiling) for information on how to build Windows programs on Linux and other platforms. – Charlie Tumahai Nov 01 '19 at 05:12
  • 2
    Note the _linux, _windows and _darwin filename suffixes which allow simple OS specific compilation. – Volker Nov 01 '19 at 06:11
  • You can find documentation on [godoc](https://godoc.org/github.com/microsoft/go-winio), but you already need to know a lot of windows-specific terms – xarantolus Nov 01 '19 at 06:43
  • Thank you all for your comments. I already found out the `// +build` comment and file suffixes, but my problem and question is that: if I have a package that does use those features (for example only has a `_windows` file), I have no way to get tools support (IntelliSense etc.) on a Linux development environment? – Farzad Nov 01 '19 at 12:00
  • That question is entirely specific to the tools involved - if that's the only thing you're having trouble with, then this isn't so much a Go packages question as it is a VS Code question. Go itself handles this just fine, it's just your tools that are at issue. You can probably override the build flags for build commands that it's using, but it may get more complicated for things like code completion - there are various ways it may be scanning code for symbols and you'll have different configuration options depending on what you're using. – Adrian Nov 01 '19 at 13:11
  • I totally agree with you @Adrian. I guess I asked the question a bit too soon without researching more. It was late at night, and I was so tired and confused. I'm gonna answer my own question with the issues I found on `gopls` tool used by VSCode – Farzad Nov 01 '19 at 13:41

1 Answers1

0

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

Farzad
  • 1,770
  • 4
  • 26
  • 48