Skip to content

Commit 9ff15db

Browse files
committed
build: rebuild the NIF when libmlx.a or the Makefile changes
The object rule depended only on c_src sources/headers and $(NIF_SO) only on the objects, so neither an MLX version bump (a freshly built libmlx.a under a new MLX_LIB_DIR) nor a compile/link flag change here forced a rebuild. An existing checkout could copy the new mlx.metallib while keeping a NIF still statically linked against the old MLX, running a mismatched binary until a manual clean. Add libmlx.a and the Makefile as prerequisites of the objects, the linked NIF, and the native bench.
1 parent b3977f5 commit 9ff15db

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ BENCH_NATIVE_SRC := bench/native/compile_microbench.cpp
6464
BENCH_NATIVE_BIN := $(BUILD_DIR)/compile_microbench
6565
BENCH_NATIVE_METALLIB := $(BUILD_DIR)/mlx.metallib
6666

67-
$(BENCH_NATIVE_BIN): $(BENCH_NATIVE_SRC) | $(BUILD_DIR)
67+
$(BENCH_NATIVE_BIN): $(BENCH_NATIVE_SRC) $(MLX_LIB_DIR)/libmlx.a Makefile | $(BUILD_DIR)
6868
$(CXX) -std=c++20 -O3 -Wall -Wextra \
6969
-isystem $(MLX_INCLUDE_DIR) \
7070
$(BENCH_NATIVE_SRC) \
@@ -88,11 +88,18 @@ $(BUILD_DIR):
8888
$(PRIV_DIR):
8989
@mkdir -p $(PRIV_DIR)
9090

91-
$(BUILD_DIR)/%.o: c_src/%.cpp $(HEADERS) | $(BUILD_DIR)
91+
# Objects and the linked NIF also depend on libmlx.a and this Makefile so an
92+
# existing checkout rebuilds when the MLX build changes (a version bump
93+
# repoints MLX_LIB_DIR at a freshly built, newer libmlx.a whose headers these
94+
# objects include) or when a compile/link flag here changes (e.g. the C++
95+
# standard). Without these, `make` can copy the new mlx.metallib while leaving
96+
# a stale NIF statically linked against the old MLX in place — a mismatched
97+
# binary until a manual clean.
98+
$(BUILD_DIR)/%.o: c_src/%.cpp $(HEADERS) $(MLX_LIB_DIR)/libmlx.a Makefile | $(BUILD_DIR)
9299
@mkdir -p $(dir $@)
93100
$(CXX) $(CXXFLAGS) -c $< -o $@
94101

95-
$(NIF_SO): $(OBJECTS) | $(PRIV_DIR)
102+
$(NIF_SO): $(OBJECTS) $(MLX_LIB_DIR)/libmlx.a Makefile | $(PRIV_DIR)
96103
$(CXX) $(OBJECTS) -o $(NIF_SO) $(LDFLAGS)
97104

98105
# MLX searches for mlx.metallib colocated with the loaded binary

0 commit comments

Comments
 (0)