forked from nautechsystems/nautilus_trader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
644 lines (538 loc) · 26.1 KB
/
Makefile
File metadata and controls
644 lines (538 loc) · 26.1 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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# Variables
# -----------------------------------------------------------------------------
PROJECT?=nautechsystems/nautilus_trader
REGISTRY?=ghcr.io/
IMAGE?=$(REGISTRY)$(PROJECT)
GIT_TAG:=$(shell git rev-parse --abbrev-ref HEAD)
IMAGE_FULL?=$(IMAGE):$(GIT_TAG)
# Tool versions from Cargo.toml [workspace.metadata.tools]
CARGO_AUDIT_VERSION := $(shell grep '^cargo-audit *= *"' Cargo.toml | awk -F\" '{print $$2}')
CARGO_DENY_VERSION := $(shell grep '^cargo-deny *= *"' Cargo.toml | awk -F\" '{print $$2}')
CARGO_EDIT_VERSION := $(shell grep '^cargo-edit *= *"' Cargo.toml | awk -F\" '{print $$2}')
CARGO_LLVM_COV_VERSION := $(shell grep '^cargo-llvm-cov *= *"' Cargo.toml | awk -F\" '{print $$2}')
CARGO_MACHETE_VERSION := $(shell grep '^cargo-machete *= *"' Cargo.toml | awk -F\" '{print $$2}')
CARGO_NEXTEST_VERSION := $(shell grep '^cargo-nextest *= *"' Cargo.toml | awk -F\" '{print $$2}')
CARGO_VET_VERSION := $(shell grep '^cargo-vet *= *"' Cargo.toml | awk -F\" '{print $$2}')
LYCHEE_VERSION := $(shell grep '^lychee *= *"' Cargo.toml | awk -F\" '{print $$2}')
UV_VERSION := $(shell cat uv-version | tr -d '\n')
V = 0 # 0 / 1 - verbose mode
Q = $(if $(filter 1,$V),,@) # Quiet mode, suppress command output
M = $(shell printf "\033[0;34m>\033[0m") # Message prefix for commands
# Verbose options for specific targets (defaults to true, can be overridden)
VERBOSE ?= true
# TARGET_DIR controls where cargo places build artifacts.
# Can be overridden to use a separate directory: make build-debug TARGET_DIR=target-python
TARGET_DIR ?= target
# Compiler configuration
# Uses clang by default (required by ed25519-blake2b and other deps).
# When sccache is available, wraps the compiler for build caching.
# Set CARGO_INCREMENTAL=0 with sccache for better cache hit rates.
# To disable sccache: make build SCCACHE=
SCCACHE ?= $(shell command -v sccache 2>/dev/null)
ifeq ($(SCCACHE),)
CC ?= clang
CXX ?= clang++
else
CC ?= sccache clang
CXX ?= sccache clang++
RUSTC_WRAPPER ?= sccache
CARGO_INCREMENTAL ?= 0
export RUSTC_WRAPPER
export CARGO_INCREMENTAL
endif
export CC
export CXX
# FAIL_FAST controls whether `cargo nextest` should stop after the first test
# failure. When set to `true` the `--no-fail-fast` flag is omitted so tests
# abort on the first failure. When `false` (the default) the flag is included
# allowing the full test suite to run.
FAIL_FAST ?= false
# Select the appropriate flag for `cargo nextest` depending on FAIL_FAST.
ifeq ($(FAIL_FAST),true)
FAIL_FAST_FLAG :=
else
FAIL_FAST_FLAG := --no-fail-fast
endif
# EXTRA_FEATURES allows adding optional features to cargo builds/tests.
# Can be set directly: make cargo-test EXTRA_FEATURES="capnp hypersync"
# Or use convenience flags below for backwards compatibility.
EXTRA_FEATURES ?=
# HYPERSYNC is a convenience flag that adds hypersync to EXTRA_FEATURES.
# Can be overridden: make check-code HYPERSYNC=true
HYPERSYNC ?= false
ifeq ($(HYPERSYNC),true)
EXTRA_FEATURES += hypersync
endif
# Base cargo features (always included)
BASE_FEATURES := ffi,python,high-precision,defi
# Combine base features with extra features
ifneq ($(strip $(EXTRA_FEATURES)),)
CARGO_FEATURES := $(BASE_FEATURES),$(EXTRA_FEATURES)
else
CARGO_FEATURES := $(BASE_FEATURES)
endif
# > Colors
# Use ANSI escape codes directly for cross-platform compatibility (Git Bash on Windows doesn't have tput)
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
PURPLE := \033[0;35m
CYAN := \033[0;36m
GRAY := \033[0;37m
RESET := \033[0m
.DEFAULT_GOAL := help
# Requires GNU Make across all platforms (Windows users should install it via MSYS2 or WSL).
#== Installation
.PHONY: install
install: export BUILD_MODE=release
install: #-- Install in release mode with all dependencies and extras
$(info $(M) Installing NautilusTrader in release mode with all dependencies and extras...)
$Q uv sync --active --all-groups --all-extras --verbose
.PHONY: install-debug
install-debug: export BUILD_MODE=debug
install-debug: #-- Install in debug mode for development
$(info $(M) Installing NautilusTrader in debug mode for development...)
$Q uv sync --active --all-groups --all-extras --verbose
.PHONY: install-just-deps
install-just-deps: #-- Install dependencies only without building the package
$(info $(M) Installing dependencies only without building the package...)
$Q uv sync --active --all-groups --all-extras --no-install-package nautilus_trader
#== Build
.PHONY: build
build: export BUILD_MODE=release
build: export CARGO_TARGET_DIR=$(TARGET_DIR)
build: #-- Build the package in release mode
uv run --active --no-sync build.py
.PHONY: build-debug
build-debug: export BUILD_MODE=debug
build-debug: export CARGO_TARGET_DIR=$(TARGET_DIR)
build-debug: #-- Build the package in debug mode (recommended for development)
ifeq ($(VERBOSE),true)
$(info $(M) Building in debug mode with verbose output...)
uv run --active --no-sync build.py
else
$(info $(M) Building in debug mode (errors will still be shown)...)
uv run --active --no-sync build.py 2>&1 | grep -E "(Error|error|ERROR|Failed|failed|FAILED|Warning|warning|WARNING|Build completed|Build time:|Traceback)" || true
endif
.PHONY: build-debug-pyo3
build-debug-pyo3: export BUILD_MODE=debug-pyo3
build-debug-pyo3: export CARGO_TARGET_DIR=$(TARGET_DIR)
build-debug-pyo3: #-- Build the package with PyO3 debug symbols (for debugging Rust code)
ifeq ($(VERBOSE),true)
$(info $(M) Building in debug mode with PyO3 debug symbols...)
uv run --active --no-sync build.py
else
$(info $(M) Building in debug mode with PyO3 debug symbols (errors will still be shown)...)
uv run --active --no-sync build.py 2>&1 | grep -E "(Error|error|ERROR|Failed|failed|FAILED|Warning|warning|WARNING|Build completed|Build time:|Traceback)" || true
endif
.PHONY: build-wheel
build-wheel: export BUILD_MODE=release
build-wheel: #-- Build wheel distribution in release mode
uv build --wheel
.PHONY: build-wheel-debug
build-wheel-debug: export BUILD_MODE=debug
build-wheel-debug: #-- Build wheel distribution in debug mode
uv build --wheel
.PHONY: build-dry-run
build-dry-run: export DRY_RUN=true
build-dry-run: #-- Show build commands without executing them
uv run --active --no-sync build.py
#== Clean
.PHONY: clean
clean: clean-build-artifacts clean-caches clean-builds #-- Clean all build artifacts, caches, and builds
.PHONY: clean-builds
clean-builds: #-- Clean distribution and target directories
$Q rm -rf dist target 2>/dev/null || true
.PHONY: clean-build-artifacts
clean-build-artifacts: #-- Clean compiled artifacts (.so, .dll, .pyc, .c files)
@echo "Cleaning build artifacts..."
# Clean Rust build artifacts (keep final libraries)
find target -name "*.rlib" -delete 2>/dev/null || true
find target -name "*.rmeta" -delete 2>/dev/null || true
rm -rf target/*/build target/*/deps 2>/dev/null || true
# Clean Python build artifacts
find . -type d -name "__pycache__" -not -path "./.venv*" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.c" -not -path "./.venv*" -not -path "./target/*" -exec rm -f {} + 2>/dev/null || true
find . -type f -a \( -name "*.pyc" -o -name "*.pyo" \) -not -path "./.venv*" -exec rm -f {} + 2>/dev/null || true
find . -type f -a \( -name "*.so" -o -name "*.dll" -o -name "*.dylib" \) -not -path "./.venv*" -exec rm -f {} + 2>/dev/null || true
rm -rf build/ cython_debug/ 2>/dev/null || true
# Clean test artifacts
rm -rf .coverage .benchmarks 2>/dev/null || true
.PHONY: clean-caches
clean-caches: #-- Clean pytest, mypy, ruff, uv, and cargo caches
rm -rf .pytest_cache .mypy_cache .ruff_cache 2>/dev/null || true
-uv cache prune --force
-cargo clean
.PHONY: distclean
distclean: clean #-- Nuclear clean - remove all untracked files (requires FORCE=1)
@if [ "$$FORCE" != "1" ]; then \
echo "Pass FORCE=1 to really nuke"; \
exit 1; \
fi
@echo "WARNING: removing all untracked files (git clean -fxd)..."
git clean -fxd -e tests/test_data/large/ -e .venv
#== Code Quality
.PHONY: format
format: #-- Format Rust code using nightly formatter
cargo +nightly fmt
.PHONY: pre-commit
pre-commit: #-- Run all pre-commit hooks on all files
uv run --active --no-sync pre-commit run --all-files
# The check-code target uses CARGO_FEATURES which is controlled by the HYPERSYNC flag.
# By default, hypersync is excluded to speed up checks. Override with: make check-code HYPERSYNC=true
.PHONY: check-code
check-code: #-- Run clippy, and ruff --fix (use HYPERSYNC=true to include hypersync feature)
$(info $(M) Running code quality checks...)
@cargo clippy --workspace --all-targets --features "$(CARGO_FEATURES)" --profile nextest -- -D warnings
@uv run --active --no-sync ruff check . --fix
@printf "$(GREEN)Checks passed$(RESET)\n"
.PHONY: pre-flight
pre-flight: export CARGO_TARGET_DIR=$(TARGET_DIR)
pre-flight: #-- Run comprehensive pre-flight checks (format, check-code, cargo-test, build-debug, pytest)
$(info $(M) Running pre-flight checks...)
@if ! git diff --quiet; then \
printf "$(RED)ERROR: You have unstaged changes$(RESET)\n"; \
printf "$(YELLOW)Stage your changes first:$(RESET) git add .\n"; \
exit 1; \
fi
@$(MAKE) --no-print-directory format
@$(MAKE) --no-print-directory check-code
@$(MAKE) --no-print-directory cargo-test
@$(MAKE) --no-print-directory build-debug
@$(MAKE) --no-print-directory pytest
@printf "$(GREEN)All pre-flight checks passed$(RESET)\n"
.PHONY: ruff
ruff: #-- Run ruff linter with automatic fixes
uv run --active --no-sync ruff check . --fix
.PHONY: clippy
clippy: #-- Run clippy linter (check only, workspace lints)
cargo clippy --all-targets --all-features -- -D warnings
.PHONY: clippy-fix
clippy-fix: #-- Run clippy linter with automatic fixes (workspace lints)
cargo clippy --fix --all-targets --all-features --allow-dirty --allow-staged -- -D warnings
.PHONY: clippy-fix-nightly
clippy-fix-nightly: #-- Run clippy linter with nightly toolchain and automatic fixes (workspace lints + additional strictness)
cargo +nightly clippy --fix --all-targets --all-features --allow-dirty --allow-staged -- -D warnings
.PHONY: clippy-pedantic-crate-%
clippy-pedantic-crate-%: #-- Run clippy linter for a specific Rust crate (usage: make clippy-crate-<crate_name>)
cargo clippy --all-targets --all-features -p $* -- -D warnings \
-W clippy::todo \
-W clippy::unwrap_used \
-W clippy::expect_used
#== Dependencies
.PHONY: outdated
outdated: check-edit-installed #-- Check for outdated dependencies
cargo upgrade --dry-run --incompatible
uv tree --outdated --depth 1 --all-groups
@printf "\n$(CYAN)Checking tool versions...$(RESET)\n"
@outdated_count=0; \
for tool in cargo-audit:$(CARGO_AUDIT_VERSION) cargo-deny:$(CARGO_DENY_VERSION) cargo-edit:$(CARGO_EDIT_VERSION) cargo-llvm-cov:$(CARGO_LLVM_COV_VERSION) cargo-machete:$(CARGO_MACHETE_VERSION) cargo-nextest:$(CARGO_NEXTEST_VERSION) cargo-vet:$(CARGO_VET_VERSION) lychee:$(LYCHEE_VERSION); do \
name=$${tool%%:*}; current=$${tool##*:}; \
latest=$$(cargo search $$name --limit 1 2>/dev/null | head -1 | awk -F\" '{print $$2}'); \
if [ "$$current" != "$$latest" ]; then \
printf "$(YELLOW) $$name: $$current → $$latest$(RESET)\n"; \
outdated_count=$$((outdated_count + 1)); \
fi; \
done; \
[ $$outdated_count -eq 0 ] && printf "$(GREEN) All tools up to date ✓$(RESET)\n"
.PHONY: update
update: cargo-update #-- Update all dependencies (cargo and uv)
uv self update && uv lock --upgrade
.PHONY: install-tools
install-tools: #-- Install required development tools (Rust tools from Cargo.toml, uv from uv-version)
cargo install cargo-deny --version $(CARGO_DENY_VERSION) --locked \
&& cargo install cargo-edit --version $(CARGO_EDIT_VERSION) --locked \
&& cargo install cargo-machete --version $(CARGO_MACHETE_VERSION) --locked \
&& cargo install cargo-nextest --version $(CARGO_NEXTEST_VERSION) --locked \
&& cargo install cargo-llvm-cov --version $(CARGO_LLVM_COV_VERSION) --locked \
&& cargo install cargo-audit --version $(CARGO_AUDIT_VERSION) --locked \
&& cargo install cargo-vet --version $(CARGO_VET_VERSION) --locked \
&& cargo install lychee --version $(LYCHEE_VERSION) --locked \
&& uv self update $(UV_VERSION)
#== Security
.PHONY: security-audit
security-audit: check-audit-installed #-- Run security audit for Rust dependencies (osv-scanner runs via pre-commit)
$(info $(M) Running security audit for Rust dependencies...)
@printf "$(CYAN)Checking Rust dependencies for known vulnerabilities...$(RESET)\n"
cargo audit --color never || true
@printf "\n$(CYAN)Note: Python dependency scanning (osv-scanner) runs via pre-commit hooks$(RESET)\n"
.PHONY: cargo-deny
cargo-deny: check-deny-installed #-- Run cargo-deny checks (advisories, sources, bans, licenses)
cargo deny --all-features check
.PHONY: cargo-vet
cargo-vet: check-vet-installed #-- Run cargo-vet supply chain audit
cargo vet
#== Documentation
.PHONY: docs
docs: docs-python docs-rust #-- Build all documentation (Python and Rust)
.PHONY: docs-python
docs-python: export BUILD_MODE=debug
docs-python: #-- Build Python documentation with Sphinx
uv run --active sphinx-build -M markdown ./docs/api_reference ./api_reference
.PHONY: docs-rust
docs-rust: export RUSTDOCFLAGS=--enable-index-page -Zunstable-options
docs-rust: #-- Build Rust documentation with cargo doc
cargo +nightly doc --all-features --no-deps --workspace
.PHONY: docsrs-check
docsrs-check: export RUSTDOCFLAGS=--cfg docsrs -D warnings
docsrs-check: check-hack-installed #-- Check documentation builds for docs.rs compatibility
cargo +nightly hack --workspace doc --no-deps --all-features
.PHONY: docs-check-links
docs-check-links: #-- Check for broken links in documentation (periodic audit)
$(info $(M) Checking documentation links...)
@lychee \
--verbose \
--no-progress \
--exclude-all-private \
--max-retries 3 \
--retry-wait-time 5 \
--timeout 30 \
--max-concurrency 10 \
--accept "100..=103,200..=299,429,502..=504" \
--exclude-file .lycheeignore \
"**/*.md"
@printf "$(GREEN)Link check passed$(RESET)\n"
#== Rust Development
.PHONY: cargo-build
cargo-build: #-- Build Rust crates in release mode
cargo build --release --all-features
.PHONY: cargo-update
cargo-update: #-- Update Rust dependencies (versions from Cargo.toml)
cargo update
.PHONY: cargo-check
cargo-check: #-- Check Rust code without building
cargo check --workspace --all-features
.PHONY: check-audit-installed
check-audit-installed: #-- Verify cargo-audit is installed
@if ! cargo audit --version >/dev/null 2>&1; then \
echo "cargo-audit is not installed. You can install it using 'cargo install cargo-audit'"; \
exit 1; \
fi
.PHONY: check-deny-installed
check-deny-installed: #-- Verify cargo-deny is installed
@if ! cargo deny --version >/dev/null 2>&1; then \
echo "cargo-deny is not installed. You can install it using 'cargo install cargo-deny'"; \
exit 1; \
fi
.PHONY: check-nextest-installed
check-nextest-installed: #-- Verify cargo-nextest is installed
@if ! cargo nextest --version >/dev/null 2>&1; then \
echo "cargo-nextest is not installed. You can install it using 'cargo install cargo-nextest'"; \
exit 1; \
fi
.PHONY: check-llvm-cov-installed
check-llvm-cov-installed: #-- Verify cargo-llvm-cov is installed
@if ! cargo llvm-cov --version >/dev/null 2>&1; then \
echo "cargo-llvm-cov is not installed. You can install it using 'cargo install cargo-llvm-cov'"; \
exit 1; \
fi
.PHONY: check-hack-installed
check-hack-installed: #-- Verify cargo-hack is installed
@if ! cargo hack --version >/dev/null 2>&1; then \
echo "cargo-hack is not installed. You can install it using 'cargo install cargo-hack'"; \
exit 1; \
fi
.PHONY: check-vet-installed
check-vet-installed: #-- Verify cargo-vet is installed
@if ! cargo vet --version >/dev/null 2>&1; then \
echo "cargo-vet is not installed. You can install it using 'cargo install cargo-vet'"; \
exit 1; \
fi
.PHONY: check-edit-installed
check-edit-installed: #-- Verify cargo-edit is installed
@if ! cargo upgrade --version >/dev/null 2>&1; then \
echo "cargo-edit is not installed. You can install it using 'cargo install cargo-edit'"; \
exit 1; \
fi
.PHONY: check-features #-- Verify crate feature combinations compile correctly
check-features: check-hack-installed
cargo hack check --each-feature
.PHONY: check-capnp-schemas #-- Verify Cap'n Proto schemas are up-to-date
check-capnp-schemas:
$(info $(M) Checking if Cap'n Proto schemas are up-to-date...)
@bash scripts/regen_capnp.sh > /dev/null 2>&1 || true
@DIFF_OUTPUT="$$(git diff -I\"ENCODED_NODE\" -- crates/serialization/generated/capnp)"; \
if [ -n "$$DIFF_OUTPUT" ]; then \
echo "$(RED)Error: Cap'n Proto generated files are out of date$(RESET)"; \
echo "Please run: ./scripts/regen_capnp.sh"; \
echo "Or: make regen-capnp"; \
exit 1; \
else \
echo "$(GREEN)✓ Cap'n Proto schemas are up-to-date$(RESET)"; \
fi
.PHONY: regen-capnp #-- Regenerate Cap'n Proto schema files
regen-capnp:
$(info $(M) Regenerating Cap'n Proto schemas...)
@bash scripts/regen_capnp.sh
#== Rust Testing
.PHONY: cargo-test
cargo-test: export RUST_BACKTRACE=1
cargo-test: check-nextest-installed
cargo-test: #-- Run all Rust tests (use EXTRA_FEATURES="feature1 feature2" or HYPERSYNC=true)
ifeq ($(VERBOSE),true)
$(info $(M) Running Rust tests with verbose output...)
cargo nextest run --workspace --features "$(CARGO_FEATURES)" $(FAIL_FAST_FLAG) --cargo-profile nextest --verbose
else
$(info $(M) Running Rust tests (showing summary and failures only)...)
cargo nextest run --workspace --features "$(CARGO_FEATURES)" $(FAIL_FAST_FLAG) --cargo-profile nextest --status-level fail --final-status-level flaky
endif
.PHONY: cargo-test-extras
cargo-test-extras: #-- Run all Rust tests with capnp and hypersync features (convenience shortcut)
$(MAKE) cargo-test EXTRA_FEATURES="capnp,hypersync"
.PHONY: cargo-test-lib
cargo-test-lib: export RUST_BACKTRACE=1
cargo-test-lib: check-nextest-installed
cargo-test-lib: #-- Run Rust library tests only with high precision
cargo nextest run --lib --workspace --no-default-features --features "ffi,python,high-precision,defi,stubs" $(FAIL_FAST_FLAG) --cargo-profile nextest
.PHONY: cargo-test-standard-precision
cargo-test-standard-precision: export RUST_BACKTRACE=1
cargo-test-standard-precision: check-nextest-installed
cargo-test-standard-precision: #-- Run Rust tests in debug mode with standard precision (64-bit)
cargo nextest run --workspace --features "ffi,python"
.PHONY: cargo-test-debug
cargo-test-debug: export RUST_BACKTRACE=1
cargo-test-debug: check-nextest-installed
cargo-test-debug: #-- Run Rust tests in debug mode with high precision
cargo nextest run --workspace --features "ffi,python,high-precision,defi" $(FAIL_FAST_FLAG)
.PHONY: cargo-test-coverage
cargo-test-coverage: check-nextest-installed check-llvm-cov-installed
cargo-test-coverage: #-- Run Rust tests with coverage reporting
cargo llvm-cov nextest run --workspace
# -----------------------------------------------------------------------------
# Library tests for a single crate
# -----------------------------------------------------------------------------
# Invoke as:
# make cargo-test-crate-<crate_name>
# Examples:
# make cargo-test-crate-nautilus-model
# make cargo-test-crate-nautilus-core FEATURES="python,ffi"
#
# This reuses the same flags as `cargo-test-lib` but targets only the specified
# crate by replacing `--workspace` with `-p <crate>`.
# To include specific features, use the FEATURES variable with comma-separated values.
# -----------------------------------------------------------------------------
.PHONY: cargo-test-crate-%
cargo-test-crate-%: export RUST_BACKTRACE=1
cargo-test-crate-%: check-nextest-installed
cargo-test-crate-%: #-- Run Rust tests for a specific crate (usage: make cargo-test-crate-<crate_name>)
cargo nextest run --lib $(FAIL_FAST_FLAG) --cargo-profile nextest -p $* $(if $(FEATURES),--features "$(FEATURES)")
.PHONY: cargo-test-coverage-crate-%
cargo-test-coverage-crate-%: export RUST_BACKTRACE=1
cargo-test-coverage-crate-%: check-nextest-installed check-llvm-cov-installed
cargo-test-coverage-crate-%: #-- Run Rust tests with coverage reporting for a specific crate (usage: make cargo-test-coverage-crate-<crate_name>)
cargo llvm-cov nextest --lib $(FAIL_FAST_FLAG) --cargo-profile nextest -p $* $(if $(FEATURES),--features "$(FEATURES)")
#------------------------------------------------------------------------------
# Benchmarks
#------------------------------------------------------------------------------
# List of crates whose criterion/iai benches run in the performance workflow
CI_BENCH_CRATES := nautilus-core nautilus-model nautilus-common nautilus-live
# NOTE:
# - We invoke `cargo bench` *once per crate* to avoid the well-known
# "mixed panic strategy" linker error that appears when crates which specify
# different `panic` strategies (e.g. `abort` for cdylib/staticlib targets vs
# `unwind` for Criterion) are linked into the *same* benchmark binary.
# - Cargo will still reuse compiled artifacts between iterations, so the cost
# of the extra invocations is marginal while the linker remains happy.
.PHONY: cargo-ci-benches
cargo-ci-benches: #-- Run Rust benches for the crates included in the CI performance workflow
@for crate in $(CI_BENCH_CRATES); do \
echo "Running benches for $$crate"; \
cargo bench -p $$crate --profile bench --benches --no-fail-fast; \
done
#== Docker
.PHONY: docker-build
docker-build: clean #-- Build Docker image for NautilusTrader
docker pull $(IMAGE_FULL) || docker pull $(IMAGE):nightly || true
docker build -f .docker/nautilus_trader.dockerfile --platform linux/x86_64 -t $(IMAGE_FULL) .
.PHONY: docker-build-force
docker-build-force: #-- Force rebuild Docker image without cache
docker build --no-cache -f .docker/nautilus_trader.dockerfile -t $(IMAGE_FULL) .
.PHONY: docker-push
docker-push: #-- Push Docker image to registry
docker push $(IMAGE_FULL)
.PHONY: docker-build-jupyter
docker-build-jupyter: #-- Build JupyterLab Docker image
docker build --build-arg GIT_TAG=$(GIT_TAG) -f .docker/jupyterlab.dockerfile --platform linux/x86_64 -t $(IMAGE):jupyter .
.PHONY: docker-push-jupyter
docker-push-jupyter: #-- Push JupyterLab Docker image to registry
docker push $(IMAGE):jupyter
.PHONY: init-services
init-services: #-- Initialize development services eg. for integration tests (start containers and setup database)
$(info $(M) Initializing development services...)
@$(MAKE) start-services
@printf "$(PURPLE)Waiting for PostgreSQL to be ready...$(RESET)\n"
@sleep 10
@$(MAKE) init-db
.PHONY: start-services
start-services: #-- Start development services (without reinitializing database)
$(info $(M) Starting development services...)
docker compose -f .docker/docker-compose.yml up -d
.PHONY: stop-services
stop-services: #-- Stop development services (preserves data)
$(info $(M) Stopping development services...)
docker compose -f .docker/docker-compose.yml down
.PHONY: purge-services
purge-services: #-- Purge all development services (stop containers and remove volumes)
$(info $(M) Purging integration test services...)
docker compose -f .docker/docker-compose.yml down -v
.PHONY: init-db
init-db: #-- Initialize PostgreSQL database schema
$(info $(M) Initializing PostgreSQL database schema...)
cat schema/sql/types.sql schema/sql/tables.sql schema/sql/functions.sql schema/sql/partitions.sql | docker exec -i nautilus-database psql -U nautilus -d nautilus
#== Python Testing
.PHONY: pytest
pytest: #-- Run Python tests with pytest in parallel with immediate failure reporting
$(info $(M) Running Python tests in parallel with immediate failure reporting...)
uv run --active --no-sync pytest --new-first --failed-first --tb=line -n logical --dist=loadgroup --maxfail=50 --durations=0 --durations-min=10.0
.PHONY: test-performance
test-performance: #-- Run performance tests with codspeed benchmarking
uv run --active --no-sync pytest tests/performance_tests --benchmark-disable-gc --codspeed
#== CLI Tools
.PHONY: install-cli
install-cli: #-- Install Nautilus CLI tool from source
cargo install --path crates/cli --bin nautilus --locked --force
#== Internal
.PHONY: help
help: #-- Show this help message and exit
@printf "NautilusTrader Makefile\n\n"
@printf "$(GRAY)Requires GNU Make. Windows users can install it via MSYS2 or WSL.$(RESET)\n\n"
@printf "$(GREEN)Usage:$(RESET) make $(CYAN)<target>$(RESET)\n\n"
@printf "$(GRAY)Tips: Use $(CYAN)make <target> V=1$(GRAY) for verbose output$(RESET)\n"
@printf "$(GRAY) Use $(CYAN)make <target> VERBOSE=false$(GRAY) to disable verbose output for build-debug and cargo-test$(RESET)\n\n"
@printf "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⣶⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣾⣿⣿⣿⠀⢸⣿⣿⣿⣿⣶⣶⣤⣀⠀⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⠀⠀⢀⣴⡇⢀⣾⣿⣿⣿⣿⣿⠀⣾⣿⣿⣿⣿⣿⣿⣿⠿⠓⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⠀⣰⣿⣿⡀⢸⣿⣿⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⠟⠁⣠⣄⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⢠⣿⣿⣿⣇⠀⢿⣿⣿⣿⣿⣿⠀⢻⣿⣿⣿⡿⢃⣠⣾⣿⣿⣧⡀⠀⠀\n"
@printf "⠀⠀⠀⠠⣾⣿⣿⣿⣿⣿⣧⠈⠋⢀⣴⣧⠀⣿⡏⢠⡀⢸⣿⣿⣿⣿⣿⣿⣿⡇⠀\n"
@printf "⠀⠀⠀⣀⠙⢿⣿⣿⣿⣿⣿⠇⢠⣿⣿⣿⡄⠹⠃⠼⠃⠈⠉⠛⠛⠛⠛⠛⠻⠇⠀\n"
@printf "⠀⠀⢸⡟⢠⣤⠉⠛⠿⢿⣿⠀⢸⣿⡿⠋⣠⣤⣄⠀⣾⣿⣿⣶⣶⣶⣦⡄⠀⠀⠀\n"
@printf "⠀⠀⠸⠀⣾⠏⣸⣷⠂⣠⣤⠀⠘⢁⣴⣾⣿⣿⣿⡆⠘⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⠛⠀⣿⡟⠀⢻⣿⡄⠸⣿⣿⣿⣿⣿⣿⣿⡀⠘⣿⣿⣿⣿⠟⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⠀⠀⣿⠇⠀⠀⢻⡿⠀⠈⠻⣿⣿⣿⣿⣿⡇⠀⢹⣿⠿⠋⠀⠀⠀⠀⠀\n"
@printf "⠀⠀⠀⠀⠀⠀⠋⠀⠀⠀⡘⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀\n"
@awk '\
BEGIN { \
FS = ":.*#--"; \
target_maxlen = 0; \
GREEN = "\033[0;32m"; \
CYAN = "\033[0;36m"; \
RESET = "\033[0m"; \
} \
/^[$$()% a-zA-Z_-]+:.*?#--/ { \
if (length($$1) > target_maxlen) target_maxlen = length($$1); \
targets[NR] = $$1; descriptions[NR] = $$2; \
} \
/^#==/ { \
groups[NR] = substr($$0, 5); \
} \
END { \
for (i = 1; i <= NR; i++) { \
if (groups[i]) { \
printf "\n" GREEN "%s:" RESET "\n", groups[i]; \
} else if (targets[i]) { \
printf " " CYAN "%-*s" RESET " %s\n", target_maxlen, targets[i], descriptions[i]; \
} \
} \
}' $(MAKEFILE_LIST)