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 7// mksyscall_windows wraps golang.org/x/sys/windows/mkwinsyscall. 8package main 9 10import ( 11 "bytes" 12 "os" 13 "os/exec" 14 "path/filepath" 15 "runtime" 16) 17 18func main() { 19 goTool := filepath.Join(runtime.GOROOT(), "bin", "go") 20 21 listCmd := exec.Command(goTool, "list", "-m") 22 listCmd.Env = append(os.Environ(), "GO111MODULE=on") 23 24 var ( 25 cmdEnv []string 26 modArgs []string 27 ) 28 if out, err := listCmd.Output(); err == nil && string(bytes.TrimSpace(out)) == "std" { 29 // Force module mode to use mkwinsyscall at the same version as the x/sys 30 // module vendored into the standard library. 31 cmdEnv = append(os.Environ(), "GO111MODULE=on") 32 33 // Force -mod=readonly instead of the default -mod=vendor. 34 // 35 // mkwinsyscall is not itself vendored into the standard library, and it is 36 // not feasible to do so at the moment: std-vendored libraries are included 37 // in the "std" meta-pattern (because in general they *are* linked into 38 // users binaries separately from the original import paths), and we can't 39 // allow a binary in the "std" meta-pattern. 40 modArgs = []string{"-mod=readonly"} 41 } else { 42 // Nobody outside the standard library should be using this wrapper: other 43 // modules can vendor in the mkwinsyscall tool directly (as described in 44 // https://golang.org/issue/25922), so they don't need this wrapper to 45 // set module mode and -mod=readonly explicitly. 46 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") 47 } 48 49 args := append([]string{"run"}, modArgs...) 50 args = append(args, "golang.org/x/sys/windows/mkwinsyscall") 51 args = append(args, os.Args[1:]...) 52 cmd := exec.Command(goTool, args...) 53 cmd.Stdout = os.Stdout 54 cmd.Stderr = os.Stderr 55 cmd.Env = cmdEnv 56 err := cmd.Run() 57 if err != nil { 58 os.Exit(1) 59 } 60} 61