-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·145 lines (117 loc) · 3.78 KB
/
build
File metadata and controls
executable file
·145 lines (117 loc) · 3.78 KB
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
#!/usr/bin/env bash
set -Eeuo pipefail
# ==============================
# CONFIG
# ==============================
APP_NAME="flutter-tool"
OUTPUT_DIR="./bin"
TARGET_OS="linux"
TARGET_ARCH="arm64"
# ==============================
# COLORS
# ==============================
BLUE="\033[1;34m"
GREEN="\033[1;32m"
RED="\033[1;31m"
YELLOW="\033[1;33m"
NC="\033[0m"
BOLD="\033[1m"
echo -e "${BLUE}${BOLD}🚀 Flutter Tool ARM Production Builder${NC}"
echo "----------------------------------------"
# ==============================
# CHECK GO INSTALL
# ==============================
if ! command -v go &>/dev/null; then
echo -e "${RED}❌ Go is not installed.${NC}"
exit 1
fi
# ==============================
# CLEAN
# ==============================
clean_module() {
echo -e "${YELLOW}${BOLD}🧹 Cleaning previous build artifacts...${NC}"
# Remove any existing binaries inside OUTPUT_DIR if it exists
if [ -d "$OUTPUT_DIR" ]; then
BIN_COUNT=$(find "$OUTPUT_DIR" -maxdepth 1 -type f | wc -l)
if [ "$BIN_COUNT" -gt 0 ]; then
echo -e "${YELLOW}⚠ Removing $BIN_COUNT existing file(s) in $OUTPUT_DIR/${NC}"
find "$OUTPUT_DIR" -maxdepth 1 -type f -delete
echo -e "${GREEN}✔ $OUTPUT_DIR/ cleared${NC}"
else
echo -e "${GREEN}✔ $OUTPUT_DIR/ already empty${NC}"
fi
fi
# Clean Go build cache
go clean -cache -modcache -testcache
echo -e "${GREEN}✔ Go cache cleared${NC}"
# Remove go.mod and go.sum for a truly fresh init
for f in go.mod go.sum; do
if [ -f "$f" ]; then
rm -f "$f"
echo -e "${GREEN}✔ Removed $f${NC}"
fi
done
echo "----------------------------------------"
}
# ==============================
# INIT MODULE + DEP
# ==============================
init_module() {
echo -e "${BLUE}${BOLD}📦 Initialising Go module...${NC}"
go mod init flutter-tool
echo -e "${GREEN}✔ go.mod created${NC}"
echo -e "${BLUE}📥 Installing dependencies...${NC}"
go mod tidy
}
# ==============================
# BUILD
# ==============================
build_binary() {
mkdir -p "$OUTPUT_DIR"
OUTPUT_PATH="${OUTPUT_DIR}/${APP_NAME}"
echo -e "\n${BLUE}${BOLD}🔨 Building ${TARGET_OS}/${TARGET_ARCH}...${NC}"
CGO_ENABLED=0 GOOS="$TARGET_OS" GOARCH="$TARGET_ARCH" \
go build -ldflags="-s -w" -o "$OUTPUT_PATH" .
if [ -f "$OUTPUT_PATH" ]; then
echo -e "\n${GREEN}${BOLD}✅ BUILD SUCCESS${NC}"
echo "----------------------------------------"
ls -lh "$OUTPUT_PATH"
echo "----------------------------------------"
echo -e "🧪 Test on ARM:"
echo -e " ${OUTPUT_PATH} --version"
else
echo -e "${RED}❌ Build failed${NC}"
exit 1
fi
}
# ==============================
# INSTALL
# ==============================
install_global() {
CURRENT_OS="$(uname -s)"
if [[ "$CURRENT_OS" != MINGW* && \
"$CURRENT_OS" != MSYS* && \
"$CURRENT_OS" != CYGWIN* ]]; then
echo -e "\n${YELLOW}📦 Install globally? (y/n)${NC}"
read -r choice
if [[ "$choice" == "y" ]]; then
TARGET_PATH="/usr/local/bin/${APP_NAME}"
# Remove old global binary if exists
if [ -f "$TARGET_PATH" ]; then
echo -e "${YELLOW}⚠ Removing old installed binary: $TARGET_PATH${NC}"
sudo rm -f "$TARGET_PATH"
fi
sudo cp "${OUTPUT_DIR}/${APP_NAME}" "$TARGET_PATH"
sudo chmod +x "$TARGET_PATH"
echo -e "${GREEN}✔ Installed to $TARGET_PATH${NC}"
fi
fi
}
# ==============================
# MAIN
# ==============================
clean_module
init_module
build_binary
install_global
echo -e "\n${GREEN}${BOLD}🎉 ARM Build Ready & Clean.${NC}"