@@ -200,6 +200,57 @@ def build_xoshiro(env):
200200 env .exposed_includes += env .xoshiro ["INCPATH" ]
201201
202202
203+ def build_type_safe (env ):
204+ import os
205+
206+ arithmetic_policy = 1
207+ if "TYPE_SAFE_ARITHMETIC_POLICY" in os .environ :
208+ arithmetic_policy = os .environ ["TYPE_SAFE_ARITHMETIC_POLICY" ].upper ().replace (" " , "_" )
209+ if arithmetic_policy not in [
210+ "ub" ,
211+ "undefined_behavior" ,
212+ "undefined" ,
213+ "checked" ,
214+ "default" ,
215+ "0" ,
216+ "1" ,
217+ "2" ,
218+ ]:
219+ print ("TYPE_SAFE_ARITHMETIC_POLICY can only be undefined, checked, or default" )
220+ exit (255 )
221+ match arithmetic_policy :
222+ case "default" :
223+ arithmetic_policy = 0
224+ case "ub" , "undefined_behavior" , "undefined" :
225+ arithmetic_policy = 1
226+ case "checked" :
227+ arithmetic_policy = 2
228+ case "0" , "1" , "2" :
229+ arithmetic_policy = int (arithmetic_policy )
230+ elif env ["dev_build" ]:
231+ arithmetic_policy = 2
232+
233+ env .Append (
234+ CPPDEFINES = [
235+ ("TYPE_SAFE_ENABLE_ASSERTIONS" , 1 if env ["target" ] == "template_release" else 0 ),
236+ ("TYPE_SAFE_ENABLE_PRECONDITION_CHECKS" , 1 ),
237+ ("TYPE_SAFE_ENABLE_WRAPPER" , 1 if env ["target" ] == "template_release" else 0 ),
238+ ("TYPE_SAFE_ARITHMETIC_POLICY" , arithmetic_policy ),
239+ ]
240+ )
241+
242+ include_path = "type_safe/include"
243+ debug_assert_include_path = "type_safe/external/debug_assert"
244+ env .type_safe = {}
245+ env .type_safe ["INCPATH" ] = [env .Dir (include_path ), env .Dir (debug_assert_include_path )]
246+ env .Append (CPPPATH = env .type_safe ["INCPATH" ])
247+ if env .get ("is_msvc" , False ):
248+ env .Append (CXXFLAGS = ["/external:I" , env .type_safe ["INCPATH" ][0 ], "/external:W0" ])
249+ else :
250+ env .Append (CXXFLAGS = ["-isystem" , env .type_safe ["INCPATH" ][0 ]])
251+ env .exposed_includes += env .type_safe ["INCPATH" ]
252+
253+
203254def link_tbb (env ):
204255 import sys
205256
@@ -216,4 +267,5 @@ build_std_function(env)
216267build_memory (env )
217268build_spdlog (env )
218269build_xoshiro (env )
270+ build_type_safe (env )
219271link_tbb (env )
0 commit comments