-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (123 loc) · 4.7 KB
/
Makefile
File metadata and controls
145 lines (123 loc) · 4.7 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
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --- 1. Configuration & Variables ---
# Shell setup
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
# Directory paths (Absolute paths for safety)
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(dir $(mkfile_path))
# [FIX 1] Define standard roots for Monorepo
# SCRIPT_DIR: Current directory (.../python/functionstream-runtime)
SCRIPT_DIR := $(current_dir)
# PYTHON_ROOT: Parent directory (.../python) - Used to find siblings like 'api'
PYTHON_ROOT := $(abspath $(current_dir)/..)
# MONOREPO_ROOT: Grandparent directory (.../function-stream) - Used to find .venv
MONOREPO_ROOT := $(abspath $(current_dir)/../..)
# Output paths
OUTPUT_DIR := $(SCRIPT_DIR)/target
WASM_OUTPUT := $(OUTPUT_DIR)/functionstream-python-runtime.wasm
# Cache directory for distribution
CACHE_DIR := $(MONOREPO_ROOT)/data/cache/python-runner
# [FIX 2] Virtual Environment (Located at Monorepo Root)
VENV_DIR := $(MONOREPO_ROOT)/.venv
VENV_BIN := $(VENV_DIR)/bin
PYTHON := $(VENV_BIN)/python
PIP := $(VENV_BIN)/pip
COMPONENTIZE := $(VENV_BIN)/componentize-py
# --- 2. Colors & logging ---
ifneq ($(shell test -t 0; echo $$?),0)
color_reset :=
color_green :=
color_blue :=
color_red :=
else
color_reset := $(shell tput sgr0)
color_green := $(shell tput setaf 2)
color_blue := $(shell tput setaf 4)
color_red := $(shell tput setaf 1)
endif
define log_info
@echo "$(color_blue)[INFO]$(color_reset) $1"
endef
define log_success
@echo "$(color_green)[SUCCESS]$(color_reset) $1"
endef
define log_error
@echo "$(color_red)[ERROR]$(color_reset) $1"
endef
# --- 3. Targets ---
.PHONY: all build clean install-deps venv check-env help
# Default target
all: build
# Ensure venv exists (Delegate to root venv creation if needed, or just warn)
$(PYTHON):
$(call log_info, Virtual environment not found at $(VENV_DIR))
$(call log_info, Please run 'python3 -m venv .venv' in the root 'function-stream' directory first.)
@exit 1
venv: $(PYTHON)
# Install dependencies
install-deps: venv
$(call log_info, Installing build dependencies...)
@$(PIP) install componentize-py
@# [FIX 3] Use PYTHON_ROOT to find the sibling 'functionstream-api' and 'functionstream-api-advanced'
@$(PIP) install -e $(PYTHON_ROOT)/functionstream-api
@$(PIP) install -e $(PYTHON_ROOT)/functionstream-api-advanced
@$(call log_success, Dependencies installed.)
# Build the wasm component
build: venv
@# Check if componentize-py is installed
@if [ ! -f "$(COMPONENTIZE)" ]; then \
echo "$(color_red)[ERROR]$(color_reset) componentize-py not found. Run 'make install-deps' first."; \
exit 1; \
fi
$(call log_info, Building WASM component...)
@mkdir -p $(OUTPUT_DIR)
@# [FIX 4] PYTHONPATH points to the sibling API correctly
@PYTHONPATH=$(PYTHON_ROOT)/functionstream-api $(PYTHON) $(SCRIPT_DIR)/build.py
@if [ -f "$(WASM_OUTPUT)" ]; then \
echo "$(color_green)[SUCCESS]$(color_reset) Build complete: $(WASM_OUTPUT)"; \
ls -lh $(WASM_OUTPUT); \
mkdir -p $(CACHE_DIR); \
cp $(WASM_OUTPUT) $(CACHE_DIR)/; \
echo "$(color_green)[SUCCESS]$(color_reset) Copied to: $(CACHE_DIR)/functionstream-python-runtime.wasm"; \
else \
echo "$(color_red)[ERROR]$(color_reset) Build failed: Output file missing"; \
exit 1; \
fi
# Clean artifacts
clean:
$(call log_info, Cleaning artifacts...)
@rm -rf $(OUTPUT_DIR)
@rm -rf $(SCRIPT_DIR)/bindings
@rm -rf $(SCRIPT_DIR)/dependencies
@find $(SCRIPT_DIR) -type d -name "__pycache__" -exec rm -rf {} +
@find $(SCRIPT_DIR) -type d -name "*.egg-info" -exec rm -rf {} +
@find $(SCRIPT_DIR) -type d -name ".pytest_cache" -exec rm -rf {} +
$(call log_success, Clean completed.)
# Self-documenting help command
help:
@echo "$(color_blue)Function Stream Runtime Build System$(color_reset)"
@echo ""
@echo "Usage:"
@echo " make $(color_green)target$(color_reset)"
@echo ""
@echo "Targets:"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf " $(color_green)%-20s$(color_reset) %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)