Browse Source

Merge pull request '增加arm64编译' (#28) from feature_sjc into master

pull/29/head
Sydonian 2 years ago
parent
commit
64793b1dd1
2 changed files with 17 additions and 3 deletions
  1. +12
    -3
      magefiles/common.go
  2. +5
    -0
      magefiles/targets/targets.go

+ 12
- 3
magefiles/common.go View File

@@ -23,7 +23,7 @@ type BuildArgs struct {
OutputName string OutputName string
OutputDir string OutputDir string
AssetsDir string AssetsDir string
EntryFile string
EntryFile string
} }


type goBuildArgs struct { type goBuildArgs struct {
@@ -50,12 +50,12 @@ func Build(args BuildArgs) error {
binPath := filepath.Join(fullOutputDir, args.OutputName+goBuildArgs.OutputExt) binPath := filepath.Join(fullOutputDir, args.OutputName+goBuildArgs.OutputExt)
fmt.Printf("building to %s\n", binPath) fmt.Printf("building to %s\n", binPath)


goCmdArgs := []string{ "build", "-o", binPath}
goCmdArgs := []string{"build", "-o", binPath}
if args.EntryFile != "" { if args.EntryFile != "" {
goCmdArgs = append(goCmdArgs, args.EntryFile) goCmdArgs = append(goCmdArgs, args.EntryFile)
} }


err = sh.RunWith(goBuildArgs.Env,"go", goCmdArgs...)
err = sh.RunWith(goBuildArgs.Env, "go", goCmdArgs...)
if err != nil { if err != nil {
return err return err
} }
@@ -83,10 +83,19 @@ func makeGoBuildArgs() (goBuildArgs, error) {
args.OutputExt = "" args.OutputExt = ""
args.Env["CGO_ENABLE"] = "0" args.Env["CGO_ENABLE"] = "0"
args.Env["GOOS"] = "linux" args.Env["GOOS"] = "linux"

} else if Global.OS != "" { } else if Global.OS != "" {
return goBuildArgs{}, fmt.Errorf("unknow os type: %s", 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 var pltParts []string
if Global.OS != "" { if Global.OS != "" {
pltParts = append(pltParts, Global.OS) pltParts = append(pltParts, Global.OS)


+ 5
- 0
magefiles/targets/targets.go View File

@@ -19,6 +19,11 @@ func AMD64() {
magefiles.Global.Arch = "amd64" magefiles.Global.Arch = "amd64"
} }


// [配置项]设置编译架构为arm64
func ARM64() {
magefiles.Global.Arch = "arm64"
}

// [配置项]设置编译的根目录 // [配置项]设置编译的根目录
func BuildRoot(dir string) { func BuildRoot(dir string) {
magefiles.Global.BuildRoot = dir magefiles.Global.BuildRoot = dir


Loading…
Cancel
Save