~starkingdoms/starkingdoms

ref: 27a49e01148b9ee1a42b66cb18e5bc5a9a3e4509 starkingdoms/spacetime -rwxr-xr-x 5.9 KiB
27a49e01 — c0repwn3r rerun if build_num changed 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash

set -e

SCRIPT_PATH=$(readlink -f "${BASH_SOURCE:-$0}")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
SERVER_MODS=${STK_SERVER_MODULES:=""}

exec_spacetime() {
  # args: target, environment, build root, modules
  echo "[*] Running configure command: 'python3 $SCRIPT_DIR/spacetime_py/spacetime.py $1 $2 $SCRIPT_DIR $SPACETIME_VERBOSE'"
  python3 "$SCRIPT_DIR/spacetime_py/spacetime.py" "$1" "$2" "$SCRIPT_DIR" "$SPACETIME_VERBOSE" "$4"
}

exec_ninja() {
  # args: target
  echo "[*] Running build command: 'ninja -C $SCRIPT_DIR $1'"
  ninja -C "$SCRIPT_DIR" "$1"
}

sub_help() {
  echo "Spacetime - StarKingdoms build utility"
  echo "Spacetime is a small utility program to generate Ninja build manifests for compiling StarKingdoms."
  echo "Available targets:"
  echo "    help - Show this help screen" # done
  echo "    run_http - Compile the client and run a development http server for testing it" # done
  echo "    run_server (default) - Compile and run the game server" # done
  echo "    build_server - Compile the game server" # done
  echo "    run_server_prod - Compile and run the game server with optimizations enabled" # done
  echo "    build_server_prod - Compile the game server with optimizations enabled" # done
  echo "    run_api - Compile and run the API server" # done
  echo "    build_api - Compile the API server" # done
  echo "    run_api_prod - Compile and run the API server with optimizations enabled" # done
  echo "    build_api_prod - Compile the API server with optimizations enabled" # done
  echo "    install_tooling - Install the compilation utilities required for compiling StarKingdoms" # done
  echo "    build_assets - Compile spritesheets in all three texture sizes for textures-fast" # done
  echo "    build_assets_full - Compile spritesheets in full size for textures-fast" # done
  echo "    build_assets_375 - Commpile 37.5% spritesheets for textures-fast" # done
  echo "    build_assets_125 - Compile 12.5% spritesheets for textures-fast" # done
  echo "    clean - Remove all generated files" # done
  echo "    build_docker_api - Build the API dockerfile" # done
  echo "    build_docker_server - Build the server dockerfile" # done
}

check_install_cargo() {
  echo "[*] Checking for $1"
  if ! command -v "$1" &> /dev/null
  then
    echo "[+] $1 was not found, installing via Cargo..."
    cargo install "$2" $3
  fi
}

check() {
  echo "[*] Checking for $1"
  if ! command -v "$1" &> /dev/null
  then
    echo "[x] $1 was not found but is required for the build process to continue. Install it with your system package manager, or, if supported, 'st install_tooling'"
    exit 1
  fi
}

check_all() {
  check inkscape
  check protoc
  check atlasify
}

sub_build_docker_api() {
  cargo build --release --bin starkingdoms-api
  docker buildx build -f api.Dockerfile -t registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:api-$(git rev-parse --short HEAD) .
  docker buildx build -f api.Dockerfile -t registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:api-bleeding .
  docker push registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:api-$(git rev-parse --short HEAD)
  docker push registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:api-bleeding
}

sub_build_docker_server() {
  cargo build --release --bin starkingdoms-server
  docker buildx build -f server.Dockerfile -t registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:server-$(git rev-parse --short HEAD) .
  docker buildx build -f server.Dockerfile -t registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:server-bleeding .
  docker push registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:server-$(git rev-parse --short HEAD)
  docker push registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:server-bleeding
}

sub_clean() {
  rm -rf web/dist
  rm -rf assets/dist
  rm -rf assets/final
  rm -rf target
  rm -rf client/pkg
}

sub_install_tooling() {
  check inkscape
  check protoc
  check atlasify
  echo "[*] All required tools are installed"
}

sub_run_http() {
  check_all
  exec_spacetime client prod "$SCRIPT_DIR" "$CLIENT_MODS"
  exec_ninja asset
  cd client && yarn && yarn run dev
}

sub_build_server() {
  check_all
  exec_spacetime server dev "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja server
}
sub_run_server() {
  check_all
  exec_spacetime server dev "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja server
  exec "$SCRIPT_DIR/target/debug/starkingdoms-server"
}

sub_build_server_prod() {
  check_all
  exec_spacetime server prod "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja server
}
sub_run_server_prod() {
  check_all
  exec_spacetime server prod "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja server
  exec "$SCRIPT_DIR/target/release/starkingdoms-server"
}

sub_build_api() {
  check_all
  exec_spacetime api dev "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja api
}
sub_run_api() {
  check_all
  exec_spacetime api dev "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja api
  cd api && exec "$SCRIPT_DIR/target/debug/starkingdoms-api"
}

sub_build_api_prod() {
  check_all
  exec_spacetime api prod "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja api
}
sub_run_api_prod() {
  check_all
  exec_spacetime api prod "$SCRIPT_DIR" "$SERVER_MODS"
  exec_ninja api
  cd api && exec "$SCRIPT_DIR/target/release/starkingdoms-api"
}

sub_build_assets() {
  check_all
  exec_spacetime asset dev "$SCRIPT_DIR"
  exec_ninja asset
}

sub_build_assets_full() {
  check_all
  exec_spacetime asset dev "$SCRIPT_DIR"
  exec_ninja asset-full
}

sub_build_assets_375() {
  check_all
  exec_spacetime asset dev "$SCRIPT_DIR"
  exec_ninja asset-375
}

sub_build_assets_125() {
  check_all
  exec_spacetime asset dev "$SCRIPT_DIR"
  exec_ninja asset-125
}

subcommand=$1
case $subcommand in
    "" | "-h" | "--help" | "help")
        sub_help
        ;;
    *)
        echo "[*] Running build command $subcommand"
        shift
        sub_${subcommand} $@
        if [ $? = 127 ]; then
            echo "Error: '$subcommand' is not a known subcommand." >&2
            echo "       Run 'st --help' for a list of known subcommands." >&2
            exit 1
        fi
        ;;
esac