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

Automatically find Visual Studio #471

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pygenn/genn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
"""
# python imports
from collections import namedtuple, OrderedDict
from distutils.spawn import find_executable
from importlib import import_module
from os import path
from os import path, environ
from platform import system
from psutil import cpu_count
from setuptools import msvc
from subprocess import check_call # to call make
from textwrap import dedent
from warnings import warn
Expand Down Expand Up @@ -85,6 +87,24 @@
else:
backend_modules[b] = m

# If we're on windows
if system() == "Windows":
# Get environment and cache in class, convertings
# all keys to upper-case for consistency
_msvc_env = msvc.msvc14_get_vc_env("x86_amd64")
_msvc_env = {k.upper(): v for k, v in iteritems(_msvc_env)}

# Update process's environment with this
# **NOTE** this handles both child processes (manually launching msbuild)
# and stuff within this process (running the code generator)
environ.update(_msvc_env)

# Find MSBuild in path
# **NOTE** we need to do this because setting the path via
# check_call's env kwarg does not effect finding the executable
# **NOTE** shutil.which would be nicer, but isn't in Python < 3.3
_msbuild = find_executable("msbuild", _msvc_env["PATH"])

GeNNType = namedtuple("GeNNType", ["np_dtype", "assign_ext_ptr_array", "assign_ext_ptr_single"])

class GeNNModel(object):
Expand Down Expand Up @@ -590,7 +610,7 @@ def build(self, path_to_model="./", force_rebuild=False):

# Build code
if system() == "Windows":
check_call(["msbuild", "/p:Configuration=Release", "/m", "/verbosity:minimal",
check_call([_msbuild, "/p:Configuration=Release", "/m", "/verbosity:minimal",
path.join(output_path, "runner.vcxproj")])
else:
check_call(["make", "-j", str(cpu_count(logical=False)), "-C", output_path])
Expand Down