Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

make: write .build-config through printf on GNU Make 3.x (#1732)

JustVuggb6fbb6555bf3
diff --git a/c/Makefile b/c/Makefile
index 258212e2..b3b61716 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -771,8 +771,17 @@ ifneq "$(BUILD_CONFIG)" "$(BUILD_CONFIG_OLD)"
# cmd.exe, so `make glm.exe` from the VS Native Tools prompt or with scoop MinGW
# (neither ships sh.exe) failed with "'printf' is not recognized" and left the
# stamp stale. $(file ...) works regardless of the shell make falls back to. (#478)
+#
+# GNU Make 3.81 -- /usr/bin/make on macOS -- has no $(file ...): it expands to
+# nothing, the stamp is never written, and every build relinks (#1732). Make
+# 3.x is found there and not under cmd.exe (MSYS2 and MinGW ship 4.x), and
+# macOS always has a POSIX printf, so that one case keeps the shell write.
+ifneq ($(filter 3.%,$(MAKE_VERSION)),)
+$(shell printf '%s\n' '$(subst ','\'',$(BUILD_CONFIG))' > .build-config)
+else
$(file >.build-config,$(BUILD_CONFIG))
endif
+endif
.build-config: ;
colibri$(EXE): colibri.c sse41_kernels.h exact_dot.h oracle.h pin_pool.h cli_args.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h omp_tune.h kv_fp8.h kv_tq.h abl.h backend_cuda.h backend_metal.h backend_vulkan.h decode_batch.h edge_adapters.h edge_runtime.h edge_tok_internal.h schema_gbnf.h segment_adapter_internal.h segment_adapters.h segment_runtime.h tier.h $(CUDA_OBJ) $(METAL_OBJ) $(VK_OBJ) $(VK_SPV) .build-config
diff --git a/c/tests/test_build_config_stamp.py b/c/tests/test_build_config_stamp.py
new file mode 100644
index 00000000..faa38efb
--- /dev/null
+++ b/c/tests/test_build_config_stamp.py
@@ -0,0 +1,59 @@
+"""c/Makefile records the build-affecting flags in .build-config (#306).
+
+The write used $(file ...), which GNU Make 3.81 -- /usr/bin/make on macOS --
+does not have: the stamp was never written and every build relinked (#1732).
+Make 3.x now writes it through printf. This drives the parse with
+MAKE_VERSION forced to 3.81 and to the running make's own version, and checks
+that both write the stamp and that an unchanged configuration leaves it alone.
+The previous .build-config is restored afterwards.
+"""
+import os
+import shutil
+import subprocess
+import time
+import unittest
+from pathlib import Path
+
+C_DIR = Path(__file__).resolve().parent.parent
+MAKE = shutil.which("make")
+STAMP = C_DIR / ".build-config"
+
+
[email protected](MAKE and os.name == "posix", "make and a POSIX shell are required")
+class BuildConfigStampTest(unittest.TestCase):
+ def setUp(self):
+ self.saved = STAMP.read_bytes() if STAMP.exists() else None
+
+ def tearDown(self):
+ if self.saved is None:
+ STAMP.unlink(missing_ok=True)
+ else:
+ STAMP.write_bytes(self.saved)
+
+ def parse(self, *variables):
+ result = subprocess.run([MAKE, "-s", *variables, ".build-config"], cwd=C_DIR,
+ text=True, capture_output=True, timeout=120)
+ self.assertEqual(result.returncode, 0, result.stderr)
+
+ def check(self, *version):
+ marker = f"-DCOLI_STAMP_TEST_{time.monotonic_ns()}"
+ self.parse(*version, f"EXTRA_CFLAGS={marker}")
+ self.assertTrue(STAMP.exists(), "the stamp was not written")
+ text = STAMP.read_text()
+ self.assertIn(marker, text)
+ before = STAMP.stat().st_mtime_ns
+ time.sleep(0.05)
+ self.parse(*version, f"EXTRA_CFLAGS={marker}")
+ self.assertEqual(STAMP.stat().st_mtime_ns, before,
+ "an unchanged configuration rewrote the stamp")
+ self.assertEqual(STAMP.read_text(), text)
+
+ def test_make_381_writes_the_stamp(self):
+ self.check("MAKE_VERSION=3.81")
+
+ def test_current_make_writes_the_stamp(self):
+ self.check()
+
+
+if __name__ == "__main__":
+ unittest.main()