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

Setuptools compatibility and Windows fixes #1558

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
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
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
Loading