Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winenv: Incomplete MSVC detection? #7

Open
jkmartindale opened this issue Jan 2, 2025 · 0 comments
Open

winenv: Incomplete MSVC detection? #7

jkmartindale opened this issue Jan 2, 2025 · 0 comments

Comments

@jkmartindale
Copy link

jkmartindale commented Jan 2, 2025

While attempting to install frida-node on Windows, I ran into an unexpected "Visual Studio is not installed" error:

npm error code 1
npm error path C:\Users\jk\AppData\Roaming\npm\node_modules\frida
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/install.js
npm error Downloading toolchain 20241208...
npm error Extracting toolchain...
npm error Downloading SDK 20241208 for windows-x86_64-mt...
npm error Extracting SDK...
npm error prebuild-install warn install No prebuilt binaries found (target=23.5.0 runtime=node arch=x64 libc= platform=win32)
npm error Visual Studio is not installed
npm error A complete log of this run can be found in: C:\Users\jk\AppData\Local\npm-cache\_logs\2025-01-02T21_28_48_409Z-debug-0.log

I found this unusual because while I did not have Visual Studio installed, I had the Visual Studio Build Tools installed. After installing Visual Studio, I got a different "list index out of range" error:

npm error code 1
npm error path C:\Users\jk\AppData\Roaming\npm\node_modules\frida
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/install.js
npm error Downloading toolchain 20241208...
npm error Extracting toolchain...
npm error Downloading SDK 20241208 for windows-x86_64-mt...
npm error Extracting SDK...
npm error prebuild-install warn install No prebuilt binaries found (target=22.10.0 runtime=node arch=x64 libc= platform=win32)
npm error list index out of range
npm error A complete log of this run can be found in: C:\Users\jk\AppData\Local\npm-cache\_logs\2025-01-02T22_52_00_687Z-debug-0.log

Looking at winenv.py it seems like the root cause is in detect_msvc_tool_dir.

In the first case with VS Build Tools only, the vswhere call in detect_msvs_installation_dir returned an empty array because, without specifying -products, vswhere only looks for Visual Studio. This explains the "Visual Studio is not installed" message.

In the second case with Visual Studio installed, detect_msvc_tool_dir assumed that MSVC would be in msvs_dir/VC/Tools/MSVC. In my case, Visual Studio installed to C:\Program Files\Microsoft Visual Studio\2022\Community and had no VC subdirectory. VC was instead located in C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools. The "list index out of range" error comes from what I'm assuming to be an empty array from a failed glob.

After reading the Find VC page in the vswhere docs I tried this change:

@@ -30,7 +30,9 @@ def detect_msvs_installation_dir(toolchain_prefix: Optional[Path]) -> Path:
                                vswhere,
                                "-latest",
                                "-format", "json",
-                               "-property", "installationPath"
+                               "-property", "installationPath",
+                               "-products", "*",
+                               "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
                            ],
                            capture_output=True,
                            encoding="utf-8",

This resulted in successfully finding where VC was installed on my PC.

I was thinking of making a pull request, but with semi-recent commits to winenv.py and successful frida-gum CI builds it definitely seems like the existing vswhere call is working, just not for me.

Is there something I'm missing in my setup that would have prevented me from needing this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant