google / shaderc-rs

Rust bindings for the shaderc library.
https://docs.rs/shaderc
Apache License 2.0
261 stars 64 forks source link

Build fails on Windows with Windows store Python #108

Closed mdegans closed 3 years ago

mdegans commented 3 years ago

Build scripts do not find Python installed through the windows store:

Caused by:
  process didn't exit successfully: `C:\Users\user\Projects\basalt\target\debug\build\shaderc-sys-a59d646b0d50f3cd\build-script-build` (exit code: 101)
  --- stdout
  cargo:warning=System installed library not found.  Falling back to build from source

  --- stderr
  thread 'main' panicked at '

  couldn't find required command: "python"

  ', C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\shaderc-sys-0.6.3\build\cmd_finder.rs:50:13
  stack backtrace:
     0: std::panicking::begin_panic_handler
               at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\std\src\panicking.rs:493
     1: std::panicking::begin_panic_fmt
               at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\std\src\panicking.rs:435
     2: build_script_build::cmd_finder::{{impl}}::must_have::{{closure}}<str>
               at .\build\cmd_finder.rs:50
     3: core::option::Option<std::path::PathBuf>::unwrap_or_else<std::path::PathBuf,closure-0>
               at C:\Users\user\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\option.rs:427
     4: build_script_build::cmd_finder::CommandFinder::must_have<str>
               at .\build\cmd_finder.rs:49
     6: core::ops::function::FnOnce::call_once<fn(),tuple<>>
               at C:\Users\user\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...
error: build failed
PS C:\Users\user\Projects\basalt> python
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Solution for me was just to install python for windows from Python.org

Not really a windows guy, so not sure why this is. python as well as python3 are in path but they weren't detected.

antiagainst commented 3 years ago

Solution for me was just to install python for windows from Python.org

Not really a windows guy, so not sure why this is. python as well as python3 are in path but they weren't detected.

I'm a bit confused here: do you have Python installed and exposed via PATH before installing python for windows from Python.org?

mdegans commented 3 years ago

Solution for me was just to install python for windows from Python.org Not really a windows guy, so not sure why this is. python as well as python3 are in path but they weren't detected.

I'm a bit confused here: do you have Python installed and exposed via PATH before installing python for windows from Python.org?

Sorry for not being clear, @antiagainst . Yes, Python was in path, installed from Windows store, but wasn't detected somehow. Immediately after the error, I double checked the command python worked. I've updated the log above. Seems cmd_finder.rs does not work in this case. After installing Python from Python.org, it's detected. Perhaps the extension is not .exe and that's why? Seems Microsoft Store is .appx

zshift commented 3 years ago

I also ran into this issue just now. Microsoft apps are installed to %USERPROFILE%\AppData\Local\Microsoft\WindowsApps, and this is automatically added to the user env path by the Microsoft Store. I've manually checked, and python.exe does exist in this directory, however it is not detected by cmd_finder.rs. I've also tried running from an elevated powershell console, so I don't think this is related to permissions.

I received the exact error as in the original post.

antiagainst commented 3 years ago

The script does read from PATH. Not an expert on Windows PATH; is there a difference between the user and system PATH? Does Microsoft Store do anything special there?

mdegans commented 3 years ago

The script does read from PATH. Not an expert on Windows PATH; is there a difference between the user and system PATH? Does Microsoft Store do anything special there?

Don't think so. It appears to be in $PATH for the cmd shell.

C:\Users\username>where python
C:\Users\username\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Users\username>python
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

C:\Users\username>where where
C:\Windows\System32\where.exe

Powershell is a different story.

PS C:\Users\username> where python
PS C:\Users\username> python
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which('python')
'C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\python.EXE'

In what universe that makes sense, IDK. where notepad doesn't even work but typing notepad and hitting enter indeed launches notepad. Possibly somebody who knows more about Windows can enlighten?

Seems python uses PATH for shutil.which() The logic isn't the exactly the same, but looking at your cmd_finder.rs I can't see what's wrong.

oxkenshin commented 3 years ago

Because the build script uses std::path::PathBuf::exists to track if dependencies are present. In the rust-lang reference

If you cannot access the metadata of the file, e.g. because of a permission error or broken symbolic links, this will return false.

Python installed by Microsoft App Store is pointing to a path which is unable to be accessed by user. A patch is submitted to fix this.

antiagainst commented 3 years ago

@oxkenshin: ah, thanks for the explanation!