41
41
COPY_TO_SOURCE = os .getenv ("COPY_TO_SOURCE" , "true" ).lower () == "true"
42
42
# If PyO3 only then don't build C extensions to reduce compilation time
43
43
PYO3_ONLY = os .getenv ("PYO3_ONLY" , "" ).lower () != ""
44
+ # If dry run only print the commands that would be executed
45
+ DRY_RUN = bool (os .getenv ("DRY_RUN" , "" ))
44
46
45
47
# Precision mode configuration
46
48
# https://nautilustrader.io/docs/nightly/getting_started/installation#precision-mode
120
122
RUST_LIBS : list [str ] = [str (path ) for path in RUST_LIB_PATHS ]
121
123
122
124
125
+ def _set_feature_flags () -> list [str ]:
126
+ if HIGH_PRECISION :
127
+ return ["--all-features" ]
128
+ else :
129
+ return ["--features" , "ffi,python,extension-module" ]
130
+
131
+
123
132
def _build_rust_libs () -> None :
124
133
print ("Compiling Rust libraries..." )
125
134
@@ -130,11 +139,7 @@ def _build_rust_libs() -> None:
130
139
131
140
build_options = " --release" if BUILD_MODE == "release" else ""
132
141
133
- if HIGH_PRECISION :
134
- features = ["--all-features" ]
135
- else :
136
- # Enable features needed for main build, but not high_precision
137
- features = ["--features" , "ffi,python,extension-module" ]
142
+ features = _set_feature_flags ()
138
143
139
144
cmd_args = [
140
145
"cargo" ,
@@ -372,6 +377,38 @@ def _strip_unneeded_symbols() -> None:
372
377
raise RuntimeError (f"Error when stripping symbols.\n { e } " ) from e
373
378
374
379
380
+ def show_rustanalyzer_settings () -> None :
381
+ """
382
+ Show appropriate vscode settings for the build.
383
+ """
384
+ import json
385
+
386
+ # Set environment variables
387
+ settings : dict [str , object ] = {}
388
+ for key in [
389
+ "rust-analyzer.check.extraEnv" ,
390
+ "rust-analyzer.runnables.extraEnv" ,
391
+ "rust-analyzer.cargo.features" ,
392
+ ]:
393
+ settings [key ] = {
394
+ "CC" : os .environ ["CC" ],
395
+ "CXX" : os .environ ["CXX" ],
396
+ "VIRTUAL_ENV" : os .environ ["VIRTUAL_ENV" ],
397
+ }
398
+
399
+ # Set features
400
+ features = _set_feature_flags ()
401
+ if features [0 ] == "--all-features" :
402
+ settings ["rust-analyzer.cargo.features" ] = "all"
403
+ settings ["rust-analyzer.check.features" ] = "all"
404
+ else :
405
+ settings ["rust-analyzer.cargo.features" ] = features [1 ].split ("," )
406
+ settings ["rust-analyzer.check.features" ] = features [1 ].split ("," )
407
+
408
+ print ("Set these rust analyzer settings in .vscode/settings.json" )
409
+ print (json .dumps (settings , indent = 2 ))
410
+
411
+
375
412
def build () -> None :
376
413
"""
377
414
Construct the extensions and distribution.
@@ -435,9 +472,14 @@ def print_env_var_if_exists(key: str) -> None:
435
472
print_env_var_if_exists ("LDFLAGS" )
436
473
print_env_var_if_exists ("LD_LIBRARY_PATH" )
437
474
print_env_var_if_exists ("RUSTFLAGS" )
438
-
439
- print ("\n Starting build..." )
440
- ts_start = dt .datetime .now (dt .UTC )
441
- build ()
442
- print (f"Build time: { dt .datetime .now (dt .UTC ) - ts_start } " )
443
- print ("\033 [32m" + "Build completed" + "\033 [0m" )
475
+ print_env_var_if_exists ("DRY_RUN" )
476
+
477
+ if DRY_RUN :
478
+ print ("Dry run" )
479
+ show_rustanalyzer_settings ()
480
+ else :
481
+ print ("\n Starting build..." )
482
+ ts_start = dt .datetime .now (dt .UTC )
483
+ build ()
484
+ print (f"Build time: { dt .datetime .now (dt .UTC ) - ts_start } " )
485
+ print ("\033 [32m" + "Build completed" + "\033 [0m" )
0 commit comments