1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-13 23:48:45 -04:00
v2fly/tools/build/go.go

26 lines
773 B
Go
Raw Normal View History

2015-10-17 18:50:51 -04:00
package main
import (
"fmt"
"os"
"os/exec"
"time"
)
func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch) error {
ldFlags := "-s"
2015-10-18 07:14:34 -04:00
if version != "custom" {
2015-10-17 18:50:51 -04:00
year, month, day := time.Now().UTC().Date()
today := fmt.Sprintf("%04d%02d%02d", year, int(month), day)
2016-08-20 14:55:45 -04:00
ldFlags = ldFlags + " -X v2ray.com/core.version=" + version + " -X v2ray.com/core.build=" + today
2015-10-17 18:50:51 -04:00
}
2016-10-12 10:46:02 -04:00
cmd := exec.Command("go", "build", "-tags", "json", "-o", targetFile, "-compiler", "gc", "-ldflags", ldFlags, "v2ray.com/core/main")
2016-12-01 15:38:13 -05:00
cmd.Env = append(cmd.Env, "GOOS="+string(goOS), "GOARCH="+string(goArch), "CGO_ENABLED=0")
2015-10-17 18:50:51 -04:00
cmd.Env = append(cmd.Env, os.Environ()...)
2015-10-18 07:14:34 -04:00
output, err := cmd.CombinedOutput()
if len(output) > 0 {
fmt.Println(string(output))
}
2015-10-17 18:50:51 -04:00
return err
}