Home > other >  what does //go:build xxx and // build xxx means in golang?
what does //go:build xxx and // build xxx means in golang?

Time:03-26

I always see the code,

//go:build linux
//  build linux

what mean? I don't understand.

just give me some examples

CodePudding user response:

These are build constraints, see https://pkg.go.dev/go/build#hdr-Build_Constraints

In older versions of Go, you would say

//  build linux

where the new syntax from Go 1.17 and up is

//go:build linux

but they do the same thing: only include this file in the Linux build.

  • Related