diff --git a/pygenn/genn_model.py b/pygenn/genn_model.py index ce6d1bdccd..6d1bd84f2f 100644 --- a/pygenn/genn_model.py +++ b/pygenn/genn_model.py @@ -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 @@ -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): @@ -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])