Skip to content

Commit 03d9ef2

Browse files
committed
Initial commit
0 parents  commit 03d9ef2

File tree

8 files changed

+278744
-0
lines changed

8 files changed

+278744
-0
lines changed

.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Build artifacts
2+
build/
3+
dist/
4+
.build
5+
*.a
6+
*.sqlite
7+
target/
8+
9+
# Rust
10+
Cargo.lock
11+
**/*.rs.bk
12+
*.pdb
13+
14+
# iOS/macOS
15+
*.xcworkspacedata
16+
*.xcuserstate
17+
*.xcbkptlist
18+
*.plist
19+
20+
# Android
21+
.gradle/
22+
*.aar
23+
local.properties
24+
jniLibs/
25+
*.apk
26+
*.ap_
27+
*.dex
28+
29+
# Node.js
30+
node_modules/
31+
package-lock.json
32+
*.tsbuildinfo
33+
coverage/
34+
*.log
35+
npm-debug.log*
36+
yarn-debug.log*
37+
yarn-error.log*
38+
packages/node/platform-packages/
39+
packages/node/test-artifacts/
40+
packages/node/test-output/
41+
packages/node/test-platform-packages/
42+
43+
# IDE
44+
.vscode
45+
.idea/
46+
*.iml
47+
*.swp
48+
*.swo
49+
50+
# System
51+
.DS_Store
52+
Thumbs.db
53+
*.db

LICENSE

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Elastic License 2.0 (modified for open-source use)
2+
3+
Copyright © 2025 SQLite Cloud, Inc.
4+
5+
This software is licensed under the Elastic License 2.0, with the additional grant described below.
6+
7+
You may not use this file except in compliance with the Elastic License 2.0 and the conditions outlined here.
8+
9+
You may obtain a copy of the Elastic License 2.0 at:
10+
11+
```
12+
https://www.elastic.co/licensing/elastic-license
13+
```
14+
15+
Software distributed under the Elastic License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
18+
See the Elastic License 2.0 for the specific language governing permissions and limitations under the license.
19+
20+
---
21+
22+
## Additional Grant for Open-Source Projects
23+
24+
In addition to the permissions granted under the Elastic License 2.0:
25+
26+
* **Free Use in Open-Source Projects**:
27+
You may use, copy, distribute, and prepare derivative works of the software — in source or object form, with or without modification — freely and without fee, provided the software is incorporated into or used by an **open-source project** licensed under an OSI-approved open-source license.
28+
29+
---
30+
31+
## Conditions
32+
33+
1. For **open-source projects**, the software may be used, copied, modified, and distributed without restriction or fee.
34+
35+
2. For **non–open-source or commercial production use**, you may use, copy, distribute, and prepare derivative works of the software only with a commercial license from SQLite Cloud, Inc.
36+
37+
3. You may not provide the software to third parties as a managed service, such as a hosted or cloud-based service, unless you have a license for that use.
38+
39+
4. The software may not be used to circumvent the license grant limitations.
40+
41+
5. Any permitted use is subject to compliance with the Elastic License 2.0, this additional grant, and applicable law.

Makefile

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Makefile for SQLite Agent Extension
2+
# Supports compilation for Linux, macOS, Windows, Android and iOS
3+
4+
# Customize sqlite3 executable with
5+
# make test SQLITE3=/opt/homebrew/Cellar/sqlite/3.49.1/bin/sqlite3
6+
SQLITE3 ?= sqlite3
7+
8+
# Set default platform if not specified
9+
ifeq ($(OS),Windows_NT)
10+
PLATFORM := windows
11+
HOST := windows
12+
CPUS := $(shell powershell -Command "[Environment]::ProcessorCount")
13+
else
14+
HOST = $(shell uname -s | tr '[:upper:]' '[:lower:]')
15+
ifeq ($(HOST),darwin)
16+
PLATFORM := macos
17+
CPUS := $(shell sysctl -n hw.ncpu)
18+
else
19+
PLATFORM := $(HOST)
20+
CPUS := $(shell nproc)
21+
endif
22+
endif
23+
24+
# Speed up builds by using all available CPU cores
25+
MAKEFLAGS += -j$(CPUS)
26+
27+
# Compiler and flags
28+
CC = gcc
29+
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(LIBS_DIR)
30+
31+
# Directories
32+
SRC_DIR = src
33+
DIST_DIR = dist
34+
BUILD_DIR = build
35+
LIBS_DIR = libs
36+
VPATH = $(SRC_DIR)
37+
38+
# Files
39+
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
40+
OBJ_FILES = $(patsubst %.c, $(BUILD_DIR)/%.o, $(notdir $(SRC_FILES)))
41+
42+
# Platform-specific settings
43+
ifeq ($(PLATFORM),windows)
44+
TARGET := $(DIST_DIR)/agent.dll
45+
LDFLAGS += -shared
46+
DEF_FILE := $(BUILD_DIR)/agent.def
47+
STRIP = strip --strip-unneeded $@
48+
else ifeq ($(PLATFORM),macos)
49+
TARGET := $(DIST_DIR)/agent.dylib
50+
MACOS_MIN_VERSION = 11.0
51+
ifndef ARCH
52+
LDFLAGS += -arch x86_64 -arch arm64
53+
CFLAGS += -arch x86_64 -arch arm64
54+
else
55+
LDFLAGS += -arch $(ARCH)
56+
CFLAGS += -arch $(ARCH)
57+
endif
58+
LDFLAGS += -dynamiclib -undefined dynamic_lookup -headerpad_max_install_names -mmacosx-version-min=$(MACOS_MIN_VERSION)
59+
CFLAGS += -mmacosx-version-min=$(MACOS_MIN_VERSION)
60+
STRIP = strip -x -S $@
61+
else ifeq ($(PLATFORM),android)
62+
ifndef ARCH
63+
$(error "Android ARCH must be set to ARCH=x86_64 or ARCH=arm64-v8a")
64+
endif
65+
ifndef ANDROID_NDK
66+
$(error "Android NDK must be set")
67+
endif
68+
BIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/$(HOST)-x86_64/bin
69+
ifneq (,$(filter $(ARCH),arm64 arm64-v8a))
70+
override ARCH := aarch64
71+
endif
72+
CC = $(BIN)/$(ARCH)-linux-android26-clang
73+
TARGET := $(DIST_DIR)/agent.so
74+
LDFLAGS += -shared
75+
STRIP = $(BIN)/llvm-strip --strip-unneeded $@
76+
else ifeq ($(PLATFORM),ios)
77+
TARGET := $(DIST_DIR)/agent.dylib
78+
SDK := -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=11.0
79+
LDFLAGS += -dynamiclib $(SDK) -headerpad_max_install_names
80+
CFLAGS += -arch arm64 $(SDK)
81+
STRIP = strip -x -S $@
82+
else ifeq ($(PLATFORM),ios-sim)
83+
TARGET := $(DIST_DIR)/agent.dylib
84+
SDK := -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) -miphonesimulator-version-min=11.0
85+
LDFLAGS += -arch x86_64 -arch arm64 -dynamiclib $(SDK) -headerpad_max_install_names
86+
CFLAGS += -arch x86_64 -arch arm64 $(SDK)
87+
STRIP = strip -x -S $@
88+
else # linux
89+
TARGET := $(DIST_DIR)/agent.so
90+
LDFLAGS += -shared
91+
CFLAGS += -fPIC
92+
STRIP = strip --strip-unneeded $@
93+
endif
94+
95+
# Windows .def file generation
96+
$(DEF_FILE):
97+
ifeq ($(PLATFORM),windows)
98+
@echo "LIBRARY agent.dll" > $@
99+
@echo "EXPORTS" >> $@
100+
@echo " sqlite3_agent_init" >> $@
101+
endif
102+
103+
$(shell mkdir -p $(BUILD_DIR) $(DIST_DIR))
104+
105+
all: extension
106+
107+
$(BUILD_DIR)/%.o: %.c
108+
$(CC) $(CFLAGS) -O3 -fPIC -c $< -o $@
109+
110+
$(TARGET): $(OBJ_FILES) $(DEF_FILE)
111+
$(CC) $(CFLAGS) $(SRC_DIR)/sqlite-agent.c $(LDFLAGS) -o $@
112+
$(STRIP)
113+
114+
extension: $(TARGET)
115+
116+
test: extension
117+
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./dist/agent" "SELECT agent_version();"
118+
119+
# Build and run Playwright MCP test
120+
playwright: extension
121+
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
122+
-I$(LIBS_DIR) -c $(LIBS_DIR)/sqlite3.c -o $(BUILD_DIR)/sqlite3.o 2>/dev/null || true
123+
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
124+
-I$(LIBS_DIR) test/playwright.c $(BUILD_DIR)/sqlite3.o -o $(BUILD_DIR)/test-playwright
125+
@echo "Note: Make sure Playwright MCP server is running on localhost:8931"
126+
@echo " Start with: npx @playwright/mcp@latest --port 8931 --headless"
127+
@echo ""
128+
$(BUILD_DIR)/test-playwright
129+
130+
# Build and run Airbnb MCP test
131+
airbnb: extension
132+
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
133+
-I$(LIBS_DIR) -c $(LIBS_DIR)/sqlite3.c -o $(BUILD_DIR)/sqlite3.o 2>/dev/null || true
134+
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
135+
-I$(LIBS_DIR) test/airbnb.c $(BUILD_DIR)/sqlite3.o -o $(BUILD_DIR)/test-airbnb
136+
@echo "Note: Make sure Airbnb MCP server is running on localhost:8000/mcp"
137+
@echo ""
138+
$(BUILD_DIR)/test-airbnb
139+
140+
# Build and run GitHub MCP test
141+
github: extension
142+
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
143+
-I$(LIBS_DIR) -c $(LIBS_DIR)/sqlite3.c -o $(BUILD_DIR)/sqlite3.o 2>/dev/null || true
144+
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
145+
-I$(LIBS_DIR) test/github.c $(BUILD_DIR)/sqlite3.o -o $(BUILD_DIR)/test-github
146+
@echo "Note: Set GITHUB_TOKEN environment variable with your GitHub Personal Access Token and make sure GitHub MCP server is running"
147+
@echo " export GITHUB_TOKEN=\"ghp_your_token_here\""
148+
@echo ""
149+
$(BUILD_DIR)/test-github
150+
151+
clean:
152+
rm -rf $(BUILD_DIR) $(DIST_DIR)
153+
154+
# Extract version from header
155+
version:
156+
@echo $(shell sed -n 's/^#define SQLITE_AGENT_VERSION[[:space:]]*"\([^"]*\)".*/\1/p' $(SRC_DIR)/sqlite-agent.h)
157+
158+
# Help target
159+
help:
160+
@echo "SQLite Agent Extension Makefile"
161+
@echo ""
162+
@echo "Usage: make [PLATFORM=platform] [ARCH=arch] [target]"
163+
@echo ""
164+
@echo "Targets:"
165+
@echo " all - Build the extension (default)"
166+
@echo " extension - Build the SQLite extension"
167+
@echo " test - Run quick CLI test"
168+
@echo " playwright - Build and run Playwright test"
169+
@echo " airbnb - Build and run Airbnb test"
170+
@echo " github - Build and run GitHub test"
171+
@echo " clean - Remove all build artifacts"
172+
@echo " version - Display extension version"
173+
@echo " help - Display this help message"
174+
@echo ""
175+
@echo "Platforms:"
176+
@echo " macos - macOS (default on Darwin)"
177+
@echo " linux - Linux (default on Linux)"
178+
@echo " windows - Windows (default on Windows)"
179+
@echo " android - Android (requires ARCH and ANDROID_NDK)"
180+
@echo " ios - iOS device"
181+
@echo " ios-sim - iOS simulator"
182+
@echo ""
183+
@echo "Examples:"
184+
@echo " make # Build for current platform"
185+
@echo " make test # Build and test"
186+
@echo " make PLATFORM=android ARCH=arm64-v8a # Build for Android ARM64"
187+
188+
.PHONY: all extension test playwright airbnb github clean version help

0 commit comments

Comments
 (0)