Skip to content

Commit 729e9b3

Browse files
committed
add scripts
1 parent 17b95b8 commit 729e9b3

File tree

3 files changed

+270
-222
lines changed

3 files changed

+270
-222
lines changed

Makefile

Lines changed: 104 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -10,233 +10,115 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
VERSION := $(shell grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d ' ')
14-
ARCH := $(shell uname -m)
15-
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
16-
BUILD_DIR := target/release
17-
DIST_BASE := dist
18-
FULL_DIR := $(DIST_BASE)/function-stream-$(VERSION)
19-
LITE_DIR := $(DIST_BASE)/function-stream-$(VERSION)-lite
20-
PACKAGE_DIR := packages
21-
PYTHON_WASM_PATH := python/functionstream-runtime/target/functionstream-python-runtime.wasm
22-
PYTHON_WASM_NAME := functionstream-python-runtime.wasm
23-
24-
.PHONY: help clean clean-dist build build-full build-lite package package-full package-lite package-all test install
13+
14+
APP_NAME := function-stream
15+
VERSION := $(shell grep '^version' Cargo.toml | head -1 | awk -F '"' '{print $$2}')
16+
ARCH := $(shell uname -m)
17+
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
18+
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
19+
20+
DIST_ROOT := dist
21+
TARGET_DIR := target/release
22+
PYTHON_ROOT := python
23+
WASM_SOURCE := $(PYTHON_ROOT)/functionstream-runtime/target/functionstream-python-runtime.wasm
24+
25+
PYTHON_EXEC := $(if $(wildcard .venv/bin/python),.venv/bin/python,python3)
26+
27+
FULL_NAME := $(APP_NAME)-$(VERSION)
28+
LITE_NAME := $(APP_NAME)-$(VERSION)-lite
29+
FULL_PATH := $(DIST_ROOT)/$(FULL_NAME)
30+
LITE_PATH := $(DIST_ROOT)/$(LITE_NAME)
31+
32+
C_R := \033[0;31m
33+
C_G := \033[0;32m
34+
C_B := \033[0;34m
35+
C_Y := \033[0;33m
36+
C_0 := \033[0m
37+
38+
log = @printf "$(C_B)[-]$(C_0) %-15s %s\n" "$(1)" "$(2)"
39+
success = @printf "$(C_G)[✔]$(C_0) %s\n" "$(1)"
40+
41+
.PHONY: all help build build-lite dist dist-lite clean test env env-clean .check-env .build-wasm
42+
43+
all: build
2544

2645
help:
27-
@echo "Function Stream Build System"
46+
@echo "Usage: make [TARGET]"
2847
@echo ""
29-
@echo "Available targets:"
30-
@echo " build - Build full version (debug)"
31-
@echo " build-full - Build full release version"
32-
@echo " build-lite - Build lite release version (no Python)"
33-
@echo " package-full - Build and package full version (.zip and .tar.gz)"
34-
@echo " package-lite - Build and package lite version (.zip and .tar.gz)"
35-
@echo " package-all - Build and package both versions"
36-
@echo " test - Run tests"
37-
@echo " clean - Clean all (cargo, dist, data, logs, sub-modules)"
38-
@echo " clean-dist - Clean distribution directory only"
48+
@echo " build Build full release (Rust + Python WASM)"
49+
@echo " build-lite Build lightweight release (Rust only)"
50+
@echo " dist Package full build (.tar.gz / .zip)"
51+
@echo " dist-lite Package lite build (.tar.gz / .zip)"
52+
@echo " env Setup Python dev environment (.venv)"
53+
@echo " test Run unit tests"
54+
@echo " clean Cleanup all artifacts"
3955
@echo ""
40-
@echo "Version: $(VERSION)"
41-
@echo "Architecture: $(ARCH)"
42-
@echo "OS: $(OS)"
56+
@echo " Version: $(VERSION) | Arch: $(ARCH) | OS: $(OS)"
57+
58+
build: .check-env .build-wasm
59+
$(call log,BUILD,Rust Full Features)
60+
@cargo build --release --features python --quiet
61+
$(call success,Target: $(TARGET_DIR)/$(APP_NAME))
62+
63+
build-lite: .check-env
64+
$(call log,BUILD,Rust Lite No Python)
65+
@cargo build --release --no-default-features --features incremental-cache --quiet
66+
$(call success,Target: $(TARGET_DIR)/$(APP_NAME))
67+
68+
.build-wasm:
69+
$(call log,WASM,Building Python Runtime using $(PYTHON_EXEC))
70+
@cd $(PYTHON_ROOT)/functionstream-runtime && \
71+
PYTHONPATH=../functionstream-api ../../$(PYTHON_EXEC) build.py > /dev/null
72+
@[ -f "$(WASM_SOURCE)" ] || (printf "$(C_R)[X] WASM Build Failed$(C_0)\n" && exit 1)
73+
74+
dist: build
75+
$(call log,DIST,Layout: $(FULL_PATH))
76+
@rm -rf "$(FULL_PATH)"
77+
@mkdir -p "$(FULL_PATH)/"{bin,conf,logs,data/cache/python-runner}
78+
@cp "$(TARGET_DIR)/$(APP_NAME)" "$(FULL_PATH)/bin/"
79+
@cp "$(WASM_SOURCE)" "$(FULL_PATH)/data/cache/python-runner/"
80+
@cp conf/config.yaml "$(FULL_PATH)/conf/config.yaml" 2>/dev/null || true
81+
@cp LICENSE README.md "$(FULL_PATH)/" 2>/dev/null || true
82+
@printf "Version: $(VERSION)\nBuild: $(ARCH)-$(OS)\nDate: $(DATE)\n" > "$(FULL_PATH)/manifest.txt"
83+
$(call log,ARCHIVE,Compressing to $(DIST_ROOT)/...)
84+
@cd $(DIST_ROOT) && tar -czf "$(FULL_NAME).tar.gz" "$(FULL_NAME)"
85+
@cd $(DIST_ROOT) && zip -rq "$(FULL_NAME).zip" "$(FULL_NAME)"
86+
$(call success,Ready: $(DIST_ROOT)/$(FULL_NAME).tar.gz)
87+
88+
dist-lite: build-lite
89+
$(call log,DIST,Layout: $(LITE_PATH))
90+
@rm -rf "$(LITE_PATH)"
91+
@mkdir -p "$(LITE_PATH)/"{bin,conf,logs,data}
92+
@cp "$(TARGET_DIR)/$(APP_NAME)" "$(LITE_PATH)/bin/"
93+
@cp conf/config.yaml "$(LITE_PATH)/conf/config.yaml" 2>/dev/null || true
94+
@cp LICENSE README.md "$(LITE_PATH)/" 2>/dev/null || true
95+
@printf "Version: $(VERSION) (Lite)\nBuild: $(ARCH)-$(OS)\nDate: $(DATE)\n" > "$(LITE_PATH)/manifest.txt"
96+
$(call log,ARCHIVE,Compressing to $(DIST_ROOT)/...)
97+
@cd $(DIST_ROOT) && tar -czf "$(LITE_NAME).tar.gz" "$(LITE_NAME)"
98+
@cd $(DIST_ROOT) && zip -rq "$(LITE_NAME).zip" "$(LITE_NAME)"
99+
$(call success,Ready: $(DIST_ROOT)/$(LITE_NAME).tar.gz)
43100

44-
# Sub-modules with their own Makefiles
45-
PYTHON_MODULES := python/functionstream-api python/functionstream-client python/functionstream-runtime
101+
test:
102+
$(call log,TEST,Running cargo tests)
103+
@cargo test --quiet
46104

47-
clean:
48-
@echo "Cleaning build artifacts..."
49-
cargo clean
50-
@rm -rf $(DIST_BASE)
51-
@echo "Cleaning data directory..."
52-
@rm -rf data
53-
@echo "Cleaning logs directory..."
54-
@rm -rf logs
55-
@echo "Cleaning sub-modules..."
56-
@for mod in $(PYTHON_MODULES); do \
57-
if [ -f "$$mod/Makefile" ]; then \
58-
echo " Cleaning $$mod..."; \
59-
$(MAKE) -C $$mod clean 2>/dev/null || true; \
60-
fi; \
61-
done
62-
@echo "Clean complete"
63-
64-
clean-dist:
65-
@echo "Cleaning distribution directory..."
66-
@rm -rf $(DIST_BASE)
67-
@echo "Distribution directory cleaned"
68-
69-
build:
70-
cargo build
71-
72-
build-full:
73-
@echo "Building full release version..."
74-
@if [ ! -f $(PYTHON_WASM_PATH) ]; then \
75-
echo "Python WASM file not found. Building it first..."; \
76-
cd python/functionstream-runtime && $(MAKE) build || { \
77-
echo "Error: Failed to build Python WASM file"; \
78-
exit 1; \
79-
}; \
80-
fi
81-
cargo build --release --features python
82-
@echo "Full version build complete"
83-
84-
build-lite:
85-
@echo "Building lite release version (no Python)..."
86-
cargo build --release --no-default-features --features incremental-cache
87-
@echo "Lite version build complete"
88-
89-
prepare-dist-full:
90-
@echo "Preparing full distribution..."
91-
@if [ -d $(FULL_DIR) ]; then \
92-
echo "Removing existing full distribution directory..."; \
93-
rm -rf $(FULL_DIR); \
94-
fi
95-
@mkdir -p $(FULL_DIR)/bin
96-
@mkdir -p $(FULL_DIR)/conf
97-
@mkdir -p $(FULL_DIR)/data/cache/python-runner
98-
@mkdir -p $(FULL_DIR)/logs
99-
@if [ -f $(BUILD_DIR)/function-stream ]; then \
100-
cp $(BUILD_DIR)/function-stream $(FULL_DIR)/bin/ && \
101-
chmod +x $(FULL_DIR)/bin/function-stream && \
102-
echo "Copied function-stream binary"; \
103-
fi
104-
@if [ -f LICENSE ]; then \
105-
cp LICENSE $(FULL_DIR)/ && \
106-
echo "Copied LICENSE file"; \
107-
else \
108-
echo "Warning: LICENSE file not found"; \
109-
fi
110-
@if [ -f README.md ]; then \
111-
cp README.md $(FULL_DIR)/ && \
112-
echo "Copied README.md"; \
113-
fi
114-
@if [ -f $(PYTHON_WASM_PATH) ]; then \
115-
cp $(PYTHON_WASM_PATH) $(FULL_DIR)/data/cache/python-runner/$(PYTHON_WASM_NAME) && \
116-
echo "Copied Python WASM file to data/cache/python-runner/"; \
117-
else \
118-
echo "Warning: Python WASM file not found at $(PYTHON_WASM_PATH)"; \
119-
echo "Warning: Full version requires Python WASM file. Please build it first:"; \
120-
echo " cd python/functionstream-runtime && make build"; \
121-
fi
122-
@if [ -f config.yaml ]; then \
123-
cp config.yaml $(FULL_DIR)/conf/config.yaml && \
124-
cp config.yaml $(FULL_DIR)/conf/config.yaml.template && \
125-
echo "Copied config.yaml and config.yaml.template"; \
126-
else \
127-
echo "Warning: config.yaml not found, creating default..."; \
128-
echo "service:" > $(FULL_DIR)/conf/config.yaml; \
129-
echo " service_id: \"default-service\"" >> $(FULL_DIR)/conf/config.yaml; \
130-
echo " service_name: \"function-stream\"" >> $(FULL_DIR)/conf/config.yaml; \
131-
echo " version: \"$(VERSION)\"" >> $(FULL_DIR)/conf/config.yaml; \
132-
echo " host: \"127.0.0.1\"" >> $(FULL_DIR)/conf/config.yaml; \
133-
echo " port: 8080" >> $(FULL_DIR)/conf/config.yaml; \
134-
echo " debug: false" >> $(FULL_DIR)/conf/config.yaml; \
135-
echo "logging:" >> $(FULL_DIR)/conf/config.yaml; \
136-
echo " level: info" >> $(FULL_DIR)/conf/config.yaml; \
137-
echo " format: json" >> $(FULL_DIR)/conf/config.yaml; \
138-
echo "python:" >> $(FULL_DIR)/conf/config.yaml; \
139-
echo " wasm_path: data/cache/python-runner/$(PYTHON_WASM_NAME)" >> $(FULL_DIR)/conf/config.yaml; \
140-
cp $(FULL_DIR)/conf/config.yaml $(FULL_DIR)/conf/config.yaml.template; \
141-
fi
142-
@echo "FULL VERSION - $(VERSION)" > $(FULL_DIR)/VERSION.txt
143-
@echo "Build date: $$(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> $(FULL_DIR)/VERSION.txt
144-
@echo "Architecture: $(ARCH)" >> $(FULL_DIR)/VERSION.txt
145-
@echo "OS: $(OS)" >> $(FULL_DIR)/VERSION.txt
146-
@if [ -f $(PYTHON_WASM_PATH) ]; then \
147-
echo "Python WASM: Included (data/cache/python-runner/$(PYTHON_WASM_NAME))" >> $(FULL_DIR)/VERSION.txt; \
148-
fi
149-
150-
prepare-dist-lite:
151-
@echo "Preparing lite distribution..."
152-
@if [ -d $(LITE_DIR) ]; then \
153-
echo "Removing existing lite distribution directory..."; \
154-
rm -rf $(LITE_DIR); \
155-
fi
156-
@mkdir -p $(LITE_DIR)/bin
157-
@mkdir -p $(LITE_DIR)/conf
158-
@mkdir -p $(LITE_DIR)/data
159-
@mkdir -p $(LITE_DIR)/logs
160-
@if [ -f $(BUILD_DIR)/function-stream ]; then \
161-
cp $(BUILD_DIR)/function-stream $(LITE_DIR)/bin/ && \
162-
chmod +x $(LITE_DIR)/bin/function-stream && \
163-
echo "Copied function-stream binary"; \
164-
fi
165-
@if [ -f LICENSE ]; then \
166-
cp LICENSE $(LITE_DIR)/ && \
167-
echo "Copied LICENSE file"; \
168-
else \
169-
echo "Warning: LICENSE file not found"; \
170-
fi
171-
@if [ -f README.md ]; then \
172-
cp README.md $(LITE_DIR)/ && \
173-
echo "Copied README.md"; \
174-
fi
175-
@if [ -f config.yaml ]; then \
176-
cp config.yaml $(LITE_DIR)/conf/config.yaml && \
177-
cp config.yaml $(LITE_DIR)/conf/config.yaml.template && \
178-
echo "Copied config.yaml and config.yaml.template"; \
179-
else \
180-
echo "Warning: config.yaml not found, creating default..."; \
181-
echo "service:" > $(LITE_DIR)/conf/config.yaml; \
182-
echo " service_id: \"default-service\"" >> $(LITE_DIR)/conf/config.yaml; \
183-
echo " service_name: \"function-stream\"" >> $(LITE_DIR)/conf/config.yaml; \
184-
echo " version: \"$(VERSION)\"" >> $(LITE_DIR)/conf/config.yaml; \
185-
echo " host: \"127.0.0.1\"" >> $(LITE_DIR)/conf/config.yaml; \
186-
echo " port: 8080" >> $(LITE_DIR)/conf/config.yaml; \
187-
echo " debug: false" >> $(LITE_DIR)/conf/config.yaml; \
188-
echo "logging:" >> $(LITE_DIR)/conf/config.yaml; \
189-
echo " level: info" >> $(LITE_DIR)/conf/config.yaml; \
190-
echo " format: json" >> $(LITE_DIR)/conf/config.yaml; \
191-
cp $(LITE_DIR)/conf/config.yaml $(LITE_DIR)/conf/config.yaml.template; \
192-
fi
193-
@echo "LITE VERSION - $(VERSION)" > $(LITE_DIR)/VERSION.txt
194-
@echo "Build date: $$(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> $(LITE_DIR)/VERSION.txt
195-
@echo "Architecture: $(ARCH)" >> $(LITE_DIR)/VERSION.txt
196-
@echo "OS: $(OS)" >> $(LITE_DIR)/VERSION.txt
197-
@echo "Note: Python processor support is disabled" >> $(LITE_DIR)/VERSION.txt
198-
199-
package-full: build-full prepare-dist-full
200-
@if [ ! -f $(FULL_DIR)/LICENSE ]; then \
201-
echo "Error: LICENSE file is required for distribution but not found"; \
202-
echo "Apache License 2.0 requires LICENSE file to be included in distribution"; \
203-
exit 1; \
204-
fi
205-
@if [ ! -f $(FULL_DIR)/data/cache/python-runner/$(PYTHON_WASM_NAME) ]; then \
206-
echo "Error: Python WASM file is required for full version but not found in distribution"; \
207-
echo "Please ensure Python WASM is built before packaging"; \
208-
exit 1; \
209-
fi
210-
@echo "Packaging full version..."
211-
@mkdir -p $(DIST_BASE)/$(PACKAGE_DIR)
212-
@cd $(DIST_BASE) && \
213-
zip -r $(PACKAGE_DIR)/function-stream-$(VERSION).zip function-stream-$(VERSION) && \
214-
tar -czf $(PACKAGE_DIR)/function-stream-$(VERSION).tar.gz function-stream-$(VERSION)
215-
@echo "Full version packages created:"
216-
@ls -lh $(DIST_BASE)/$(PACKAGE_DIR)/function-stream-$(VERSION).*
217-
218-
package-lite: build-lite prepare-dist-lite
219-
@if [ ! -f $(LITE_DIR)/LICENSE ]; then \
220-
echo "Error: LICENSE file is required for distribution but not found"; \
221-
echo "Apache License 2.0 requires LICENSE file to be included in distribution"; \
222-
exit 1; \
223-
fi
224-
@echo "Packaging lite version..."
225-
@mkdir -p $(DIST_BASE)/$(PACKAGE_DIR)
226-
@cd $(DIST_BASE) && \
227-
zip -r $(PACKAGE_DIR)/function-stream-$(VERSION)-lite.zip function-stream-$(VERSION)-lite && \
228-
tar -czf $(PACKAGE_DIR)/function-stream-$(VERSION)-lite.tar.gz function-stream-$(VERSION)-lite
229-
@echo "Lite version packages created:"
230-
@ls -lh $(DIST_BASE)/$(PACKAGE_DIR)/function-stream-$(VERSION)-lite.*
231-
232-
package-all: clean-dist package-full package-lite
233-
@echo ""
234-
@echo "All packages created:"
235-
@ls -lh $(DIST_BASE)/$(PACKAGE_DIR)/
105+
env:
106+
$(call log,ENV,Initializing Python environment)
107+
@./scripts/setup.sh
108+
$(call success,Environment Ready)
236109

237-
test:
238-
cargo test
110+
env-clean:
111+
$(call log,CLEAN,Python artifacts)
112+
@./scripts/clean.sh
113+
$(call success,Done)
239114

240-
install: build-full prepare-dist-full
241-
@echo "Installation complete"
242-
@echo "Distribution directory: $(FULL_DIR)"
115+
clean:
116+
$(call log,CLEAN,Removing all artifacts)
117+
@cargo clean
118+
@rm -rf $(DIST_ROOT) data logs
119+
@./scripts/clean.sh 2>/dev/null || true
120+
$(call success,Done)
121+
122+
.check-env:
123+
@command -v cargo >/dev/null 2>&1 || { printf "$(C_R)[X] Cargo not found$(C_0)\n"; exit 1; }
124+
@command -v python3 >/dev/null 2>&1 || { printf "$(C_R)[X] Python3 not found$(C_0)\n"; exit 1; }

0 commit comments

Comments
 (0)