The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): build Windows sdists under a short uv cache path
Teknium1aaf75e6f2ed
diff --git a/scripts/bundles/desktop_prepare.py b/scripts/bundles/desktop_prepare.pyindex 1351a850012..b1b7225fe1d 100644--- a/scripts/bundles/desktop_prepare.py+++ b/scripts/bundles/desktop_prepare.py@@ -337,7 +337,7 @@ def prepare_in_worker(request: BuildRequest) -> Path:request.validate_channel()python, node, env = prepare_tools(request.source, request.work, request.cache, os.environ)env = identity_environment(request, request.variant, env)- native_toolchain = Path(env["UV_CACHE_DIR"]).name+ native_toolchain = Path(env["UV_CACHE_DIR"]).resolve().namerun([str(node), "scripts/build/node-deps.mjs", "--source", str(request.source), "--reuse","--native-toolchain", native_toolchain,*[arg for name in request.workspaces() for arg in ("--workspace", name)]], cwd=request.source, env=env)diff --git a/scripts/bundles/desktop_toolchain.py b/scripts/bundles/desktop_toolchain.pyindex 7652959d793..974c43f427f 100644--- a/scripts/bundles/desktop_toolchain.py+++ b/scripts/bundles/desktop_toolchain.py@@ -32,7 +32,7 @@ def bootstrap_environment(source: Path, work: Path, cache: Path,"HERMES_PYTHON_SRC_ROOT", "XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME","UV_CACHE_DIR", "NPM_CONFIG_CACHE", "NPM_EXECPATH", "NPM_NODE_EXECPATH","NPM_CONFIG_USERCONFIG", "NPM_CONFIG_GLOBALCONFIG", "NPM_CONFIG_PREFIX",- "PYTHONUTF8", "PYTHONDONTWRITEBYTECODE", "CARGO_HOME", "RUSTUP_HOME"}+ "PYTHONUTF8", "PYTHONDONTWRITEBYTECODE", "CARGO_HOME", "RUSTUP_HOME", "CARGO_TARGET_DIR"}result = {key: value for key, value in env.items() if key.upper() not in _INSTALL_ENV | owned}canonical = {key.upper(): value for key, value in env.items()}# Rustup must still find the runner's installed toolchain after HOME moves.@@ -51,6 +51,10 @@ def bootstrap_environment(source: Path, work: Path, cache: Path,"XDG_CONFIG_HOME": str(home / "config"), "XDG_CACHE_HOME": str(home / "cache"),"XDG_DATA_HOME": str(home / "data"), "XDG_STATE_HOME": str(home / "state"),"UV_CACHE_DIR": str(cache / "python/runtime"),+ # Rust sdists (obstore via maturin) otherwise compile into target/ inside uv's+ # nested sdist cache entry; on Windows that pushes build-script paths past+ # MAX_PATH and link.exe fails with LNK1104. A job-local root keeps them short.+ "CARGO_TARGET_DIR": str(work / "cargo"),# vcpkg's default binary cache is under LOCALAPPDATA, which moved into the# job-local home above; keep its archives in the transported native domain."VCPKG_DEFAULT_BINARY_CACHE": str(cache / "native/vcpkg-archives"),@@ -120,11 +124,33 @@ def prepare_tools(source: Path, work: Path, cache: Path,raise FileNotFoundError(f"PM did not prepare a native {name} executable")binaries[name] = installed.binaryprepared = pm.env_for("python", "npm", base_env=prepared)+ uv_cache = native_cache_path(cache, prepared)+ if os.name == "nt":+ uv_cache = short_alias(uv_cache, work / "uv")prepared.update({"HERMES_PYTHON": str(binaries["python"]), "HERMES_NODE": str(binaries["node"]),- "UV_CACHE_DIR": str(native_cache_path(cache, prepared))})+ "UV_CACHE_DIR": str(uv_cache)})return binaries["python"], binaries["node"], prepared+def short_alias(directory: Path, link: Path) -> Path:+ """Reach a transported cache directory through a short job-local junction.++ uv builds each sdist in <cache>/sdists-v10/pypi/<name>/<version>/<id>/src, and+ MSVC link.exe cannot open paths past MAX_PATH, so a deep cache root pushes+ native build outputs over 260 characters (LNK1104). uv keeps the spelling it+ is given, so builds run under the junction while the bytes stay in the cache.+ """+ import _winapi++ from pm.filesystem import is_junction++ directory.mkdir(parents=True, exist_ok=True)+ if is_junction(link):+ os.rmdir(link) # Removes only the reparse point, never the cache behind it.+ _winapi.CreateJunction(str(directory), str(link))+ return link++def _msvc_identity() -> dict[str, str] | None:"""The newest VC toolset vswhere reports, with its default tools version."""from hermes_platform.resolver import locate_commanddiff --git a/scripts/bundles/native.py b/scripts/bundles/native.pyindex 31c3de2448c..aae96cf0c36 100644--- a/scripts/bundles/native.py+++ b/scripts/bundles/native.py@@ -167,7 +167,7 @@ def prepare_native(*, out: Path, ref: str, source: Path, cache: Path,prepared_path(out).unlink(missing_ok=True)(out / "manifest.json").unlink(missing_ok=True)return _prepare_native(out=out, ref=ref, source=Path(source).resolve(),- cache=Path(cache).resolve(), tools=tools, env=env)+ cache=Path(cache).absolute(), tools=tools, env=env)def _prepare_native(*, out: Path, ref: str, source: Path, cache: Path,diff --git a/tests/scripts/test_desktop_toolchain.py b/tests/scripts/test_desktop_toolchain.pyindex d17ab0673a6..22e44bb2448 100644--- a/tests/scripts/test_desktop_toolchain.py+++ b/tests/scripts/test_desktop_toolchain.py@@ -85,6 +85,37 @@ def test_bootstrap_environment_isolates_owned_paths_without_mutating_caller(tmp_assert len([key for key in mixed if key.upper() == "HERMES_RUNTIME_DIR"]) == 1+def test_rust_sdists_build_outside_the_nested_uv_cache(tmp_path):+ # Windows link.exe has no long-path support: target/ inside uv's sdist entry+ # under the cache exceeded MAX_PATH (LNK1104) when obstore compiled cold.+ from scripts.bundles.desktop_toolchain import bootstrap_environment++ source, work, cache = (tmp_path / name for name in ("source", "work", "cache"))+ env = bootstrap_environment(source, work, cache, {"CARGO_TARGET_DIR": str(cache / "python/runtime/x")})+ target = Path(env["CARGO_TARGET_DIR"])+ assert target.parent == work.resolve()+ assert not target.is_relative_to(cache.resolve())++[email protected]("windows")+def test_windows_uv_cache_is_a_short_junction_into_the_transported_cache(tmp_path):+ # uv nests sdist builds ~200 characters below its root; under the deep transported+ # cache, setuptools/maturin link outputs passed MAX_PATH (LNK1104) on win32-x64/arm64.+ from scripts.bundles.desktop_toolchain import short_alias++ first, second = tmp_path / "desktop-inputs/python/runtime/a", tmp_path / "desktop-inputs/python/runtime/b"+ first.mkdir(parents=True)+ (first / "wheel").write_text("kept", encoding="utf-8")+ link = tmp_path / "work" / "uv"+ link.parent.mkdir()+ assert short_alias(first, link) == link+ (link / "built").write_text("cached", encoding="utf-8")+ assert (first / "built").read_text(encoding="utf-8") == "cached"+ short_alias(second, link) # Re-preparing re-points the alias; cached bytes stay put.+ assert link.resolve() == second.resolve()+ assert (first / "wheel").read_text(encoding="utf-8") == "kept"++@pytest.mark.parametrize("exit_code", [0, 7])@pytest.mark.platforms("linux", "macos", "windows")def test_run_preparation_bootstraps_before_worker_in_isolated_child(tmp_path, monkeypatch, exit_code):