Skip to content

Commit

Permalink
MUSIC wheel
Browse files Browse the repository at this point in the history
* retrieve include dirs + MPI include dirs
* neuronmusic package
* handle rpath

Drop setup.py.in leftover
  • Loading branch information
alexsavulescu committed Mar 10, 2023
1 parent f86c5bb commit c9dd9fb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 47 deletions.
5 changes: 4 additions & 1 deletion packaging/python/build_wheels.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pip_numpy_install() {

# older version for apple m1 as building from source fails
if [[ `uname -m` == 'arm64' ]]; then
numpy_ver="numpy==1.21.3"
numpy_ver="numpy==1.23.5"
fi

echo " - pip install $numpy_ver"
Expand Down Expand Up @@ -168,6 +168,9 @@ build_wheel_osx() {
echo " - Python installation is universal2 and we are on arm64, setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}"
export ARCHFLAGS="-arch arm64"
echo " - Setting ARCHFLAGS to: ${ARCHFLAGS}"
# This is a shortcut to have a successful delocate-wheel. See:
# https://github.com/matthew-brett/delocate/issues/153
python -c "import os,delocate; print(os.path.join(os.path.dirname(delocate.__file__), 'tools.py'));quit()" | xargs -I{} sed -i."" "s/first, /input.pop('i386',None); first, /g" {}
else
export _PYTHON_HOST_PLATFORM="${py_platform/universal2/x86_64}"
echo " - Python installation is universal2 and we are on x84_64, setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}"
Expand Down
34 changes: 31 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,22 @@ def run(self, *args, **kw):
the CMake building, sets the extension build environment and collects files.
"""
for ext in self.extensions:

if ext.name == "neuronmusic" and not just_extensions:
# Since MUSIC is not a CMakeAugmentedExtension, we need to add the include_dirs manually
# Of interest are the include_dirs for the MPI library and the CMAKE_PREFIX_PATH
if self.cmake_prefix:
ext.include_dirs += [
os.path.join(inc_dir, "include")
for inc_dir in self.cmake_prefix.split(";")
]
# Look for NRN_MPI_DYNAMIC in cmake_defs, split it and add to include_dirs
if self.cmake_defs:
for cmake_def in self.cmake_defs.split(","):
if cmake_def.startswith("NRN_MPI_DYNAMIC"):
ext.include_dirs += cmake_def.split("=")[1].split(";")
break

continue
if isinstance(ext, CMakeAugmentedExtension):
if ext.cmake_done:
continue
Expand Down Expand Up @@ -382,7 +397,9 @@ def setup_package():
"neuron.rxd",
"neuron.crxd",
"neuron.gui2",
] + (["neuron.rxd.geometry3d"] if Components.RX3D else [])
]
py_packages += ["neuron.rxd.geometry3d"] if Components.RX3D else []
#py_packages += ["neuronmusic"] if Components.MUSIC else []

REL_RPATH = "@loader_path" if sys.platform[:6] == "darwin" else "$ORIGIN"

Expand All @@ -407,6 +424,8 @@ def setup_package():
# Get extra_compile_args and extra_link_args from environment variable
extra_link_args = os.environ.get("LDFLAGS", "").split()
extra_compile_args = os.environ.get("CFLAGS", "").split()
logging.info("CFLAGS %s" % str(extra_compile_args))
logging.info("LDFLAGS %s" % str(extra_link_args))

extensions = [
CMakeAugmentedExtension(
Expand Down Expand Up @@ -456,12 +475,21 @@ def setup_package():
]

if Components.MUSIC:
music_libraries = ["nrniv"]
if not just_extensions:
music_libraries.append("nrnmusic")
extensions += [
CyExtension(
"neuronmusic",
["src/neuronmusic/neuronmusic.pyx"],
libraries=music_libraries,
library_dirs=[os.path.join(cmake_build_dir, "lib")],
include_dirs=["src/nrnpython", "src/nrnmusic"],
**extension_common_params,
language="c++",
extra_link_args=extra_link_args
+ ["-Wl,-rpath,{}{}".format(REL_RPATH, "/neuron/.data/lib/")]
if not just_extensions
else [],
)
]

Expand Down
40 changes: 0 additions & 40 deletions src/neuronmusic/setup.py.in

This file was deleted.

3 changes: 0 additions & 3 deletions src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,6 @@ if(NRN_ENABLE_MPI)
if(NRN_ENABLE_MUSIC)
# libnrnmusic does not depend explicitly on MPI so don't need mpi version specific versions.
set(libnrnmusic "nrnmusic")
set(NRNMUSIC_DYNAM_LIB
"'${libnrnmusic}'"
PARENT_SCOPE)
add_library(${libnrnmusic}_lib SHARED ${NRN_MUSIC_SRC_FILES})
target_include_directories(${libnrnmusic}_lib BEFORE PUBLIC ${include})
add_dependencies(${libnrnmusic}_lib nrniv_lib ${libname}_lib)
Expand Down
1 change: 1 addition & 0 deletions test/music_tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def run(cmd):
result = subprocess.run(cmd, shell=True, env=my_env, capture_output=True, text=True)
if result.returncode != 0:
print(result.stderr)
print(result.stdout)
result.check_returncode()
return result

Expand Down

0 comments on commit c9dd9fb

Please sign in to comment.