From 6989210e318248f18c16e68550861868fc3a638e Mon Sep 17 00:00:00 2001 From: songjc <969378911@qq.com> Date: Mon, 16 Oct 2023 16:23:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0arm64=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- magefiles/common.go | 15 ++++++++++++--- magefiles/targets/targets.go | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/magefiles/common.go b/magefiles/common.go index 3eb9149..a1862e3 100644 --- a/magefiles/common.go +++ b/magefiles/common.go @@ -23,7 +23,7 @@ type BuildArgs struct { OutputName string OutputDir string AssetsDir string - EntryFile string + EntryFile string } type goBuildArgs struct { @@ -50,12 +50,12 @@ func Build(args BuildArgs) error { binPath := filepath.Join(fullOutputDir, args.OutputName+goBuildArgs.OutputExt) fmt.Printf("building to %s\n", binPath) - goCmdArgs := []string{ "build", "-o", binPath} + goCmdArgs := []string{"build", "-o", binPath} if args.EntryFile != "" { goCmdArgs = append(goCmdArgs, args.EntryFile) } - err = sh.RunWith(goBuildArgs.Env,"go", goCmdArgs...) + err = sh.RunWith(goBuildArgs.Env, "go", goCmdArgs...) if err != nil { return err } @@ -83,10 +83,19 @@ func makeGoBuildArgs() (goBuildArgs, error) { args.OutputExt = "" args.Env["CGO_ENABLE"] = "0" args.Env["GOOS"] = "linux" + } else if Global.OS != "" { return goBuildArgs{}, fmt.Errorf("unknow os type: %s", Global.OS) } + if Global.Arch == "amd64" { + args.Env["GOARCH"] = "amd64" + } else if Global.Arch == "arm64" { + args.Env["GOARCH"] = "arm64" + } else if Global.Arch != "" { + return goBuildArgs{}, fmt.Errorf("unknow arch type: %s", Global.Arch) + } + var pltParts []string if Global.OS != "" { pltParts = append(pltParts, Global.OS) diff --git a/magefiles/targets/targets.go b/magefiles/targets/targets.go index a941e93..09c8212 100644 --- a/magefiles/targets/targets.go +++ b/magefiles/targets/targets.go @@ -19,6 +19,11 @@ func AMD64() { magefiles.Global.Arch = "amd64" } +// [配置项]设置编译架构为arm64 +func ARM64() { + magefiles.Global.Arch = "arm64" +} + // [配置项]设置编译的根目录 func BuildRoot(dir string) { magefiles.Global.BuildRoot = dir