-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (127 loc) · 6.91 KB
/
Makefile
File metadata and controls
159 lines (127 loc) · 6.91 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
.PHONY: all lingua-wasm typescript-types typescript python test test-payloads capture capture-transforms update-snapshots clean help generate-types generate-all-providers install-hooks install-wasm-tools setup precommit fuzz-snapshots fuzz-snapshots-prune typed-boundary-check typed-boundary-check-branch
all: typescript python ## Build all bindings
help: ## Show this help message
@echo "Lingua Build Targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
generate-provider-types: ## Regenerate provider types from OpenAPI specs (usage: make generate-provider-types PROVIDER=openai)
@if [ -z "$(PROVIDER)" ]; then \
echo "Usage: make generate-provider-types PROVIDER=<provider>"; \
echo "Available providers: openai, anthropic, google, all"; \
echo "Example: make generate-provider-types PROVIDER=openai"; \
exit 1; \
fi
@echo "Regenerating $(PROVIDER) types from OpenAPI spec..."
@cargo run --bin generate-types -- $(PROVIDER)
generate-all-providers: ## Regenerate types for all providers (anthropic, openai, google)
@echo "Regenerating all provider types..."
./pipelines/generate-provider-types.sh anthropic
./pipelines/generate-provider-types.sh openai
./pipelines/generate-provider-types.sh google
generate-types: ## Generate TypeScript types from Rust (via ts-rs)
@echo "Generating TypeScript types from Rust..."
@cargo test export_bindings --lib --quiet
lingua-wasm: ## Build WASM package
@echo "Building WASM package..."
cd bindings/lingua-wasm && pnpm run build
typescript-types: generate-types ## Build TypeScript types-only package
@echo "Building TypeScript types-only package..."
cd bindings/typescript-types && pnpm install --frozen-lockfile && pnpm run build
typescript: generate-types typescript-types lingua-wasm ## Build TypeScript bindings (WASM)
@echo "Building TypeScript bindings..."
cd bindings/typescript && pnpm install --frozen-lockfile && pnpm run build
python: ## Build Python bindings (PyO3)
@echo "Building Python bindings..."
cd bindings/python && uv sync --python 3.11 --all-extras --group dev
test: test-rust test-typescript test-python test-payloads ## Run all tests
test-rust: ## Run Rust tests
@echo "Running Rust tests..."
cargo test
test-typescript: typescript ## Run TypeScript tests
@echo "Running TypeScript tests..."
cd bindings/typescript && pnpm run test:run
test-typescript-integration: typescript ## Run TypeScript integration tests
@echo "Running TypeScript integration tests..."
cd bindings/typescript && pnpm run test:integration
test-payloads: lingua-wasm ## Run payload transform tests (REGENERATE=1 to auto-fix with API validation)
@echo "Running payload tests..."
@cd payloads && pnpm vitest run scripts/transforms $(if $(REGENERATE),|| pnpm tsx scripts/regenerate-failed.ts) \
|| (echo "\n❌ Tests failed! Run 'make regenerate-failed-transforms' to regenerate with real API calls" && exit 1)
fuzz-snapshots: ## Run ignored fuzz tests to generate/update snapshots, then prune duplicate failures
@$(MAKE) -C crates/lingua/tests/fuzz refresh-snapshots
fuzz-snapshots-prune: ## Prune fuzz snapshots (dedupe by normalized failure reason)
@$(MAKE) -C crates/lingua/tests/fuzz prune
typed-boundary-check: ## Fail if local provider/universal edits add direct Value field access
@echo "Checking typed boundary regressions in local changes..."; \
RESULTS=$$(git diff --unified=0 -- crates/lingua/src/providers crates/lingua/src/universal | \
rg -N '^\+.*(\.get\(\"|\.as_object\(|\.as_array\(|\.as_str\(|\.as_i64\(|\.as_u64\(|\.as_bool\(|\.as_f64\()' || true); \
if [ -n "$$RESULTS" ]; then \
echo "Found direct Value access in added lines:"; \
printf '%s\n' "$$RESULTS"; \
exit 1; \
fi; \
echo "No new direct Value field access detected."
typed-boundary-check-branch: ## Fail if committed branch diff adds direct Value field access (usage: make typed-boundary-check-branch BASE=fuzz-test-anthropic)
@if [ -z "$(BASE)" ]; then \
echo "Usage: make typed-boundary-check-branch BASE=<comparison-branch>"; \
exit 1; \
fi; \
echo "Checking typed boundary regressions in committed diff against $(BASE)..."; \
RESULTS=$$(git diff --unified=0 "$(BASE)"...HEAD -- crates/lingua/src/providers crates/lingua/src/universal | \
rg -N '^\+.*(\.get\(\"|\.as_object\(|\.as_array\(|\.as_str\(|\.as_i64\(|\.as_u64\(|\.as_bool\(|\.as_f64\()' || true); \
if [ -n "$$RESULTS" ]; then \
echo "Found direct Value access in added lines:"; \
printf '%s\n' "$$RESULTS"; \
exit 1; \
fi; \
echo "No new direct Value field access detected in committed diff."
capture: lingua-wasm ## Capture payloads (snapshots + transforms + vitest snapshots)
cd payloads && pnpm capture $(if $(FILTER),--filter $(FILTER)) $(if $(CASES),--cases $(CASES)) $(if $(FORCE),--force)
capture-transforms: lingua-wasm ## Re-capture only transforms (e.g. make capture-transforms PAIR=chat-completions,google FORCE=1)
cd payloads && pnpm tsx scripts/transforms/capture-transforms.ts $(if $(FILTER),$(FILTER)) $(if $(PAIR),--pair $(PAIR)) $(if $(FORCE),--force)
update-snapshots: lingua-wasm ## Update vitest snapshots without recapturing
cd payloads && pnpm vitest run scripts/transforms -u
regenerate-failed-transforms: lingua-wasm ## Auto-regenerate failed transform payloads
cd payloads && pnpm tsx scripts/regenerate-failed.ts
test-python: python ## Run Python tests
@echo "Running Python tests..."
cd bindings/python && uv run --extra dev --group dev maturin develop --features python
cd bindings/python && uv run --with pytest python -m pytest tests/ -v
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
cargo clean
rm -rf bindings/lingua-wasm/nodejs bindings/lingua-wasm/web
rm -rf bindings/typescript/dist bindings/typescript/node_modules
rm -rf bindings/typescript/src/generated
rm -rf bindings/python/.venv bindings/python/target
rm -rf target/wheels
check: ## Check all code compiles
@echo "Checking Rust code..."
cargo check --all-features
@echo "Checking TypeScript code..."
cd bindings/typescript && pnpm run typecheck
fmt: ## Format all code
@echo "Formatting Rust code..."
cargo fmt
@echo "Formatting TypeScript code..."
cd bindings/typescript && pnpm run lint
install-hooks: ## Install git pre-commit hooks
@echo "Installing git hooks..."
./scripts/install-hooks.sh
install-wasm-tools: ## Install WASM build tools (wasm32-unknown-unknown target, wasm-pack)
@echo "Installing WASM build tools..."
@rustup target add wasm32-unknown-unknown
@if ! command -v wasm-pack >/dev/null 2>&1; then \
cargo install wasm-pack; \
else \
echo "✅ wasm-pack already installed"; \
fi
install-dependencies: ## Install dependencies
@echo "Installing dependencies..."
./scripts/setup.sh
setup: install-dependencies install-hooks ## Setup the project
precommit: ## Run formatting, linting, and tests for Rust code
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test
.DEFAULT_GOAL := all