github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/go/src/syscall/mksyscall_windows.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build ignore 6 // +build ignore 7 8 // mksyscall_windows wraps golang.org/x/sys/windows/mkwinsyscall. 9 package main 10 11 import ( 12 "bytes" 13 "os" 14 "os/exec" 15 "path/filepath" 16 "runtime" 17 ) 18 19 func main() { 20 goTool := filepath.Join(runtime.GOROOT(), "bin", "go") 21 22 listCmd := exec.Command(goTool, "list", "-m") 23 listCmd.Env = append(os.Environ(), "GO111MODULE=on") 24 25 var ( 26 cmdEnv []string 27 modArgs []string 28 ) 29 if out, err := listCmd.Output(); err == nil && string(bytes.TrimSpace(out)) == "std" { 30 // Force module mode to use mkwinsyscall at the same version as the x/sys 31 // module vendored into the standard library. 32 cmdEnv = append(os.Environ(), "GO111MODULE=on") 33 34 // Force -mod=readonly instead of the default -mod=vendor. 35 // 36 // mkwinsyscall is not itself vendored into the standard library, and it is 37 // not feasible to do so at the moment: std-vendored libraries are included 38 // in the "std" meta-pattern (because in general they *are* linked into 39 // users binaries separately from the original import paths), and we can't 40 // allow a binary in the "std" meta-pattern. 41 modArgs = []string{"-mod=readonly"} 42 } else { 43 // Nobody outside the standard library should be using this wrapper: other 44 // modules can vendor in the mkwinsyscall tool directly (as described in 45 // https://golang.org/issue/25922), so they don't need this wrapper to 46 // set module mode and -mod=readonly explicitly. 47 os.Stderr.WriteString("WARNING: Please switch from using:\n go run $GOROOT/src/syscall/mksyscall_windows.go\nto using:\n go run golang.org/x/sys/windows/mkwinsyscall\n") 48 } 49 50 args := append([]string{"run"}, modArgs...) 51 args = append(args, "golang.org/x/sys/windows/mkwinsyscall") 52 args = append(args, os.Args[1:]...) 53 cmd := exec.Command(goTool, args...) 54 cmd.Stdout = os.Stdout 55 cmd.Stderr = os.Stderr 56 cmd.Env = cmdEnv 57 err := cmd.Run() 58 if err != nil { 59 os.Exit(1) 60 } 61 }