Skip to content

Commit 9f83a02

Browse files
committed
Implement cross compilation
1 parent 0147a80 commit 9f83a02

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

cmd/build.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
7+
"strings"
68

79
"github.com/code-game-project/go-utils/cgfile"
810
"github.com/code-game-project/go-utils/external"
@@ -25,14 +27,31 @@ var buildCmd = &cobra.Command{
2527
data.URL = external.TrimURL(data.URL)
2628
abort(data.Write(""))
2729

28-
cmdArgs := []string{"build"}
29-
cmdArgs = append(cmdArgs, args...)
30-
3130
output, err := cmd.Flags().GetString("output")
3231
abort(err)
32+
33+
os, err := cmd.Flags().GetString("os")
34+
abort(err)
35+
os = strings.ToLower(os)
36+
if os != "current" && os != "windows" && os != "macos" && os != "linux" {
37+
abort(fmt.Errorf("OS '%s' is not supported. (possible values: windows, macos, linux)", os))
38+
}
39+
arch, err := cmd.Flags().GetString("arch")
40+
abort(err)
41+
arch = strings.ToLower(arch)
42+
if arch != "current" && arch != "x64" && arch != "x86" && arch != "arm32" && arch != "arm64" {
43+
abort(fmt.Errorf("Architecture '%s' is not supported. (possible values: x64, x86, arm32, arm64)", arch))
44+
}
45+
46+
if os == "macos" && arch == "arm32" {
47+
abort(errors.New("macOS does not support arm32. Try arm64 instead."))
48+
}
49+
3350
buildData := modules.BuildData{
3451
Lang: data.Lang,
3552
Output: output,
53+
OS: os,
54+
Arch: arch,
3655
}
3756
switch data.Lang {
3857
case "cs", "go", "js", "ts":
@@ -47,4 +66,6 @@ var buildCmd = &cobra.Command{
4766
func init() {
4867
rootCmd.AddCommand(buildCmd)
4968
buildCmd.Flags().StringP("output", "o", "", "The name of the output file.")
69+
buildCmd.Flags().String("os", "current", "The target OS for compiled languages. (possible values: windows, macos, linux)")
70+
buildCmd.Flags().String("arch", "current", "The target architecture for compiled languages. (possible values: x64, x86, arm32, arm64)")
5071
}

cmd/game_create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var gameCreateCmd = &cobra.Command{
5959
}
6060
var r response
6161
err = json.NewDecoder(resp.Body).Decode(&r)
62+
abort(err)
6263

6364
out := colorable.NewColorableStdout()
6465
fmt.Fprintf(out, "%sGame ID:%s %s\n", cli.Cyan, cli.Reset, r.GameId)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/Bananenpro/cli v0.3.0
77
github.com/adrg/xdg v0.4.0
8-
github.com/code-game-project/go-utils v0.2.11
8+
github.com/code-game-project/go-utils v0.2.13
99
github.com/gomarkdown/markdown v0.0.0-20220731190611-dcdaee8e7a53
1010
github.com/google/uuid v1.3.0
1111
github.com/mattn/go-colorable v0.1.12
@@ -19,7 +19,7 @@ require (
1919
github.com/mattn/go-isatty v0.0.14 // indirect
2020
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
2121
github.com/spf13/pflag v1.0.5 // indirect
22-
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
22+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
2323
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
2424
golang.org/x/text v0.3.7 // indirect
2525
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n
66
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
77
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
88
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
9-
github.com/code-game-project/go-utils v0.2.11 h1:PhAD+6cPacBuAFcfBEV5oHhzo0R9/N48ZGSpziKOKCE=
10-
github.com/code-game-project/go-utils v0.2.11/go.mod h1:/ws9iYkZCnZvS9g2aqdxKwSnU5AEeI7SE1mbB+x4ggg=
9+
github.com/code-game-project/go-utils v0.2.13 h1:Am5raDGXHPywKH6VtKFEvG7rx6GbaJ8G0z6eHGnufX4=
10+
github.com/code-game-project/go-utils v0.2.13/go.mod h1:/ws9iYkZCnZvS9g2aqdxKwSnU5AEeI7SE1mbB+x4ggg=
1111
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1212
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
1313
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
@@ -51,8 +51,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
5151
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5252
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5353
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
54-
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs=
55-
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
54+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
55+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5656
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
5757
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
5858
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/code-game-project/codegame-cli/cmd"
2121
)
2222

23-
const Version = "0.7.2"
23+
const Version = "0.8.0"
2424

2525
func main() {
2626
checkVersion()

0 commit comments

Comments
 (0)