Skip to content

Commit d51f0fd

Browse files
twitucjdsellers
andauthored
Implement high-precision 128-bit value types (#2072)
Co-authored-by: Chris Sellers <[email protected]> RFC #2084
1 parent e284162 commit d51f0fd

File tree

139 files changed

+3618
-2215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+3618
-2215
lines changed

.github/workflows/build.yml

Lines changed: 179 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ jobs:
8181
- name: Run pre-commit
8282
continue-on-error: true
8383
run: |
84-
pre-commit run --all-files
84+
pre-commit run --all-files || echo "PRECOMMIT_FAILED=true" > $GITHUB_ENV
8585
8686
- name: Add PR comment on failure
87-
if: failure() && github.event_name == 'pull_request'
87+
if: env.PRECOMMIT_FAILED == 'true' && github.event_name == 'pull_request'
8888
uses: actions/github-script@v7
8989
with:
9090
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -95,11 +95,185 @@ jobs:
9595
})
9696
9797
- name: Fail job if pre-commit failed
98-
if: failure()
98+
if: env.PRECOMMIT_FAILED == 'true'
9999
run: |
100100
echo "Pre-commit checks failed, exiting"
101101
exit 1
102102
103+
build-linux-low-precision:
104+
strategy:
105+
fail-fast: false
106+
matrix:
107+
os: [ubuntu-latest]
108+
python-version: ["3.12"]
109+
defaults:
110+
run:
111+
shell: bash
112+
name: build low-precision (${{ matrix.os }})
113+
runs-on: ${{ matrix.os }}
114+
needs: [pre-commit]
115+
env:
116+
BUILD_MODE: debug
117+
HIGH_PRECISION: false
118+
RUST_BACKTRACE: 1
119+
# > --------------------------------------------------
120+
# > sccache
121+
# https://github.com/Mozilla-Actions/sccache-action
122+
SCCACHE_IDLE_TIMEOUT: 0
123+
SCCACHE_DIRECT: "true"
124+
SCCACHE_CACHE_MULTIARCH: 1
125+
SCCACHE_DIR: ${{ github.workspace }}/.cache/sccache
126+
RUSTC_WRAPPER: "sccache"
127+
CC: "sccache clang"
128+
CXX: "sccache clang++"
129+
# Incrementally compiled crates cannot be cached by sccache
130+
# https://github.com/mozilla/sccache#rust
131+
CARGO_INCREMENTAL: 0
132+
# > --------------------------------------------------
133+
134+
services:
135+
redis:
136+
image: redis
137+
ports:
138+
- 6379:6379
139+
options: >-
140+
--health-cmd "redis-cli ping"
141+
--health-interval 10s
142+
--health-timeout 5s
143+
--health-retries 5
144+
postgres:
145+
image: postgres
146+
env:
147+
POSTGRES_USER: postgres
148+
POSTGRES_PASSWORD: pass
149+
POSTGRES_DB: nautilus
150+
ports:
151+
- 5432:5432
152+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
153+
154+
steps:
155+
# - name: Free disk space # Continue to monitor
156+
# uses: jlumbroso/free-disk-space@main
157+
# with:
158+
# tool-cache: true
159+
# android: false
160+
# dotnet: false
161+
# haskell: false
162+
# large-packages: true
163+
# docker-images: true
164+
# swap-storage: true
165+
166+
- name: Install runner dependencies
167+
run: sudo apt-get install -y curl clang git libssl-dev make pkg-config
168+
169+
- name: Checkout repository
170+
uses: actions/checkout@v4
171+
172+
- name: Set up Rust toolchain
173+
run: |
174+
rustup toolchain add --profile minimal stable --component clippy,rustfmt
175+
176+
- name: Set up Python environment
177+
uses: actions/setup-python@v5
178+
with:
179+
python-version: ${{ matrix.python-version }}
180+
181+
- name: Get Python version
182+
run: |
183+
version=$(bash scripts/python-version.sh)
184+
echo "PYTHON_VERSION=$version" >> $GITHUB_ENV
185+
186+
- name: Get Poetry version from poetry-version
187+
run: |
188+
version=$(cat poetry-version)
189+
echo "POETRY_VERSION=$version" >> $GITHUB_ENV
190+
191+
- name: Install Poetry
192+
uses: snok/install-poetry@v1
193+
with:
194+
version: ${{ env.POETRY_VERSION }}
195+
196+
- name: Install build dependencies
197+
run: python -m pip install --upgrade pip setuptools wheel poetry-plugin-export pre-commit msgspec
198+
199+
- name: Cached sccache
200+
id: cached-sccache
201+
uses: actions/cache@v4
202+
with:
203+
path: ${{ env.SCCACHE_DIR }}
204+
key: sccache-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ hashFiles('**/Cargo.lock', '**/poetry.lock') }}
205+
restore-keys: |
206+
sccache-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-
207+
sccache-${{ runner.os }}-${{ github.workflow }}-
208+
sccache-${{ runner.os }}-
209+
210+
- name: Run sccache
211+
uses: mozilla-actions/[email protected]
212+
213+
- name: Cached cargo
214+
id: cached-cargo
215+
uses: actions/cache@v4
216+
with:
217+
path: |
218+
~/.cargo/bin/
219+
~/.cargo/registry/index/
220+
~/.cargo/registry/cache/
221+
~/.cargo/git/db/
222+
target/
223+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
224+
restore-keys: ${{ runner.os }}-cargo-
225+
226+
- name: Cache Python site-packages
227+
id: cached-site-packages
228+
uses: actions/cache@v4
229+
with:
230+
path: ~/.local/lib/python${{ matrix.python-version }}/site-packages
231+
key: ${{ runner.os }}-${{ matrix.python-version }}-site-packages
232+
restore-keys: |
233+
${{ runner.os }}-site-packages-
234+
235+
- name: Cached test data
236+
id: cached-testdata-large
237+
uses: actions/cache@v4
238+
with:
239+
path: tests/test_data/large
240+
key: ${{ runner.os }}-large-files-${{ hashFiles('tests/test_data/large/checksums.json') }}
241+
restore-keys: ${{ runner.os }}-large-files-
242+
243+
- name: Install Nautilus CLI and run init postgres
244+
run: |
245+
make install-cli
246+
nautilus database init --schema ${{ github.workspace }}/schema
247+
env:
248+
POSTGRES_HOST: localhost
249+
POSTGRES_PORT: 5432
250+
POSTGRES_USERNAME: postgres
251+
POSTGRES_PASSWORD: pass
252+
POSTGRES_DATABASE: nautilus
253+
254+
- name: Install cargo-nextest
255+
uses: taiki-e/install-action@v2
256+
with:
257+
tool: nextest
258+
259+
- name: Run nautilus_core tests
260+
run: |
261+
make cargo-test-low-precision
262+
263+
- name: Build Python wheel
264+
run: |
265+
poetry build --format wheel
266+
ls -lh dist/
267+
268+
- name: Install Python wheel
269+
run: |
270+
poetry export --with test --all-extras --format requirements.txt --output requirements-test.txt
271+
python -m pip install -r requirements-test.txt
272+
pip install "$(ls dist/*.whl)"
273+
274+
- name: Run tests
275+
run: pytest --ignore=tests/performance_tests
276+
103277
build-linux:
104278
strategy:
105279
fail-fast: false
@@ -525,6 +699,8 @@ jobs:
525699
needs: [pre-commit]
526700
env:
527701
BUILD_MODE: debug # Not building wheels, so debug is fine
702+
HIGH_PRECISION: false
703+
PARALLEL_BUILD: false
528704
RUST_BACKTRACE: 1
529705
# > --------------------------------------------------
530706
# > sccache
@@ -627,8 +803,6 @@ jobs:
627803
run: |
628804
poetry install --with test --all-extras
629805
poetry run pytest --ignore=tests/performance_tests
630-
env:
631-
PARALLEL_BUILD: false
632806
633807
publish-wheels:
634808
name: publish-packages

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ cargo-test:
9999
echo "cargo-nextest is not installed. You can install it using 'cargo install cargo-nextest'"; \
100100
exit 1; \
101101
fi
102-
RUST_BACKTRACE=1 && (cd nautilus_core && cargo nextest run --workspace)
102+
RUST_BACKTRACE=1 && (cd nautilus_core && cargo nextest run --workspace --features "python,ffi,high-precision")
103+
104+
105+
.PHONY: cargo-test-low-precision
106+
cargo-test-low-precision:
107+
@if ! cargo nextest --version >/dev/null 2>&1; then \
108+
echo "cargo-nextest is not installed. You can install it using 'cargo install cargo-nextest'"; \
109+
exit 1; \
110+
fi
111+
RUST_BACKTRACE=1 && (cd nautilus_core && cargo nextest run --workspace --features "python,ffi")
112+
103113

104114
.PHONY: cargo-test-coverage
105115
cargo-test-coverage:

build.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
# If ANNOTATION mode is enabled, generate an annotated HTML version of the input source files
3030
ANNOTATION_MODE = bool(os.getenv("ANNOTATION_MODE", ""))
3131
# If PARALLEL build is enabled, uses all CPUs for compile stage of build
32-
PARALLEL_BUILD = os.getenv("PARALLEL_BUILD", "true") == "true"
32+
PARALLEL_BUILD = os.getenv("PARALLEL_BUILD", "true").lower() == "true"
3333
# If COPY_TO_SOURCE is enabled, copy built *.so files back into the source tree
34-
COPY_TO_SOURCE = os.getenv("COPY_TO_SOURCE", "true") == "true"
34+
COPY_TO_SOURCE = os.getenv("COPY_TO_SOURCE", "true").lower() == "true"
3535
# If PyO3 only then don't build C extensions to reduce compilation time
36-
PYO3_ONLY = os.getenv("PYO3_ONLY", "") != ""
36+
PYO3_ONLY = os.getenv("PYO3_ONLY", "").lower() != ""
37+
# If high-precision mode is enabled (value types use 128-bit integers, rather than 64-bit)
38+
HIGH_PRECISION = os.getenv("HIGH_PRECISION", "true").lower() == "true"
3739

3840
if PROFILE_MODE:
3941
# For subsequent debugging, the C source needs to be in the same tree as
@@ -99,11 +101,17 @@ def _build_rust_libs() -> None:
99101

100102
build_options = " --release" if BUILD_MODE == "release" else ""
101103

104+
if HIGH_PRECISION:
105+
features = ["--all-features"]
106+
else:
107+
# Enable features needed for main build, but not high_precision
108+
features = ["--features", "ffi,python,extension-module"]
109+
102110
cmd_args = [
103111
"cargo",
104112
"build",
105113
*build_options.split(),
106-
"--all-features",
114+
*features,
107115
]
108116

109117
if RUST_TOOLCHAIN == "nightly":
@@ -132,8 +140,6 @@ def _build_rust_libs() -> None:
132140
Options.annotate = ANNOTATION_MODE # Create annotated HTML files for each .pyx
133141
if ANNOTATION_MODE:
134142
Options.annotate_coverage_xml = "coverage.xml"
135-
Options.warning_errors = True # Treat compiler warnings as errors
136-
Options.extra_warnings = True
137143

138144
CYTHON_COMPILER_DIRECTIVES = {
139145
"language_level": "3",
@@ -145,6 +151,12 @@ def _build_rust_libs() -> None:
145151
"warn.maybe_uninitialized": True,
146152
}
147153

154+
# TODO: Temporarily separate Cython configuration while we require v3.0.11 for coverage
155+
if cython_compiler_version == "3.1.0a1":
156+
Options.warning_errors = True # Treat compiler warnings as errors
157+
Options.extra_warnings = True
158+
CYTHON_COMPILER_DIRECTIVES["warn.deprecated.IF"] = False
159+
148160

149161
def _build_extensions() -> list[Extension]:
150162
# Regarding the compiler warning: #warning "Using deprecated NumPy API,
@@ -371,6 +383,7 @@ def build() -> None:
371383
print(f"PARALLEL_BUILD={PARALLEL_BUILD}")
372384
print(f"COPY_TO_SOURCE={COPY_TO_SOURCE}")
373385
print(f"PYO3_ONLY={PYO3_ONLY}")
386+
print(f"HIGH_PRECISION={HIGH_PRECISION}")
374387
print(f"CC={os.environ['CC']}") if "CC" in os.environ else None
375388
print(f"CXX={os.environ['CXX']}") if "CXX" in os.environ else None
376389
print(f"LDSHARED={os.environ['LDSHARED']}") if "LDSHARED" in os.environ else None

nautilus_core/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nautilus_core/adapters/databento/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ rstest = { workspace = true }
4242
tracing-test = { workspace = true }
4343

4444
[features]
45-
default = ["python"]
45+
default = ["python", "nautilus-core/ffi"]
4646
extension-module = [
4747
"pyo3/extension-module",
4848
"nautilus-core/extension-module",

0 commit comments

Comments
 (0)