44package main
55
66import (
7- "github.com/openimsdk/gomake/mageutil "
7+ "flag "
88 "os"
9- "strings"
9+
10+ "github.com/openimsdk/gomake/mageutil"
1011)
1112
1213var Default = Build
1314
15+ var Aliases = map [string ]any {
16+ "buildcc" : BuildWithCustomConfig ,
17+ "startcc" : StartWithCustomConfig ,
18+ }
19+
20+ var (
21+ customRootDir = "." // workDir in mage, default is "./"(project root directory)
22+ customSrcDir = "cmd" // source code directory, default is "cmd"
23+ customOutputDir = "_output" // output directory, default is "_output"
24+ customConfigDir = "config" // configuration directory, default is "config"
25+ customToolsDir = "tools" // tools source code directory, default is "tools"
26+ )
27+
28+ // Build support specifical binary build.
29+ //
30+ // Example: `mage build chat-api chat-rpc check-component`
1431func Build () {
15- platforms := os .Getenv ("PLATFORMS" )
16- if platforms == "" {
17- platforms = mageutil .DetectPlatform ()
32+ flag .Parse ()
33+ bin := flag .Args ()
34+ if len (bin ) != 0 {
35+ bin = bin [1 :]
1836 }
1937
20- for _ , platform := range strings .Split (platforms , " " ) {
21- mageutil .CompileForPlatform (platform )
38+ mageutil .Build (bin , nil )
39+ }
40+
41+ func BuildWithCustomConfig () {
42+ flag .Parse ()
43+ bin := flag .Args ()
44+ if len (bin ) != 0 {
45+ bin = bin [1 :]
46+ }
47+
48+ config := & mageutil.PathOptions {
49+ RootDir : & customRootDir ,
50+ OutputDir : & customOutputDir ,
51+ SrcDir : & customSrcDir ,
52+ ToolsDir : & customToolsDir ,
2253 }
2354
24- mageutil .PrintGreen ( "All binaries under cmd and tools were successfully compiled." )
55+ mageutil .Build ( bin , config )
2556}
2657
2758func Start () {
@@ -31,7 +62,37 @@ func Start() {
3162 mageutil .PrintRed ("setMaxOpenFiles failed " + err .Error ())
3263 os .Exit (1 )
3364 }
34- mageutil .StartToolsAndServices ()
65+
66+ flag .Parse ()
67+ bin := flag .Args ()
68+ if len (bin ) != 0 {
69+ bin = bin [1 :]
70+ }
71+
72+ mageutil .StartToolsAndServices (bin , nil )
73+ }
74+
75+ func StartWithCustomConfig () {
76+ mageutil .InitForSSC ()
77+ err := setMaxOpenFiles ()
78+ if err != nil {
79+ mageutil .PrintRed ("setMaxOpenFiles failed " + err .Error ())
80+ os .Exit (1 )
81+ }
82+
83+ flag .Parse ()
84+ bin := flag .Args ()
85+ if len (bin ) != 0 {
86+ bin = bin [1 :]
87+ }
88+
89+ config := & mageutil.PathOptions {
90+ RootDir : & customRootDir ,
91+ OutputDir : & customOutputDir ,
92+ ConfigDir : & customConfigDir ,
93+ }
94+
95+ mageutil .StartToolsAndServices (bin , config )
3596}
3697
3798func Stop () {
0 commit comments