Skip to content

Commit ac4a9f2

Browse files
authored
[CICD] Use system nlohmann-json (#530)
1 parent e3e8ca0 commit ac4a9f2

5 files changed

Lines changed: 35 additions & 23 deletions

File tree

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ BUILD_INCDIR := $(BUILDDIR)/include
226226
PREFIX ?= /usr/local
227227
DESTDIR ?= $(PREFIX)/lib
228228
INC_DESTDIR ?= $(PREFIX)/include
229+
# Source builds use the submodule; distro builds override this with /usr/include.
230+
JSON_INCLUDE_DIR ?= $(abspath third-party/json/single_include)
229231

230232
# Public headers exported alongside libflagcx.so
231233
PUBLIC_HEADERS := \
@@ -242,7 +244,7 @@ INCLUDEDIR := \
242244
$(abspath flagcx/runner/include) \
243245
$(abspath flagcx/core/include) \
244246
$(abspath flagcx/service/include) \
245-
$(abspath third-party/json/single_include)
247+
$(JSON_INCLUDE_DIR)
246248

247249
# Append NVSHMEM include path (must come after INCLUDEDIR := assignment)
248250
ifeq ($(USE_SHMEM), 1)

packaging/debian/control

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Build-Depends: debhelper-compat (= 13),
66
g++ (>= 9),
77
make,
88
cmake,
9+
nlohmann-json3-dev,
910
patchelf
1011
Standards-Version: 4.6.0
1112
Homepage: https://github.com/flagos-ai/FlagCX
@@ -21,8 +22,8 @@ X-Build-Environment: This package is designed to be built in backend-specific
2122
- MetaX backend: Requires maca_sdk (from repos.metax-tech.com)
2223
Built in Ubuntu 22.04 with MetaX APT repository configured
2324
.
24-
The Build-Depends listed above are for the Debian packaging tools only.
25-
Backend-specific dependencies are provided by the container environment.
25+
Common build dependencies are declared above. Backend-specific dependencies
26+
are provided by the container environment.
2627

2728
Package: libflagcx-metax
2829
Build-Profiles: <!pkg.flagcx.nvidia-only>

packaging/debian/rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export DH_VERBOSE = 1
66
# Usage: FLAGCX_BUILD_BACKEND=metax dpkg-buildpackage ...
77
# Valid values: metax, nvidia, all (default)
88
FLAGCX_BUILD_BACKEND ?= all
9+
# Distro packages build against nlohmann-json3-dev, not the git submodule.
10+
JSON_INCLUDE_DIR ?= /usr/include
11+
export JSON_INCLUDE_DIR
912

1013
# Build directories for different backends
1114
BUILD_DIR_METAX = $(CURDIR)/build-metax

packaging/rpm/specs/flagcx.spec

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,12 @@ BuildRequires: make
3535
BuildRequires: cmake
3636
BuildRequires: patchelf
3737
# nlohmann-json package name varies by distro:
38-
# - RHEL/Rocky 8 (via EPEL): json-devel
39-
# - RHEL/Rocky 9 (via EPEL): nlohmann-json-devel
40-
# - OpenEuler / others: nlohmann-json-devel (fallback)
41-
# TODO: verify Rocky 9 / RHEL 9 build path end-to-end; the EPEL 9 package
42-
# name is nlohmann-json-devel, but this has only been smoke-tested.
43-
%if 0%{?rhel} == 8
38+
# - Fedora and RHEL/Rocky 8/9 (via EPEL): json-devel
39+
# - openEuler: nlohmann-json-devel
40+
%if 0%{?fedora} || 0%{?rhel}
4441
BuildRequires: json-devel
4542
%else
46-
%if 0%{?rhel} >= 9
4743
BuildRequires: nlohmann-json-devel
48-
%else
49-
# Non-RHEL (OpenEuler, etc.) – assume upstream nlohmann-json-devel package name.
50-
BuildRequires: nlohmann-json-devel
51-
%endif
5244
%endif
5345

5446
%description
@@ -80,7 +72,7 @@ Development files (headers and libraries) for libflagcx-%{backend}.
8072
%setup -q
8173

8274
%build
83-
make USE_%{backend_upper}=1 PREFIX=%{_prefix}
75+
make USE_%{backend_upper}=1 PREFIX=%{_prefix} JSON_INCLUDE_DIR=%{_includedir}
8476

8577
%install
8678
rm -rf %{buildroot}

setup.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@
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+
5156
include_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
@@ -77,22 +82,31 @@
7782
if 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

Comments
 (0)