Skip to content

Commit

Permalink
Merge pull request #1558 from brian-team/setuptools_compatibility
Browse files Browse the repository at this point in the history
Setuptools compatibility and Windows fixes
  • Loading branch information
mstimberg authored Sep 3, 2024
2 parents 23203fc + 2929206 commit 5c6d814
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 7 additions & 3 deletions brian2/codegen/cpp_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
import subprocess
import sys
import tempfile
from distutils.ccompiler import get_default_compiler

from setuptools import msvc
try:
from setuptools.msvc import msvc14_get_vc_env as _get_vc_env
except ImportError: # Setuptools 0.74.0 removed this function
from distutils._msvccompiler import _get_vc_env

from distutils.ccompiler import get_default_compiler

from brian2.core.preferences import BrianPreference, prefs
from brian2.utils.filetools import ensure_directory
Expand Down Expand Up @@ -352,7 +356,7 @@ def get_msvc_env():
# Search for MSVC environment if not already cached
if _msvc_env is None:
try:
_msvc_env = msvc.msvc14_get_vc_env(arch_name)
_msvc_env = _get_vc_env(arch_name)
except distutils.errors.DistutilsPlatformError:
raise OSError(
"Cannot find Microsoft Visual Studio, You "
Expand Down
17 changes: 11 additions & 6 deletions brian2/devices/cpp_standalone/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,12 +1174,7 @@ def compile_source(self, directory, compiler, debug, clean):
self.timers["compile"]["make"] = time.time() - start_time

if x != 0:
if os.path.exists("winmake.log"):
with open("winmake.log") as f:
print(f.read())
error_message = (
"Project compilation failed (error code: %u)." % x
)
error_message = f"Project compilation failed (error code: {x}), consider having a look at 'winmake.log'."
if not clean:
error_message += (
" Consider running with "
Expand Down Expand Up @@ -1559,10 +1554,20 @@ def build(
libraries = self.libraries + prefs["codegen.cpp.libraries"] + codeobj_libraries

compiler_obj = ccompiler.new_compiler(compiler=compiler)

# Distutils does not use the shell, so it does not need to quote filenames/paths
# Since we include the compiler flags in the makefile, we need to quote them
include_dirs = [f'"{include_dir}"' for include_dir in include_dirs]
library_dirs = [f'"{library_dir}"' for library_dir in library_dirs]
runtime_library_dirs = [
f'"{runtime_dir}"' for runtime_dir in runtime_library_dirs
]

compiler_flags = (
ccompiler.gen_preprocess_options(define_macros, include_dirs)
+ extra_compile_args
)

linker_flags = (
ccompiler.gen_lib_options(
compiler_obj,
Expand Down

0 comments on commit 5c6d814

Please sign in to comment.