-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (166 loc) · 8.46 KB
/
Copy pathMakefile
File metadata and controls
204 lines (166 loc) · 8.46 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# php-lsp — build & package
# Usage:
# make — full build (server + client + stubs + .vsix)
# make server — build Rust server binary for host platform
# make client — install deps & build VS Code extension JS
# make stubs — init submodule & bundle stubs
# make package — produce .vsix (depends on all above)
# make server-all — cross-compile server for all 6 platforms
# make package-all— universal .vsix with all platform binaries
# make release — bump versions from VERSION, commit, tag & push to GitHub
# make clean — remove build artefacts
# make check — run all lints and tests
# make check-server — run Rust fmt, clippy and tests
# make check-client — run VS Code client lint and build
# make test-server — run php-lsp-server crate tests
# make test-e2e — run LSP protocol e2e tests
SHELL := /bin/bash
.DEFAULT_GOAL := package
ROOT_DIR := $(shell pwd)
SERVER_DIR := $(ROOT_DIR)/server
CLIENT_DIR := $(ROOT_DIR)/client
STUBS_SRC := $(SERVER_DIR)/data/stubs
STUBS_DEST := $(CLIENT_DIR)/stubs
VERSION := $(shell cat $(ROOT_DIR)/VERSION | tr -d '[:space:]')
# Detect host Rust target
HOST_TARGET := $(shell rustc -vV | awk '/^host:/ {print $$2}')
# Map Rust target → VS Code platform dir
platform = $(strip \
$(if $(findstring x86_64-unknown-linux,$(1)),linux-x64, \
$(if $(findstring aarch64-unknown-linux,$(1)),linux-arm64, \
$(if $(findstring x86_64-apple-darwin,$(1)),darwin-x64, \
$(if $(findstring aarch64-apple-darwin,$(1)),darwin-arm64, \
$(if $(findstring x86_64-pc-windows,$(1)),win32-x64, \
$(if $(findstring aarch64-pc-windows,$(1)),win32-arm64, \
$(error Unknown target: $(1)))))))))
PLATFORM := $(call platform,$(HOST_TARGET))
BIN_DIR := $(CLIENT_DIR)/bin/$(PLATFORM)
BIN_NAME := $(if $(findstring windows,$(HOST_TARGET)),php-lsp.exe,php-lsp)
SERVER_BIN := $(BIN_DIR)/$(BIN_NAME)
# ─── Phony targets ───────────────────────────────────────────────
.PHONY: all package package-all install server server-all client stubs check-stubs clean check check-server check-client cargo-check test test-parser test-index test-completion test-server test-e2e lint fmt release
all: package
# ─── Stubs (git submodule + bundle) ─────────────────────────────
$(STUBS_SRC)/.git:
git submodule update --init --recursive
$(STUBS_DEST): $(STUBS_SRC)/.git
$(ROOT_DIR)/scripts/bundle-stubs.sh
stubs: $(STUBS_DEST)
check-stubs:
$(ROOT_DIR)/scripts/check-stubs.sh --kind source $(STUBS_SRC)
$(ROOT_DIR)/scripts/check-stubs.sh --kind bundled $(STUBS_DEST)
# ─── Server (Rust) ──────────────────────────────────────────────
RUST_SOURCES := $(shell find $(SERVER_DIR)/crates -name '*.rs' 2>/dev/null)
$(SERVER_BIN): $(RUST_SOURCES) $(SERVER_DIR)/Cargo.toml $(SERVER_DIR)/Cargo.lock
cargo build --release --manifest-path $(SERVER_DIR)/Cargo.toml --target $(HOST_TARGET)
@mkdir -p $(BIN_DIR)
cp $(SERVER_DIR)/target/$(HOST_TARGET)/release/$(BIN_NAME) $(SERVER_BIN)
@if [[ "$(HOST_TARGET)" != *windows* ]] && command -v strip &>/dev/null; then \
strip $(SERVER_BIN) 2>/dev/null || true; \
fi
@echo "→ $(SERVER_BIN) ($$(du -h $(SERVER_BIN) | cut -f1))"
server: $(SERVER_BIN)
# ─── Server (all platforms) ──────────────────────────────────────
ALL_TARGETS := \
x86_64-unknown-linux-gnu \
aarch64-unknown-linux-gnu \
x86_64-apple-darwin \
aarch64-apple-darwin \
x86_64-pc-windows-msvc \
aarch64-pc-windows-msvc
server-all:
$(ROOT_DIR)/scripts/build-server.sh --all
# ─── Client (TypeScript) ────────────────────────────────────────
$(CLIENT_DIR)/node_modules: $(CLIENT_DIR)/package.json $(wildcard $(CLIENT_DIR)/package-lock.json)
cd $(CLIENT_DIR) && npm ci
@touch $@
$(CLIENT_DIR)/out/extension.js: $(CLIENT_DIR)/node_modules $(wildcard $(CLIENT_DIR)/src/*.ts)
cd $(CLIENT_DIR) && npm run build
client: $(CLIENT_DIR)/out/extension.js
# ─── Package (.vsix) ────────────────────────────────────────────
package: $(SERVER_BIN) $(CLIENT_DIR)/out/extension.js $(STUBS_DEST)
cd $(CLIENT_DIR) && npx @vscode/vsce package --no-dependencies
@echo "=== .vsix created ==="
@ls -lh $(CLIENT_DIR)/*.vsix 2>/dev/null
# ─── Package all platforms (.vsix) ───────────────────────────────
package-all: server-all $(CLIENT_DIR)/out/extension.js $(STUBS_DEST)
cd $(CLIENT_DIR) && npx @vscode/vsce package --no-dependencies
@echo "=== universal .vsix created ==="
@ls -lh $(CLIENT_DIR)/*.vsix 2>/dev/null
# ─── Quality checks ─────────────────────────────────────────────
check: check-stubs lint test
check-server:
cd $(SERVER_DIR) && cargo fmt --all --check
cd $(SERVER_DIR) && cargo clippy --all-targets -- -D warnings
cd $(SERVER_DIR) && cargo test --all
check-client:
cd $(CLIENT_DIR) && npm run lint
cd $(CLIENT_DIR) && npm run build
cargo-check:
cd $(SERVER_DIR) && cargo check --workspace
lint:
cd $(SERVER_DIR) && cargo fmt --all --check
cd $(SERVER_DIR) && cargo clippy --all-targets -- -D warnings
cd $(CLIENT_DIR) && npm run lint
fmt:
cd $(SERVER_DIR) && cargo fmt --all
test:
cd $(SERVER_DIR) && cargo test --all
test-parser:
cd $(SERVER_DIR) && cargo test -p php-lsp-parser
test-index:
cd $(SERVER_DIR) && cargo test -p php-lsp-index
test-completion:
cd $(SERVER_DIR) && cargo test -p php-lsp-completion
test-server:
cd $(SERVER_DIR) && cargo test -p php-lsp-server
test-e2e:
cd $(SERVER_DIR) && cargo test -p php-lsp-server --tests
# ─── Install into VS Code ────────────────────────────────────────
VSIX := $(shell ls -t $(CLIENT_DIR)/*.vsix 2>/dev/null | head -1)
install: package
@VSIX=$$(ls -t $(CLIENT_DIR)/*.vsix 2>/dev/null | head -1); \
if [[ -z "$$VSIX" ]]; then \
echo "ERROR: no .vsix found in $(CLIENT_DIR)"; exit 1; \
fi; \
echo "=== Installing $$VSIX ==="; \
code --install-extension "$$VSIX" --force
# ─── Clean ───────────────────────────────────────────────────────
clean:
cd $(SERVER_DIR) && cargo clean
rm -rf $(CLIENT_DIR)/out $(CLIENT_DIR)/node_modules
rm -rf $(CLIENT_DIR)/bin
rm -rf $(STUBS_DEST)
rm -f $(CLIENT_DIR)/*.vsix
# ─── Release ─────────────────────────────────────────────────────
# Reads version from VERSION file, patches package.json and Cargo.toml,
# commits version files, creates/force-updates the git tag and pushes.
release:
@if [[ -z "$(VERSION)" ]]; then echo "ERROR: VERSION file is empty"; exit 1; fi
@if ! echo "$(VERSION)" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'; then \
echo "ERROR: VERSION '$(VERSION)' is not valid semver (X.Y.Z)"; exit 1; \
fi
@if ! git -C $(ROOT_DIR) diff --quiet || ! git -C $(ROOT_DIR) diff --cached --quiet; then \
echo "ERROR: working tree is not clean, commit or stash changes first"; exit 1; \
fi
@echo "=== Release v$(VERSION) ==="
@echo "--- Patching client/package.json ---"
cd $(CLIENT_DIR) && npm version "$(VERSION)" --no-git-tag-version --allow-same-version
@echo "--- Patching server/Cargo.toml workspace version ---"
sed -i 's/^version = ".*"/version = "$(VERSION)"/' $(SERVER_DIR)/Cargo.toml
@echo "--- Updating Cargo.lock ---"
cd $(SERVER_DIR) && cargo update --workspace --quiet 2>/dev/null || true
@echo "--- Tagging v$(VERSION) (force) ---"
git -C $(ROOT_DIR) add \
$(CLIENT_DIR)/package.json \
$(CLIENT_DIR)/package-lock.json \
$(SERVER_DIR)/Cargo.toml \
$(SERVER_DIR)/Cargo.lock \
$(ROOT_DIR)/VERSION
git -C $(ROOT_DIR) diff --cached --quiet || \
git -C $(ROOT_DIR) commit -m "chore(release): bump version to $(VERSION)"
git -C $(ROOT_DIR) tag -f "v$(VERSION)"
@echo "--- Pushing branch and tag to GitHub ---"
git -C $(ROOT_DIR) push origin main
git -C $(ROOT_DIR) push origin "v$(VERSION)" --force
@echo "=== Released v$(VERSION) ==="