Last active
May 26, 2021 11:59
-
-
Save giovaneliberato/c648319d54a31f100118e4d9884c3d53 to your computer and use it in GitHub Desktop.
Golang cli wrapper for Mac M1 chips - Add -tags=dynamic required by some libraries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Installation | |
// - go build cli_wrapper.go | |
// - mv cli_wrapper go | |
// - export PATH=`pwd`:$PATH | |
package main | |
import "fmt" | |
import "os" | |
import "os/exec" | |
import "strings" | |
func addDynamicTag(args []string) []string { | |
for i, a := range args { | |
if strings.Contains(a, "-tags=") { | |
args[i] = a + ",dynamic" | |
return args | |
} | |
} | |
args = append(args, "") | |
copy(args[2:], args[1:]) | |
args[1] = "-tags=dynamic" | |
return args | |
} | |
func main() { | |
pwd, _ := os.Getwd() | |
goArgs := os.Args[1:] | |
subcommand := goArgs[0] | |
switch subcommand { | |
case | |
"build", | |
"test", | |
"install": | |
goArgs = addDynamicTag(goArgs) | |
} | |
cmd := exec.Command("/opt/homebrew/bin/go", goArgs...) | |
cmd.Dir = pwd | |
stdout, err := cmd.Output() | |
if err != nil { | |
fmt.Println(err.Error()) | |
return | |
} | |
fmt.Println(string(stdout)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment