|
2 | 2 |
|
3 | 3 | **Function Stream** is a high-performance, event-driven stream processing framework built in Rust. It provides a modular runtime to orchestrate serverless-style processing functions compiled to **WebAssembly (WASM)**, supporting functions written in **Go, Python, and Rust**. |
4 | 4 |
|
5 | | - |
6 | | - |
7 | 5 | ## Key Features |
8 | 6 |
|
9 | 7 | * **Event-Driven WASM Runtime**: Executes polyglot functions (Go, Python, Rust) with near-native performance and sandboxed isolation. |
|
12 | 10 |
|
13 | 11 | ## Repository Layout |
14 | 12 |
|
15 | | -``` |
| 13 | +```text |
16 | 14 | function-stream/ |
17 | | -├── src/ # Core runtime, coordinator, server, config, SQL parser |
18 | | -├── protocol/ # Protocol Buffers definitions and generated gRPC code |
19 | | -├── cli/cli/ # SQL REPL client |
| 15 | +├── src/ # Core runtime, coordinator, server, config |
| 16 | +├── protocol/ # Protocol Buffers definitions |
| 17 | +├── cli/ # SQL REPL client |
20 | 18 | ├── conf/ # Default runtime configuration |
21 | | -├── examples/ # Sample processors and integration examples |
22 | | -├── python/ # Python API, client, and runtime WASM generator |
23 | | -├── Makefile # Build and packaging automation |
| 19 | +├── examples/ # Sample processors |
| 20 | +├── python/ # Python API, Client, and Runtime (WASM) |
| 21 | +├── scripts/ # Build and environment automation scripts |
| 22 | +├── Makefile # Unified build system |
24 | 23 | └── Cargo.toml # Workspace manifest |
25 | 24 | ``` |
26 | 25 |
|
27 | 26 | ## Prerequisites |
28 | 27 |
|
29 | | -- Rust toolchain (recommend `rustup` with stable >= 1.77) |
30 | | -- `protoc` (Protocol Buffers compiler) for generating gRPC bindings |
31 | | -- Build tooling for `rdkafka`: `cmake`, `pkg-config`, and OpenSSL headers |
32 | | -- Optional (for Python processors and full package): |
33 | | - - Python 3.9+ with `venv` |
34 | | - - `componentize-py` (installed via `make install-deps` inside `python/functionstream-runtime`) |
35 | | - |
36 | | -## Build From Source |
37 | | - |
38 | | -Clone the repository and install dependencies: |
| 28 | +* **Rust Toolchain**: Stable >= 1.77 (via rustup). |
| 29 | +* **Python 3.9+**: Required for building the Python WASM runtime. |
| 30 | +* **Protoc**: Protocol Buffers compiler (for generating gRPC bindings). |
| 31 | +* **Build Tools**: cmake, pkg-config, OpenSSL headers (for rdkafka). |
39 | 32 |
|
40 | | -``` |
41 | | -git clone https://github.com/<your-org>/function-stream.git |
42 | | -cd function-stream |
43 | | -cargo fetch |
44 | | -``` |
45 | | - |
46 | | -Build targets: |
| 33 | +## Quick Start (Local Development) |
47 | 34 |
|
48 | | -- Debug build (fast iteration): |
49 | | - ``` |
50 | | - cargo build |
51 | | - ``` |
52 | | -- Release build with Python support (default features): |
53 | | - ``` |
54 | | - cargo build --release |
55 | | - ``` |
56 | | -- Release build without Python (lite): |
57 | | - ``` |
58 | | - cargo build --release --no-default-features --features incremental-cache |
59 | | - ``` |
| 35 | +### 1. Initialize Environment |
60 | 36 |
|
61 | | -To regenerate Protocol Buffers, rerun the build; `tonic-build` automatically recompiles when `protocol/proto/function_stream.proto` changes. |
| 37 | +We provide an automated script to set up the Python virtual environment (`.venv`), install dependencies, and compile necessary sub-modules. |
62 | 38 |
|
63 | | -## Run Locally |
| 39 | +```bash |
| 40 | +make env |
| 41 | +``` |
64 | 42 |
|
65 | | -### Prepare configuration |
| 43 | +This runs `scripts/setup.sh`, creating a `.venv` and installing the API, Client, and Runtime builder tools. |
66 | 44 |
|
67 | | -1. Review `conf/config.yaml` and adjust service host/port, logging, state storage, and Python runtime settings as needed. |
68 | | -2. Optionally point `FUNCTION_STREAM_CONF` to a custom configuration file or directory: |
69 | | - ``` |
70 | | - export FUNCTION_STREAM_CONF=/path/to/config.yaml |
71 | | - ``` |
72 | | -3. Ensure `data/` and `logs/` directories are writable (they are created automatically on startup). |
| 45 | +### 2. Build & Run Server |
73 | 46 |
|
74 | | -### Start the control plane |
| 47 | +Start the control plane in release mode. The build system will automatically compile the Python WASM runtime if it's missing. |
75 | 48 |
|
76 | | -``` |
| 49 | +```bash |
77 | 50 | cargo run --release --bin function-stream |
78 | 51 | ``` |
79 | 52 |
|
80 | | -The server logs appear under `logs/app.log` (default JSON format). Stop the service with `Ctrl+C`. |
| 53 | +Logs are output to `logs/app.log` (JSON format) and stdout. Default configuration is loaded from `conf/config.yaml`. |
81 | 54 |
|
82 | | -### Use the SQL CLI |
| 55 | +### 3. Run CLI |
83 | 56 |
|
84 | | -Run the interactive CLI from another terminal to issue SQL statements: |
| 57 | +In a separate terminal, launch the SQL REPL: |
85 | 58 |
|
| 59 | +```bash |
| 60 | +cargo run -p function-stream-cli -- --host 127.0.0.1 --port 8080 |
86 | 61 | ``` |
87 | | -cargo run -p function-stream-cli -- --ip 127.0.0.1 --port 8080 |
88 | | -``` |
89 | | - |
90 | | -The CLI connects to the gRPC endpoint exposed by the server. |
91 | 62 |
|
92 | | -### Try sample processors |
| 63 | +## Building & Packaging |
93 | 64 |
|
94 | | -- Python processor example: |
95 | | - ``` |
96 | | - cd examples/python-processor |
97 | | - python main.py |
98 | | - ``` |
99 | | -- Kafka integration tests and Go processor examples are under `examples/`. |
| 65 | +The project uses a standard Makefile to handle compilation and distribution. Artifacts are generated in the `dist/` directory. |
100 | 66 |
|
101 | | -## Packaging |
| 67 | +### Build Targets |
102 | 68 |
|
103 | | -Packaging is orchestrated by the top-level `Makefile`. Outputs are placed in `dist/`. |
| 69 | +| Command | Description | |
| 70 | +|----------------|--------------------------------------------------| |
| 71 | +| `make` | Alias for `make build`. Compiles Rust binaries and Python WASM runtime. | |
| 72 | +| `make build` | Builds the Full version (Rust + Python Support). | |
| 73 | +| `make build-lite` | Builds the Lite version (Rust only, no Python dependencies). | |
104 | 74 |
|
105 | | -### Full distribution (includes Python runtime) |
| 75 | +### Distribution (Packaging) |
106 | 76 |
|
107 | | -1. Create the virtual environment once: |
108 | | - ``` |
109 | | - python3 -m venv .venv |
110 | | - source .venv/bin/activate |
111 | | - make -C python/functionstream-runtime install-deps build |
112 | | - deactivate |
113 | | - ``` |
114 | | -2. Build and package: |
115 | | - ``` |
116 | | - make package-full |
117 | | - ``` |
| 77 | +To create production-ready archives (`.tar.gz` and `.zip`), use the dist targets. |
118 | 78 |
|
119 | | -Artifacts: |
120 | | -- `dist/function-stream-<version>/` directory containing binaries, config, logs/data skeletons, README, and Python WASM runtime. |
121 | | -- `dist/packages/function-stream-<version>.zip` and `.tar.gz`. |
| 79 | +#### 1. Function Stream (Full) |
122 | 80 |
|
123 | | -### Lite distribution (Rust-only) |
| 81 | +Includes the Rust binary, Python WASM runtime, configuration, and default directory structure. |
124 | 82 |
|
125 | | -``` |
126 | | -make package-lite |
| 83 | +```bash |
| 84 | +make dist |
127 | 85 | ``` |
128 | 86 |
|
129 | | -Artifacts: |
130 | | -- `dist/function-stream-<version>-lite/` directory with binaries and configs. |
131 | | -- `dist/packages/function-stream-<version>-lite.zip` and `.tar.gz`. |
| 87 | +**Output:** |
| 88 | +* `dist/function-stream-<version>.tar.gz` |
| 89 | +* `dist/function-stream-<version>.zip` |
132 | 90 |
|
133 | | -### Package all variants |
| 91 | +#### 2. Function Stream Lite |
134 | 92 |
|
135 | | -``` |
136 | | -make package-all |
137 | | -``` |
| 93 | +A lightweight distribution without the Python WASM runtime or dependencies. |
138 | 94 |
|
139 | | -The script cleans previous `dist/` contents, produces both full and lite packages, and lists generated archives. |
| 95 | +```bash |
| 96 | +make dist-lite |
| 97 | +``` |
140 | 98 |
|
141 | | -## Testing |
| 99 | +**Output:** |
| 100 | +* `dist/function-stream-<version>-lite.tar.gz` |
| 101 | +* `dist/function-stream-<version>-lite.zip` |
142 | 102 |
|
143 | | -Run the Rust test suite: |
| 103 | +## Maintenance |
144 | 104 |
|
145 | | -``` |
146 | | -cargo test |
147 | | -``` |
| 105 | +| Command | Description | |
| 106 | +|----------------|------------------------------------------------------------------| |
| 107 | +| `make clean` | Deep clean. Removes `target/`, `dist/`, `.venv/`, and all temporary artifacts. | |
| 108 | +| `make env-clean` | Removes only the Python virtual environment and Python artifacts. | |
| 109 | +| `make test` | Runs the Rust test suite. | |
148 | 110 |
|
149 | | -Python components expose their own `Makefile` targets (for example, `make -C python/functionstream-runtime test` if defined). |
| 111 | +## Configuration |
150 | 112 |
|
151 | | -## Environment Variables |
| 113 | +The runtime behavior is controlled by `conf/config.yaml`. You can override the configuration location using environment variables: |
152 | 114 |
|
153 | | -- `FUNCTION_STREAM_HOME`: Overrides the project root for resolving data/log directories. |
154 | | -- `FUNCTION_STREAM_CONF`: Points to a configuration file or directory containing `config.yaml`. |
| 115 | +```bash |
| 116 | +export FUNCTION_STREAM_CONF=/path/to/custom/config.yaml |
| 117 | +``` |
155 | 118 |
|
156 | 119 | ## License |
157 | 120 |
|
158 | | -Licensed under the Apache License, Version 2.0. See `LICENSE` for details. |
| 121 | +Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details. |
0 commit comments