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

Idea: More robust detection of Visual Studio #560

Closed
ivan-kalev opened this issue Aug 28, 2015 · 12 comments
Closed

Idea: More robust detection of Visual Studio #560

ivan-kalev opened this issue Aug 28, 2015 · 12 comments
Assignees
Labels
locked [bot] locked due to inactivity

Comments

@ivan-kalev
Copy link
Contributor

I'm looking into the source code of conda_build.windows.msvc_env_cmd():

https://github.com/conda/conda-build/blob/master/conda_build/windows.py#L56

I've just implemented something similar, not realizing that such functionality already exists in conda-build (this is something worth mentioning in the documentation by the way). The only thing that concerns me a bit is msvc_env_cmd() assumes that Visual Studio is installed in Program Files rather than getting it from the registry. Perhaps you can refactor that by relying on setuptools:

from distutils.msvc9compiler import VERSION, PLAT_TO_VCVARS, get_platform
from setuptools.msvc9_support import find_vcvarsall

vc = find_vcvarsall(VERSION)
plat = PLAT_TO_VCVARS[get_platform()]

header = 'call "{vc}" {plat}".format(vc=vc, plat=plat)

This code gives you the full path to vcvarsall.bat matching the version of the current Python interpreter and its plat argument. The generated header can be inserted in bld.bat. It needs to be executed using %PYTHON% to produce correct results as it decides what version of Visual Studio to look for based on the version of the current interpreter.

@asmeurer
Copy link
Contributor

One possible issue I see is that distutils doesn't support the Microsoft Visual C++ Compiler for Python 2.7.

@ivan-kalev
Copy link
Contributor Author

find_vcvarsall() from setuptools does though:

https://github.com/jaraco/setuptools/blob/master/setuptools/msvc9_support.py#L29

@Korijn
Copy link
Contributor

Korijn commented Sep 12, 2015

👍

@msarahan msarahan self-assigned this Oct 31, 2015
@msarahan
Copy link
Contributor

+1 we will look into this. The other alternatives raised internally are to use the VS??COMNTOOLS environment variable, and/or the registry.

@msarahan
Copy link
Contributor

msarahan commented May 9, 2016

This was improved by @patricksnape in #861

@msarahan msarahan closed this as completed May 9, 2016
@ivan-kalev
Copy link
Contributor Author

@msarahan Is this part of the latest release? I'm running conda-build=1.20.1 and it's still looking for vcvarsall in Program Files:

C:\ANACONDA\conda-bld\work\zlib-1.2.8>call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
The system cannot find the path specified.

My VS 2015 is installed in a different folder. setuptools.msvc9_support.find_vcvarsall() returns the correct path.

@msarahan
Copy link
Contributor

This will be part of the coming release. If you'd like to try a beta:

conda install -c conda-team/labels/dev conda-build

This will not fix things that are manually installed elsewhere - it just incorporates more of the different standard install locations (for the VS compiler for Python, for example)

@ivan-kalev
Copy link
Contributor Author

This was actually my main concern, because Visual Studio can be installed virtually anywhere. Mine is at C:\VS14 for example, so only the registry or the standard VS environment variables can tell us the right location.

@msarahan
Copy link
Contributor

Yeah, that's not fixed yet. Sorry. @groutr did some work on that. I'd be happy to review a PR if you want to work on it.

This is something that needs fixing, I agree. Unfortunately I can't get to it right now.

@ivan-kalev
Copy link
Contributor Author

Here is one way to resolve it:

def build_vcvarsall_vs_path(version):
    """
    Given the Visual Studio version, returns the default path to the
    Microsoft Visual Studio vcvarsall.bat file.
    Expected versions are of the form {9, 10, 12, 14}
    """
    return os.path.join(
        os.environ["VS{0}0COMNTOOLS".format(version)],
        '..\\..\\VC\\vcvarsall.bat'
    )

This replaces build_vcvarsall_vs_path from 1.20.2beta

@msarahan
Copy link
Contributor

Seems fine. I'll try to work this in.

@github-actions
Copy link

Hi there, thank you for your contribution!

This issue has been automatically locked because it has not had recent activity after being closed.

Please open a new issue if needed.

Thanks!

@github-actions github-actions bot added the locked [bot] locked due to inactivity label Apr 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked [bot] locked due to inactivity
Projects
None yet
Development

No branches or pull requests

4 participants