Repository navigation
Expand file tree
/
Copy pathmakefile
More file actions
174 lines (155 loc) · 5.67 KB
/
Copy pathmakefile
File metadata and controls
174 lines (155 loc) · 5.67 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
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
.PHONY: build generate-types test clean copy-wasm-exec build-optimized build-tinygo
# Default target
all: build
# Generate TypeScript type definitions
generate-types:
@echo "Generating TypeScript definitions..."
@mkdir -p build
@go run tools/type-generator.go > ./build/wasm.d.ts
# Copy wasm_exec.js from Go installation
copy-wasm-exec:
@echo "Copying wasm_exec.js..."
@cp "$$(go env GOROOT)/misc/wasm/wasm_exec.js" ./src/wasm_exec.js
# Build WASM binary (standard)
build-wasm:
@echo "Building WASM binary (standard)..."
@mkdir -p build
@GOOS=js GOARCH=wasm go build -o ./build/color-assembly.wasm
# Build WASM binary (optimized with ldflags)
build-optimized:
@echo "Building WASM binary (optimized)..."
@mkdir -p build
@GOOS=js GOARCH=wasm go build -ldflags="-s -w" -o ./build/color-assembly.wasm
@echo "Optimized build complete!"
@ls -lh ./build/color-assembly.wasm
# Build WASM binary with TinyGo (smallest size)
build-tinygo:
@echo "Building WASM binary with TinyGo..."
@mkdir -p build
@command -v tinygo >/dev/null 2>&1 || { echo "TinyGo not installed. Install from https://tinygo.org/getting-started/install/"; exit 1; }
@tinygo build -o ./build/color-assembly.wasm -target wasm -no-debug -opt=2 .
@echo "TinyGo build complete!"
@ls -lh ./build/color-assembly.wasm
# Full build: generate types, build WASM, prepare dist
build: generate-types build-optimized
@echo "Preparing distribution..."
@mkdir -p dist
@cp build/color-assembly.wasm dist/
@cp build/wasm.d.ts dist/wasm.d.ts
@cp src/wasm_exec.js dist/
@echo "Build complete!"
@echo ""
@echo "Binary sizes:"
@ls -lh dist/color-assembly.wasm
@echo -n "Gzipped: " && gzip -c dist/color-assembly.wasm | wc -c | awk '{printf "%.0fKB\n", $$1/1024}'
# Build with TinyGo for production (smallest size)
build-prod: generate-types build-tinygo
@echo "Preparing production distribution..."
@mkdir -p dist
@cp build/color-assembly.wasm dist/
@cp build/wasm.d.ts dist/wasm.d.ts
@# TinyGo uses different wasm_exec.js
@command -v tinygo >/dev/null 2>&1 && cp "$$(tinygo env TINYGOROOT)/targets/wasm_exec.js" ./dist/wasm_exec.js || cp src/wasm_exec.js dist/
@echo "Production build complete!"
@echo ""
@echo "Binary sizes:"
@ls -lh dist/color-assembly.wasm
@echo -n "Gzipped: " && gzip -c dist/color-assembly.wasm | wc -c | awk '{printf "%.0fKB\n", $$1/1024}'
# Run Go tests with WASM target
test:
@echo "Running tests..."
@GOOS=js GOARCH=wasm go test ./tests/... -exec="$$(go env GOROOT)/misc/wasm/go_js_wasm_exec" -v
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
@GOOS=js GOARCH=wasm go test ./tests/... -exec="$$(go env GOROOT)/misc/wasm/go_js_wasm_exec" -v -coverprofile=coverage.out
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Compile tests to check for errors
test-compile:
@echo "Compiling tests..."
@GOOS=js GOARCH=wasm go test -c ./tests/... -o /dev/null 2>/dev/null || GOOS=js GOARCH=wasm go build ./tests/...
@echo "Tests compile successfully!"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf build/
@rm -rf dist/
@rm -f coverage.out coverage.html
@echo "Clean complete!"
# Development mode - quick rebuild
dev: build-wasm
@echo "Quick build complete!"
# Lint Go code
lint:
@echo "Linting Go code..."
@go vet ./...
@echo "Lint complete!"
# Format Go code
fmt:
@echo "Formatting Go code..."
@go fmt ./...
@echo "Format complete!"
# Check dependencies
deps:
@echo "Checking dependencies..."
@go mod tidy
@go mod verify
@echo "Dependencies OK!"
# Full CI/CD pipeline
ci: lint test-compile build
@echo "CI pipeline complete!"
# Size comparison between build methods
size-compare:
@echo "Comparing build sizes..."
@echo ""
@echo "Standard build:"
@GOOS=js GOARCH=wasm go build -o ./build/standard.wasm
@ls -lh ./build/standard.wasm
@echo -n "Gzipped: " && gzip -c ./build/standard.wasm | wc -c | awk '{printf "%.0fKB\n", $$1/1024}'
@echo ""
@echo "Optimized build (-ldflags=\"-s -w\"):"
@GOOS=js GOARCH=wasm go build -ldflags="-s -w" -o ./build/optimized.wasm
@ls -lh ./build/optimized.wasm
@echo -n "Gzipped: " && gzip -c ./build/optimized.wasm | wc -c | awk '{printf "%.0fKB\n", $$1/1024}'
@echo ""
@if command -v tinygo >/dev/null 2>&1; then \
echo "TinyGo build:"; \
tinygo build -o ./build/tinygo.wasm -target wasm -no-debug -opt=2 .; \
ls -lh ./build/tinygo.wasm; \
echo -n "Gzipped: " && gzip -c ./build/tinygo.wasm | wc -c | awk '{printf "%.0fKB\n", $$1/1024}'; \
else \
echo "TinyGo not installed - skipping"; \
fi
@rm -f ./build/standard.wasm ./build/optimized.wasm ./build/tinygo.wasm
# Help
help:
@echo "ColorAssembly Build System"
@echo ""
@echo "Build targets:"
@echo " build - Full build with optimized WASM"
@echo " build-wasm - Build WASM binary (standard)"
@echo " build-optimized - Build WASM with size optimizations"
@echo " build-tinygo - Build WASM with TinyGo (smallest)"
@echo " build-prod - Production build with TinyGo"
@echo " size-compare - Compare sizes of different builds"
@echo ""
@echo "Development:"
@echo " dev - Quick development build"
@echo " generate-types - Generate TypeScript definitions"
@echo " copy-wasm-exec - Copy wasm_exec.js from Go"
@echo ""
@echo "Testing:"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " test-compile - Verify tests compile"
@echo ""
@echo "Quality:"
@echo " lint - Lint Go code"
@echo " fmt - Format Go code"
@echo " deps - Check dependencies"
@echo " ci - Run full CI pipeline"
@echo ""
@echo "Cleanup:"
@echo " clean - Remove build artifacts"
@echo " help - Show this help"