Skip to content

Commit fcff5d1

Browse files
committed
build: compile the NIF as C++20 to match MLX 0.32
MLX 0.32.0 sets `CMAKE_CXX_STANDARD 20` (REQUIRED), so libmlx.a is built as C++20 and its public headers use C++20 features — e.g. a defaulted `operator==` on `CompileOptions` in mlx/backend/common/metal_kernel.h, reachable via <mlx/fast.h>. The NIF includes those headers and statically links those objects, so build it at the same language level to stay ABI/ODR-consistent with the library. Raises both `-std=c++17` sites in the Makefile (the NIF objects and the standalone native bench binary) to `-std=c++20`.
1 parent 0c4a332 commit fcff5d1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ HEADERS := $(shell find c_src \( -name '*.h' -o -name '*.hpp' \))
1010
OBJECTS := $(patsubst c_src/%.cpp,$(BUILD_DIR)/%.o,$(SOURCES))
1111

1212
# Flags
13-
CXXFLAGS := -std=c++17 -O3 -fPIC -fvisibility=hidden -Wall -Wextra
13+
#
14+
# C++20 to match MLX itself: as of 0.32.0 MLX sets `CMAKE_CXX_STANDARD 20`
15+
# (REQUIRED), so libmlx.a is compiled as C++20 and its public headers use
16+
# C++20 features (e.g. a defaulted `operator==` on `CompileOptions` in
17+
# mlx/backend/common/metal_kernel.h, reachable via <mlx/fast.h>). We include
18+
# those headers and statically link those objects, so we build the NIF at the
19+
# same language level to stay ABI/ODR-consistent with the library.
20+
CXXFLAGS := -std=c++20 -O3 -fPIC -fvisibility=hidden -Wall -Wextra
1421
CXXFLAGS += -I$(ERTS_INCLUDE_DIR) -Ic_src
1522
# Third-party headers: use -isystem so warnings inside them (e.g. MLX's
1623
# -Wdeprecated-copy on _MLX_BFloat16) don't clutter our builds or trip
@@ -58,7 +65,7 @@ BENCH_NATIVE_BIN := $(BUILD_DIR)/compile_microbench
5865
BENCH_NATIVE_METALLIB := $(BUILD_DIR)/mlx.metallib
5966

6067
$(BENCH_NATIVE_BIN): $(BENCH_NATIVE_SRC) | $(BUILD_DIR)
61-
$(CXX) -std=c++17 -O3 -Wall -Wextra \
68+
$(CXX) -std=c++20 -O3 -Wall -Wextra \
6269
-isystem $(MLX_INCLUDE_DIR) \
6370
$(BENCH_NATIVE_SRC) \
6471
$(MLX_LIB_DIR)/libmlx.a \

0 commit comments

Comments
 (0)