forked from lindera/lindera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
457 lines (352 loc) · 18.9 KB
/
Copy pathMakefile
File metadata and controls
457 lines (352 loc) · 18.9 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
LINDERA_VERSION ?= $(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera") | .version')
USER_AGENT ?= $(shell curl --version | head -n1 | awk '{print $1"/"$2}')
USER ?= $(shell whoami)
HOSTNAME ?= $(shell hostname)
# ── Python venv ─────────────────────────────────────────────────────────────
PYTHON_VENV_DIR := lindera-python/.venv
PYTHON := $(PYTHON_VENV_DIR)/bin/python
PIP := $(PYTHON_VENV_DIR)/bin/pip
MATURIN := $(PYTHON_VENV_DIR)/bin/maturin
PYTEST := $(PYTHON_VENV_DIR)/bin/pytest
# ── WASM ────────────────────────────────────────────────────────────────────
WASM_FEATURES = embed-ipadic
.DEFAULT_GOAL := help
help: ## Show help
@echo "Available targets:"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-30s %s\n", $$1, $$2}'
# ── Python venv setup ───────────────────────────────────────────────────────
$(PYTHON_VENV_DIR):
python3 -m venv $(PYTHON_VENV_DIR)
$(PIP) install --quiet --upgrade pip
setup-venv: $(PYTHON_VENV_DIR) ## Create lindera-python venv and install dev dependencies
$(PIP) install --quiet maturin pytest isort black flake8 mypy
clean-venv: ## Remove the lindera-python venv
rm -rf $(PYTHON_VENV_DIR)
# ── Clean ───────────────────────────────────────────────────────────────────
clean-lindera-crf: ## Clean lindera-crf
cargo clean -p lindera-crf
clean-lindera-dictionary: ## Clean lindera-dictionary
cargo clean -p lindera-dictionary
clean-lindera-ipadic: ## Clean lindera-ipadic
cargo clean -p lindera-ipadic
clean-lindera-ipadic-neologd: ## Clean lindera-ipadic-neologd
cargo clean -p lindera-ipadic-neologd
clean-lindera-unidic: ## Clean lindera-unidic
cargo clean -p lindera-unidic
clean-lindera-ko-dic: ## Clean lindera-ko-dic
cargo clean -p lindera-ko-dic
clean-lindera-cc-cedict: ## Clean lindera-cc-cedict
cargo clean -p lindera-cc-cedict
clean-lindera-jieba: ## Clean lindera-jieba
cargo clean -p lindera-jieba
clean-lindera: ## Clean lindera
cargo clean -p lindera
clean-lindera-cli: ## Clean lindera-cli
cargo clean -p lindera-cli
clean-lindera-python: ## Clean lindera-python build artifacts
rm -rf lindera-python/target
rm -rf lindera-python/dist
rm -rf lindera-python/__pycache__
rm -rf lindera-python/tests/__pycache__
rm -rf lindera-python/.pytest_cache
clean-lindera-nodejs: ## Clean lindera-nodejs build artifacts
rm -rf lindera-nodejs/node_modules
rm -rf lindera-nodejs/npm
rm -f lindera-nodejs/*.node
rm -f lindera-nodejs/index.js
rm -f lindera-nodejs/index.d.ts
rm -f lindera-nodejs/package-lock.json
clean-lindera-ruby: ## Clean lindera-ruby build artifacts
rm -rf lindera-ruby/tmp
rm -f lindera-ruby/lib/lindera/lindera_ruby.so
rm -f lindera-ruby/Gemfile.lock
clean-lindera-php: ## Clean lindera-php build artifacts
rm -rf lindera-php/vendor
rm -f lindera-php/composer.lock
clean-lindera-wasm: ## Clean lindera-wasm build artifacts
rm -rf lindera-wasm/pkg
rm -rf lindera-wasm/example/dist
rm -rf lindera-wasm/example/node_modules
rm -f lindera-wasm/example/package-lock.json
rm -f lindera-wasm/example/temp.json
clean: ## Clean all build artifacts
make clean-lindera-crf
make clean-lindera-dictionary
make clean-lindera-ipadic
make clean-lindera-ipadic-neologd
make clean-lindera-unidic
make clean-lindera-ko-dic
make clean-lindera-cc-cedict
make clean-lindera-jieba
make clean-lindera
make clean-lindera-cli
make clean-lindera-python
make clean-lindera-nodejs
make clean-lindera-ruby
make clean-lindera-php
make clean-lindera-wasm
# ── Format ──────────────────────────────────────────────────────────────────
format-lindera-crf: ## Format lindera-crf
cargo fmt -p lindera-crf
format-lindera-dictionary: ## Format lindera-dictionary
cargo fmt -p lindera-dictionary
format-lindera-ipadic: ## Format lindera-ipadic
cargo fmt -p lindera-ipadic
format-lindera-ipadic-neologd: ## Format lindera-ipadic-neologd
cargo fmt -p lindera-ipadic-neologd
format-lindera-unidic: ## Format lindera-unidic
cargo fmt -p lindera-unidic
format-lindera-ko-dic: ## Format lindera-ko-dic
cargo fmt -p lindera-ko-dic
format-lindera-cc-cedict: ## Format lindera-cc-cedict
cargo fmt -p lindera-cc-cedict
format-lindera-jieba: ## Format lindera-jieba
cargo fmt -p lindera-jieba
format-lindera: ## Format lindera
cargo fmt -p lindera
format-lindera-cli: ## Format lindera-cli
cargo fmt -p lindera-cli
format-lindera-python: ## Format lindera-python
cargo fmt -p lindera-python
ruff format lindera-python/tests/ lindera-python/examples/
ruff check --fix lindera-python/tests/ lindera-python/examples/
format-lindera-nodejs: ## Format lindera-nodejs
cargo fmt -p lindera-nodejs
prettier --write lindera-nodejs/tests/ lindera-nodejs/examples/
format-lindera-ruby: ## Format lindera-ruby
cargo fmt -p lindera-ruby
rubocop -a lindera-ruby/test/ lindera-ruby/examples/ lindera-ruby/lib/
format-lindera-php: ## Format lindera-php
cargo fmt -p lindera-php
cd lindera-php && vendor/bin/php-cs-fixer fix
format-lindera-wasm: ## Format lindera-wasm
cargo fmt -p lindera-wasm
prettier --write lindera-wasm/js/ lindera-wasm/example/
format: ## Format all crates
make format-lindera-crf
make format-lindera-dictionary
make format-lindera-ipadic
make format-lindera-ipadic-neologd
make format-lindera-unidic
make format-lindera-ko-dic
make format-lindera-cc-cedict
make format-lindera-jieba
make format-lindera
make format-lindera-cli
make format-lindera-python
make format-lindera-nodejs
make format-lindera-ruby
make format-lindera-php
make format-lindera-wasm
# ── Lint ────────────────────────────────────────────────────────────────────
lint-lindera-crf: ## Lint lindera-crf
cargo clippy -p lindera-crf -- -D warnings
lint-lindera-dictionary: ## Lint lindera-dictionary
cargo clippy -p lindera-dictionary --features train -- -D warnings
lint-lindera-ipadic: ## Lint lindera-ipadic
cargo clippy -p lindera-ipadic --features embed-ipadic -- -D warnings
lint-lindera-ipadic-neologd: ## Lint lindera-ipadic-neologd
cargo clippy -p lindera-ipadic-neologd --features embed-ipadic-neologd -- -D warnings
lint-lindera-unidic: ## Lint lindera-unidic
cargo clippy -p lindera-unidic --features embed-unidic -- -D warnings
lint-lindera-ko-dic: ## Lint lindera-ko-dic
cargo clippy -p lindera-ko-dic --features embed-ko-dic -- -D warnings
lint-lindera-cc-cedict: ## Lint lindera-cc-cedict
cargo clippy -p lindera-cc-cedict --features embed-cc-cedict -- -D warnings
lint-lindera-jieba: ## Lint lindera-jieba
cargo clippy -p lindera-jieba --features embed-jieba -- -D warnings
lint-lindera: ## Lint lindera
cargo clippy -p lindera --features embed-ipadic,train -- -D warnings
lint-lindera-cli: ## Lint lindera-cli
cargo clippy -p lindera-cli --features train -- -D warnings
lint-lindera-python: ## Lint lindera-python
cargo clippy -p lindera-python -- -D warnings
ruff format --check lindera-python/tests/ lindera-python/examples/
ruff check lindera-python/tests/ lindera-python/examples/
lint-lindera-nodejs: ## Lint lindera-nodejs
cargo clippy -p lindera-nodejs -- -D warnings
prettier --check lindera-nodejs/tests/ lindera-nodejs/examples/
lint-lindera-ruby: ## Lint lindera-ruby
$(CARGO_TEST_WITH_RBCONFIG) cargo clippy -p lindera-ruby -- -D warnings
rubocop lindera-ruby/test/ lindera-ruby/examples/ lindera-ruby/lib/
lint-lindera-php: ## Lint lindera-php
cargo clippy -p lindera-php -- -D warnings
lint-lindera-wasm: ## Lint lindera-wasm (wasm32 target)
cargo clippy -p lindera-wasm --target wasm32-unknown-unknown -- -D warnings
prettier --check lindera-wasm/js/ lindera-wasm/example/
lint: ## Lint all crates
make lint-lindera-crf
make lint-lindera-dictionary
make lint-lindera-ipadic
make lint-lindera-ipadic-neologd
make lint-lindera-unidic
make lint-lindera-ko-dic
make lint-lindera-cc-cedict
make lint-lindera-jieba
make lint-lindera
make lint-lindera-cli
make lint-lindera-python
make lint-lindera-nodejs
make lint-lindera-ruby
make lint-lindera-php
make lint-lindera-wasm
# ── Test ────────────────────────────────────────────────────────────────────
test-lindera-crf: ## Test lindera-crf
cargo test -p lindera-crf
test-lindera-dictionary: ## Test lindera-dictionary
cargo test -p lindera-dictionary --features train
test-lindera-ipadic: ## Test lindera-ipadic
cargo test -p lindera-ipadic --features embed-ipadic
test-lindera-ipadic-neologd: ## Test lindera-ipadic-neologd
cargo test -p lindera-ipadic-neologd --features embed-ipadic-neologd
test-lindera-unidic: ## Test lindera-unidic
cargo test -p lindera-unidic --features embed-unidic
test-lindera-ko-dic: ## Test lindera-ko-dic
cargo test -p lindera-ko-dic --features embed-ko-dic
test-lindera-cc-cedict: ## Test lindera-cc-cedict
cargo test -p lindera-cc-cedict --features embed-cc-cedict
test-lindera-jieba: ## Test lindera-jieba
cargo test -p lindera-jieba --features embed-jieba
test-lindera: ## Test lindera
cargo test -p lindera --features embed-ipadic,train
test-lindera-cli: ## Test lindera-cli
cargo test -p lindera-cli --features train
test-lindera-python: setup-venv ## Test lindera-python (Rust unit tests + Python pytest)
cargo test -p lindera-python --lib
cd lindera-python && VIRTUAL_ENV=$(abspath $(PYTHON_VENV_DIR)) $(abspath $(MATURIN)) develop --quiet --features=embed-ipadic,train && $(abspath $(PYTEST)) tests/ -v
test-lindera-nodejs: ## Test lindera-nodejs (Rust unit tests + Node.js test)
cargo test -p lindera-nodejs --lib
cd lindera-nodejs && npm install --quiet && npx napi build --platform -p lindera-nodejs && npm test
CARGO_TEST_WITH_RBCONFIG = ruby -rrbconfig -e 'RbConfig::CONFIG.each { |k, v| ENV["RBCONFIG_\#{k.upcase}"] = v }; exec(*ARGV)' --
test-lindera-ruby: ## Test lindera-ruby (Rust unit tests + minitest)
$(CARGO_TEST_WITH_RBCONFIG) cargo test -p lindera-ruby --lib
cd lindera-ruby && bundle install --quiet && LINDERA_FEATURES="embed-ipadic,train" bundle exec rake compile && bundle exec rake test
test-lindera-php: ## Test lindera-php (Rust unit tests + PHPUnit)
cargo test -p lindera-php --lib
cargo build -p lindera-php --features embed-ipadic,train
cd lindera-php && composer install --quiet && \
LIB=$$(find ../target/debug -maxdepth 1 -name 'liblindera_php.*' \( -name '*.so' -o -name '*.dylib' \) | head -1) && \
php -d extension=$$LIB vendor/bin/phpunit tests/LinderaTest.php
test-lindera-wasm: ## Build-test lindera-wasm (wasm32 target)
cargo test -p lindera-wasm --lib
cd lindera-wasm && wasm-pack test --node --features=$(WASM_FEATURES)
test: ## Test all crates
make test-lindera-crf
make test-lindera-dictionary
make test-lindera-ipadic
make test-lindera-ipadic-neologd
make test-lindera-unidic
make test-lindera-ko-dic
make test-lindera-cc-cedict
make test-lindera-jieba
make test-lindera
make test-lindera-cli
make test-lindera-python
make test-lindera-nodejs
make test-lindera-ruby
make test-lindera-php
make test-lindera-wasm
# ── Build ───────────────────────────────────────────────────────────────────
build-lindera-crf: ## Build lindera-crf (release)
cargo build -p lindera-crf --release
build-lindera-dictionary: ## Build lindera-dictionary (release)
cargo build -p lindera-dictionary --release --features train
build-lindera-ipadic: ## Build lindera-ipadic (release)
cargo build -p lindera-ipadic --release --features embed-ipadic
build-lindera-ipadic-neologd: ## Build lindera-ipadic-neologd (release)
cargo build -p lindera-ipadic-neologd --release --features embed-ipadic-neologd
build-lindera-unidic: ## Build lindera-unidic (release)
cargo build -p lindera-unidic --release --features embed-unidic
build-lindera-ko-dic: ## Build lindera-ko-dic (release)
cargo build -p lindera-ko-dic --release --features embed-ko-dic
build-lindera-cc-cedict: ## Build lindera-cc-cedict (release)
cargo build -p lindera-cc-cedict --release --features embed-cc-cedict
build-lindera-jieba: ## Build lindera-jieba (release)
cargo build -p lindera-jieba --release --features embed-jieba
build-lindera: ## Build lindera (release)
cargo build -p lindera --release --features train
build-lindera-cli: ## Build lindera-cli (release)
cargo build -p lindera-cli --release --features train
build-lindera-python: setup-venv ## Build lindera-python wheel (release)
cd lindera-python && VIRTUAL_ENV=$(abspath $(PYTHON_VENV_DIR)) $(abspath $(MATURIN)) build --release --features train
build-lindera-nodejs: ## Build lindera-nodejs (release)
cd lindera-nodejs && npm install --quiet && npx napi build --platform --release -p lindera-nodejs
build-lindera-ruby: ## Build lindera-ruby (release)
cd lindera-ruby && bundle install --quiet && LINDERA_FEATURES="embed-ipadic,train" bundle exec rake compile
build-lindera-php: ## Build lindera-php (release)
cargo build -p lindera-php --release --features train
build-lindera-wasm: ## Build lindera-wasm (wasm-pack, --target web)
cd lindera-wasm && wasm-pack build --release --features=$(WASM_FEATURES) --target=web
cp lindera-wasm/js/opfs.js lindera-wasm/pkg/
cp lindera-wasm/js/opfs.d.ts lindera-wasm/pkg/
build: ## Build all crates (release)
make build-lindera-crf
make build-lindera-dictionary
make build-lindera-ipadic
make build-lindera-ipadic-neologd
make build-lindera-unidic
make build-lindera-ko-dic
make build-lindera-cc-cedict
make build-lindera-jieba
make build-lindera
make build-lindera-cli
make build-lindera-python
make build-lindera-nodejs
make build-lindera-ruby
make build-lindera-php
make build-lindera-wasm
# ── Benchmark ───────────────────────────────────────────────────────────────
bench: ## Run all benchmarks
@echo "Running all Lindera benchmarks..."
@$(foreach dict,ipadic ipadic_neologd unidic ko_dic cc_cedict, \
echo "Running $(dict) benchmark..."; \
(cd lindera && cargo bench --bench=bench_$(dict) --features=embed-$(subst _,-,$(dict))) || true; \
echo "";)
@echo "All benchmarks completed!"
@echo "Results are available in lindera/target/criterion/"
bench-all: ## Run all benchmarks with CJK dictionaries
@echo "Running all Lindera benchmarks with CJK dictionaries..."
(cd lindera && cargo bench --features embed-cjk)
@echo "All benchmarks completed!"
# ── WASM example ────────────────────────────────────────────────────────────
build-lindera-wasm-example: ## Build the WASM example application (OPFS, no embedded dictionary)
cd lindera-wasm && wasm-pack build --release --target=web
cp lindera-wasm/js/opfs.js lindera-wasm/pkg/
cp lindera-wasm/js/opfs.d.ts lindera-wasm/pkg/
cd lindera-wasm/example && \
LINDERA_WASM_VERSION=$$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-wasm") | .version') && \
jq ".version = \"$$LINDERA_WASM_VERSION\"" ./package.json > ./temp.json && mv ./temp.json ./package.json && \
npm install && \
npm run build && \
cp index.html dist/index.html
run-lindera-wasm-example: ## Run the WASM example application
cd lindera-wasm/example && npm run start
# ── Tag & Publish ───────────────────────────────────────────────────────────
tag: ## Make a tag for the current version
git tag v$(LINDERA_VERSION)
git push origin v$(LINDERA_VERSION)
define PUBLISH_CRATE
@if [ -z "$$(curl -s -XGET -H "User-Agent: $(USER_AGENT) ($(USER)@$(HOSTNAME))" https://crates.io/api/v1/crates/$(1) | jq -r '.versions[].num | select(. == "$(2)")')" ]; then \
echo "Publishing $(1) v$(2)..."; \
(cd $(1) && cargo package && cargo publish); \
sleep 10; \
else \
echo "$(1) v$(2) is already published."; \
fi
endef
publish: ## Publish packages to crates.io
$(call PUBLISH_CRATE,lindera-crf,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-crf") | .version'))
$(call PUBLISH_CRATE,lindera-dictionary,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-dictionary") | .version'))
$(call PUBLISH_CRATE,lindera-cc-cedict,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-cc-cedict") | .version'))
$(call PUBLISH_CRATE,lindera-ipadic,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-ipadic") | .version'))
$(call PUBLISH_CRATE,lindera-ipadic-neologd,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-ipadic-neologd") | .version'))
$(call PUBLISH_CRATE,lindera-jieba,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-jieba") | .version'))
$(call PUBLISH_CRATE,lindera-ko-dic,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-ko-dic") | .version'))
$(call PUBLISH_CRATE,lindera-unidic,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-unidic") | .version'))
$(call PUBLISH_CRATE,lindera,$(LINDERA_VERSION))
$(call PUBLISH_CRATE,lindera-cli,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-cli") | .version'))
$(call PUBLISH_CRATE,lindera-python,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-python") | .version'))
$(call PUBLISH_CRATE,lindera-nodejs,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-nodejs") | .version'))
$(call PUBLISH_CRATE,lindera-ruby,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-ruby") | .version'))
$(call PUBLISH_CRATE,lindera-php,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-php") | .version'))
$(call PUBLISH_CRATE,lindera-wasm,$(shell cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="lindera-wasm") | .version'))