4848 os .path .join ("plugin" , "torch" , "flagcx" , "src" , "utils_flagcx.cpp" ),
4949]
5050
51+ VENDORED_JSON_INCLUDE_DIR = os .path .join (
52+ ROOT_DIR , "third-party" , "json" , "single_include"
53+ )
54+ JSON_INCLUDE_DIR = os .environ .get ("JSON_INCLUDE_DIR" ) or VENDORED_JSON_INCLUDE_DIR
55+
5156include_dirs = [
5257 os .path .join (PLUGIN_DIR , "flagcx" , "include" ),
5358 os .path .join (ROOT_DIR , "flagcx" , "include" ),
54- os . path . join ( ROOT_DIR , "third-party" , "json" , "single_include" ) ,
59+ JSON_INCLUDE_DIR ,
5560]
5661
5762# Will be updated in build_ext to point at the built libflagcx.so
7782if BuildExtension is not None :
7883 class BuildExtWithMake (BuildExtension ):
7984 def build_extensions (self ):
80- # -- Step 0: Ensure git submodules are initialized --
81- submodule_marker = os .path .join (
82- ROOT_DIR , "third-party" , "json" , "single_include"
83- )
84- if not os .path .isdir (submodule_marker ):
85+ # -- Step 0: Resolve nlohmann-json headers --
86+ json_header = os .path .join (JSON_INCLUDE_DIR , "nlohmann" , "json.hpp" )
87+ if (
88+ JSON_INCLUDE_DIR == VENDORED_JSON_INCLUDE_DIR
89+ and not os .path .isfile (json_header )
90+ ):
8591 print ("[flagcx] Initializing git submodules ..." )
8692 subprocess .check_call (
8793 ["git" , "submodule" , "update" , "--init" , "--recursive" ],
8894 cwd = ROOT_DIR ,
8995 )
96+ if not os .path .isfile (json_header ):
97+ raise RuntimeError (
98+ f"nlohmann/json.hpp not found under JSON_INCLUDE_DIR={ JSON_INCLUDE_DIR } "
99+ )
90100
91101 # -- Step 1: Build libflagcx.so via make --
92102 build_dir = os .path .join (ROOT_DIR , "build" )
93103 lib_dir = os .path .join (build_dir , "lib" )
94104
95- make_args = [f"BUILDDIR={ build_dir } " , f"{ adaptor_make_flag } =1" ]
105+ make_args = [
106+ f"BUILDDIR={ build_dir } " ,
107+ f"{ adaptor_make_flag } =1" ,
108+ f"JSON_INCLUDE_DIR={ JSON_INCLUDE_DIR } " ,
109+ ]
96110
97111 # Forward additional env vars to make
98112 env_to_make = [
@@ -185,4 +199,4 @@ def build_extensions(self):
185199 ext_modules = ext_modules ,
186200 cmdclass = cmdclass ,
187201 entry_points = {"torch.backends" : ["flagcx = flagcx:init" ]},
188- )
202+ )
0 commit comments