turborepo
8fcdd33b - fix: Run a Windows archive tool's executable from its own folder (#15162)

Commit
22 hours ago
fix: Run a Windows archive tool's executable from its own folder (#15162) ### Description On Windows, `turbo setup` exposes each tool's `.exe` as a hard link in one shared `bin` folder. A program that finds its own files from the location of its executable then fails. Zig is the reported case, from CI on #15126: ``` error: unable to find zig installation directory from executable path "C:\\Users\\runneradmin\\AppData\\Local\\turborepo\\tools\\envs\\<hash>\\bin\\zig.exe": FileNotFound ``` Built-in tools each have their own workaround (rustup proxies for Rust, a `.cmd` launcher for Python). An additional tool is any archive that a repository declares, so it had none. #### What changed - An additional tool's `.exe` from an archive now gets a small generated launcher in `bin` under the export's name. The launcher starts the real file by its path inside the tool's tree, with the original command line and standard handles, and returns its exit code. - `build.rs` in `turborepo-tool-install` compiles the launcher from one source file, `windows/launcher.rs`, with the `rustc` that builds the crate. The repository holds no prebuilt binary. - An environment's seal records the SHA-256 of the launcher that it was built with. The check accepts a launcher whose program matches that hash and whose target is the one this selection renders, so a later `turbo` with a different launcher keeps using the environment. #### Scope - Only additional tools, only on Windows, only an `.exe`, and only from an archive. Built-in tools, macOS, Linux, `.cmd` exports, and `binary` artifacts keep their current `bin` entries and environment keys. - Known differences from running the program directly: a parent that starts the launcher with `DETACHED_PROCESS` gives a console target a new console, a priority class above normal is not passed on, and `cmd.exe` waits for a GUI target. - Activation reads and hashes one launcher (about 240 KB) for each such export. #### Tradeoffs I measured the alternatives on Windows 11 with the real `zig.exe`: | Way to reach `zig.exe` | Result | | --- | --- | | Hard link in another folder (today) | Same error as CI | | File symlink | Cannot be created without a privilege that an ordinary account lacks | | `.cmd` forwarder | `cmd.exe` finds it by name. A program that starts `zig` with `CreateProcess` does not, and that is what a Rust build script does. | | Folder junction | Works, but puts the tool's whole folder on `PATH` | A check of `turborepo-tool-install` for a Windows target from macOS or Linux now needs a Windows linker, because `build.rs` links the launcher. #### Blast radius A repository on Windows that declares an archive tool gets a new environment on its next `turbo setup`. Its tool trees are reused. I ran the checks below on Windows on ARM64, where `turbo setup` itself refuses to run. Windows x64 CI on this PR is the run on a supported host. ### Testing Instructions The first commit is a test that fails on `main` the way Zig did: ``` assertion `left == right` failed: probe: no data.txt beside the executable left: Some(3) right: Some(7) ``` On Windows 11 ARM64, in a native clone at this branch: - `cargo test -p turborepo-tool-install`: 16 passed. The tests start the export by bare name through `CreateProcess`, pass arguments with spaces and quotes, end the launcher and check that its target ends, and change a launcher's program and its target on disk and check that both are damage. - The real `zig.exe` behind a launcher: `zig env` prints a `lib_dir` inside the tool's tree from `cmd.exe`, from PowerShell, and from Rust's `Command::new("zig")`. - A launcher inside a job that ends everything when it closes, which is how `turbo run` starts a task: closing the job ended the launcher, its target, and a child of the target. - A parent whose own output handles are not inheritable, as with Python's `subprocess`: the target's output was lost before the launcher passed inheritable copies, and arrives now. On Windows x64 in CI, the end-to-end test `additional_tools_export_and_find_resources_then_repeat_offline_and_remove` runs `turbo setup` against a fixture archive whose `.exe` succeeds only beside its own files, and it passes along with the store tests above.
Author
Parents
Loading