Fix #3403: the Mac setup installs cmake and ninja before it compiles

This commit is contained in:
Niko1221 committed 2026-10-20 14:13:34 +02:00
1 parent 98faf8139e
commit e346198ff3
4 files changed
+47 -6

No files matched your search

+1 -1
View File
@@ -56,7 +56,7 @@ What the first run does (each step is skipped when it is already done):
1. **Python.** It needs Python 3.10 or newer, but macOS ships 3.9. If that is all your Mac has, `setup.sh` downloads a standalone Python 3.12 (25 MB, pinned by SHA-256) into `.python`. No sudo, no Homebrew.
2. **Checks your Mac:** the chip, the memory, the macOS version, the Command Line Tools and the free disk.
3. **Python packages** into `.venv`. CMake and Ninja come from pip.
3. **Python packages** into `.venv`. CMake and Ninja come from pip too, installed just before the build in step 4.
4. **Builds the engine** (`build-metal/strata`). It uses Apple's metal-cpp headers (pinned by SHA-256) and llama.cpp's ggml at the commit the PC build pins.
5. **Downloads the model.** The download resumes if interrupted. `--gguf-dir` uses files you already have.
6. **Prepares the model:** the pack (seconds), and the MTP draft layer (about 5 GB of the original checkpoint). On a Mac that streams: the experts' copy instead of the draft layer (about 3 minutes on the M4, checked byte for byte against the model file).
+5 -3
View File
@@ -6,7 +6,7 @@ What it does, each step skipped when it is already done:
1. checks the Mac: Apple Silicon, the chip, unified memory, macOS version, the Command Line Tools, free disk
2. recommends a model by memory (recommend, never force: an explicit --model is kept, with what it risks)
3. installs the Python packages into .venv (cmake and ninja come from pip: no Homebrew, no sudo)
3. installs the Python packages into .venv (cmake and ninja come from pip, just before step 4: no Homebrew, no sudo)
4. builds the Metal engine from source: metal-cpp (Apple's headers) and llama.cpp's ggml at the pinned commit
5. downloads the model (setup.py's downloader: resumable, the pinned revision)
6. prepares the model: the native pack (tools/iq_pack.py) and the MTP draft layer (tools/mtp_fetch.py, mtp_pack.py)
@@ -127,6 +127,7 @@ def build_engine(llama: Path, jobs: int | None = None) -> Path:
S.ok(f"Metal engine: {EXE} (built for this source)")
return EXE
mcpp = metal_cpp()
S.ensure_build_tools() # cmake and ninja are in requirements-build.txt, not requirements.txt (#3403)
S.say(" Building the Metal engine from source (5-15 minutes the first time) ...")
BUILD_DIR.mkdir(exist_ok=True)
log = BUILD_DIR / "build.log"
@@ -170,6 +171,7 @@ def build_vision(llama: Path) -> Path:
return VISION_EXE
except (OSError, ValueError):
pass
S.ensure_build_tools()
S.say(" Building the image encoder (1-3 minutes) ...")
env = dict(os.environ, PATH=str(Path(sys.executable).parent) + os.pathsep + os.environ.get("PATH", ""))
log = ROOT / "build-vision.log"
@@ -416,9 +418,9 @@ def main(argv=None) -> int:
if free < need:
S.warn(f"about {need:.0f} GB are needed on the disk ({free:.0f} GB free): kept as you chose; it may run out")
# ---- 3. Python packages (cmake and ninja among them: the engine build's tools)
# ---- 3. Python packages (cmake and ninja come with the build in step 4, from requirements-build.txt)
S.step(3, "Python packages")
S.pip_install(S.requirement_lines() if S.REQUIREMENTS.exists() else S.PY_PACKAGES, "numpy, jinja2, ..., cmake, ninja")
S.pip_install(S.requirement_lines() if S.REQUIREMENTS.exists() else S.PY_PACKAGES, "numpy, jinja2, ...")
# ---- 4. the engine
S.step(4, "the Strata engine (Metal)")
+9 -2
View File
@@ -4910,8 +4910,9 @@ def install_build_tools(gpu, yes):
return nvcc, find_vcvars(cuda_v) if WIN else None
def cmake_build(src, bdir, target, defs, vcvars, bat_name):
acquisition.require("a compile (cmake)")
def ensure_build_tools():
"""cmake and ninja for a local compile, installed from requirements-build.txt when missing (#3403: the Mac setup
compiles without cmake_build(), so it calls this too). Returns (cmake, ninja)."""
# The ready-made engine path never calls this function. Keep build helpers out of
# the normal serving environment, and use already installed tools offline.
build_packages = requirement_lines(BUILD_REQUIREMENTS) if BUILD_REQUIREMENTS.exists() else BUILD_PACKAGES
@@ -4921,6 +4922,12 @@ def cmake_build(src, bdir, target, defs, vcvars, bat_name):
cmake, ninja = find_tool("cmake"), find_tool("ninja")
if cmake is None or ninja is None:
fail("cmake / ninja not found after installing them", "run: .venv python -m pip install -r requirements-build.txt")
return cmake, ninja
def cmake_build(src, bdir, target, defs, vcvars, bat_name):
acquisition.require("a compile (cmake)")
cmake, ninja = ensure_build_tools()
conf = [cmake, "-G", "Ninja", f"-DCMAKE_MAKE_PROGRAM={ninja}", "-S", str(src), "-B", str(bdir),
"-DCMAKE_BUILD_TYPE=Release", *defs]
build = [cmake, "--build", str(bdir), "--target", target, "-j", str(max(2, (os.cpu_count() or 4) // 2))]
+32
View File
@@ -65,6 +65,38 @@ class Issue3298MtpDepth(unittest.TestCase):
self.assertEqual(files_present({"args": ["--mtp", str(self.root / "gone")]}), [str(self.root / "gone")])
class Issue3403MacBuildTools(unittest.TestCase):
"""The Mac setup compiles without setup.cmake_build(), so cmake and ninja must be installed for it too."""
def test_missing_build_tools_are_installed_before_the_mac_compile(self):
from unittest import mock
import setup
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "metal"))
import setup_mac as M
installed = {"cmake": None, "ninja": None}
def find(name):
return installed[name]
def pip(packages, what):
self.assertTrue(all(p.split("==")[0] in ("cmake", "ninja") for p in packages), packages)
for p in packages:
installed[p.split("==")[0]] = "/venv/bin/" + p.split("==")[0]
with mock.patch.object(setup, "find_tool", side_effect=find), mock.patch.object(setup, "pip_install", side_effect=pip) as pi:
self.assertEqual(setup.ensure_build_tools(), ("/venv/bin/cmake", "/venv/bin/ninja"))
self.assertEqual(pi.call_count, 1)
setup.ensure_build_tools() # present now: nothing more is installed
self.assertEqual(pi.call_count, 1)
def test_both_mac_builds_ask_for_the_tools_first(self):
import inspect
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "metal"))
import setup_mac as M
for fn in (M.build_engine, M.build_vision):
self.assertIn("S.ensure_build_tools()", inspect.getsource(fn), fn.__name__)
class Issue3188BenchStartsItsOwnServer(unittest.TestCase):
"""tools/strata_bench.py named `port` in the start-a-server branch without ever setting it."""