Skip to content

Commit 21c0160

Browse files
ritvikraomatthiasdienermayantaylor
authored
fixing build issues on mac (#254)
* fixing build issues on mac contains a workaround to fix the path to the libcharm shared library in the c_object_store library * get directory name with os command * environment append * cppflags if statement * minor cppflag change Co-authored-by: Matthias Diener <[email protected]> * changing clang -arch flag for arm * no renaming --------- Co-authored-by: Ritvik Rao <[email protected]> Co-authored-by: Matthias Diener <[email protected]> Co-authored-by: mayantaylor <[email protected]>
1 parent a460a95 commit 21c0160

File tree

3 files changed

+101
-50
lines changed

3 files changed

+101
-50
lines changed

charm4py/charmlib/charmlib_ctypes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import os
77
import time
8+
import platform
89
if sys.version_info < (3, 0, 0):
910
import cPickle
1011
else:
@@ -108,6 +109,7 @@ def __init__(self, charm, opts, libcharm_path):
108109
self.chareNames = []
109110
self.charm = charm
110111
self.opts = opts
112+
self.system = platform.system().lower()
111113
self.init(libcharm_path)
112114
self.ReducerType = ReducerTypes.in_dll(self.lib, "charm_reducers")
113115
self.times = [0.0] * 3 # track time in [charm reduction callbacks, custom reduction, outgoing object migration]
@@ -609,9 +611,15 @@ def init(self, libcharm_path):
609611
p = os.environ.get('LIBCHARM_PATH')
610612
if p is not None: libcharm_path = p
611613
if libcharm_path is not None:
612-
self.lib = ctypes.CDLL(os.path.join(libcharm_path, 'libcharm.so'))
614+
if self.system == 'darwin':
615+
self.lib = ctypes.CDLL(os.path.join(libcharm_path, 'libcharm.dylib'))
616+
else:
617+
self.lib = ctypes.CDLL(os.path.join(libcharm_path, 'libcharm.so'))
613618
else:
614-
self.lib = ctypes.CDLL('libcharm.so')
619+
if self.system == 'darwin':
620+
self.lib = ctypes.CDLL('libcharm.dylib')
621+
else:
622+
self.lib = ctypes.CDLL('libcharm.so')
615623
else:
616624
self.lib = ctypes.CDLL(os.path.join(libcharm_path, 'charm.dll'))
617625

docs/install.rst

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,56 @@ CPython (most common implementation) and PyPy_.
1515
.. _PyPy: http://pypy.org
1616

1717

18-
pip
19-
---
20-
21-
To install on regular Linux, macOS and Windows machines, do::
18+
Manually building the Charm++ shared library
19+
--------------------------------------------
2220

23-
$ pip3 install charm4py
21+
Use this to build Charm4py binaries manually, instead of downloading prebuilt libraries from pip.
22+
This is needed when building Charm++ for specialized machine/network layers
23+
other than TCP and MPI (e.g. Cray XC/XE).
2424

25-
.. note::
25+
Before installing, you need the following prerequisites:
26+
- CPython: numpy, greenlet and cython (``pip3 install 'numpy>=1.10.0' cython greenlet``)
27+
- PyPy: none
2628

27-
This option uses Charm++'s TCP layer as the communication layer.
28-
If you want a faster communication layer (e.g. MPI), see "Install from
29-
source" below.
29+
The first step is to clone the Charm4py repository from Git::
3030

31-
pip >= 8.0 is recommended to simplify the install and avoid building Charm4py or
32-
any dependencies from sources.
31+
$ git clone https://github.com/UIUC-PPL/charm4py
32+
$ cd charm4py
3333

34-
Note that a 64-bit version of Python is required to install and run Charm4py.
34+
Next, create a folder called charm_src in the charm4py repo, and then clone the Charm++ repo
35+
into that folder::
3536

37+
$ mkdir charm_src && cd charm_src
38+
$ git clone https://github.com/UIUC-PPL/charm
3639

37-
Install from source
38-
-------------------
40+
Once this is done, there are two ways to build Charm4py. The first way is to change back up
41+
into the Charm4Py directory and run the install script::
42+
43+
$ cd ..
44+
$ python3 setup.py install [--mpi]
3945

40-
.. note::
41-
This is not required if installing from a binary wheel with pip.
46+
The optional flag ``--mpi``, when enabled, will build the
47+
Charm++ library with the MPI communication layer (MPI headers and libraries
48+
need to be installed on the system). After this, Charm4Py will be built.
4249

43-
Prerequisites:
44-
- CPython: numpy, greenlet and cython (``pip3 install 'numpy>=1.10.0' cython greenlet``)
45-
- PyPy: none
50+
The other option is to manually build Charm++ before building Charm4py. To do this, change to
51+
the charm directory and run the following build command::
52+
53+
$ cd charm
54+
$ ./build charm4py <version> -j<N> --with-production
4655

47-
To build the latest *stable* release, do::
56+
Then, return to the charm4py directory and run setup.py::
4857

49-
$ pip3 install [--install-option="--mpi"] charm4py --no-binary charm4py
58+
$ cd ../..
59+
$ python3 setup.py install [--mpi]
5060

51-
Or download the source distribution from PyPI, uncompress and run
52-
``python3 setup.py install [--mpi]``.
5361

54-
The optional flag ``--mpi``, when enabled, will build the
55-
Charm++ library with the MPI communication layer (MPI headers and libraries
56-
need to be installed on the system).
62+
After building, you can run Charm4py examples. One example you can try is
63+
array_hello.py, which can be run as follows::
5764

58-
To build the latest *development* version, download Charm4py and Charm++ source code
59-
and run setup::
65+
$ cd examples/hello
66+
$ python -m charmrun.start +p2 array_hello.py
6067

61-
$ git clone https://github.com/UIUC-PPL/charm4py
62-
$ cd charm4py
63-
$ git clone https://github.com/UIUC-PPL/charm charm_src/charm
64-
$ python3 setup.py install [--mpi]
6568

6669
.. note::
6770

@@ -72,25 +75,27 @@ and run setup::
7275
to manually build the Charm++ library (see below).
7376

7477

75-
Manually building the Charm++ shared library
76-
--------------------------------------------
78+
pip
79+
---
7780

78-
This is needed when building Charm++ for specialized machine/network layers
79-
other than TCP and MPI (e.g. Cray XC/XE).
81+
This option installs prebuilt Charm4Py binaries from pip. The prebuilt pip libraries
82+
were built with Python 3.7.
8083

81-
Before running ``python3 setup.py`` in the steps above, enter the Charm++ source code
82-
directory (``charm_src/charm``), and manually build the Charm++ library. The build
83-
command syntax is::
84+
To install on regular Linux, macOS and Windows machines, do::
8485

85-
$ ./build charm4py <version> -j<N> --with-production
86+
$ pip3 install charm4py
8687

87-
where ``<version>`` varies based on the system and communication layer, and ``<N>``
88-
is the number of processes to use for compiling.
89-
For help in choosing the correct ``<version>``, please refer to the Charm++ manual_
90-
and the README in Charm++'s root directory.
88+
.. note::
89+
90+
This option uses Charm++'s TCP layer as the communication layer.
91+
If you want a faster communication layer (e.g. MPI), see "Install from
92+
source" below.
93+
94+
pip >= 8.0 is recommended to simplify the install and avoid building Charm4py or
95+
any dependencies from sources.
96+
97+
Note that a 64-bit version of Python is required to install and run Charm4py.
9198

92-
After the library has been built, continue with ``python3 setup.py install`` in the
93-
Charm4py source root directory.
9499

95100

96101
.. _manual: https://charm.readthedocs.io/en/latest/charm++/manual.html#installing-charm

setup.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import os
3+
import re
34
import shutil
45
import platform
56
import subprocess
@@ -8,6 +9,7 @@
89
from setuptools.command.build_py import build_py
910
from setuptools.command.install import install
1011
from distutils.errors import DistutilsSetupError
12+
from distutils.command.install_lib import install_lib as _install_lib
1113
from distutils import log
1214
import distutils
1315

@@ -17,10 +19,11 @@
1719
build_mpi = False
1820

1921

22+
2023
def get_build_machine():
2124
machine = platform.machine()
2225
if machine == 'arm64' or machine == 'aarch64':
23-
return 'arm8'
26+
return 'arm64'
2427
return machine
2528

2629

@@ -53,6 +56,10 @@ def get_build_triple(build_mpi):
5356
os.environ['ARCHFLAGS'] = f'-arch {machine}'
5457
libcharm_filename = 'libcharm.dylib'
5558
charmrun_filename = 'charmrun'
59+
if 'CPPFLAGS' in os.environ:
60+
os.environ['CPPFLAGS'] += ' -Wno-error=implicit-function-declaration' # needed because some functions used by charm4py are not exported by charm.
61+
else:
62+
os.environ['CPPFLAGS'] = '-Wno-error=implicit-function-declaration '
5663
else: # Linux
5764
libcharm_filename = 'libcharm.so'
5865
charmrun_filename = 'charmrun'
@@ -185,6 +192,7 @@ def build_libcharm(charm_src_dir, build_dir):
185192
for output_dir in lib_output_dirs:
186193
log.info('copying ' + os.path.relpath(lib_src_path) + ' to ' + os.path.relpath(output_dir))
187194
shutil.copy(lib_src_path, output_dir)
195+
188196

189197
# ---- copy charmrun ----
190198
charmrun_src_path = os.path.join(charm_src_dir, 'charm', 'bin', charmrun_filename)
@@ -257,6 +265,35 @@ def run(self):
257265
build_libcharm(os.path.join(os.getcwd(), 'charm_src'), self.build_lib)
258266
super(custom_build_ext, self).run()
259267

268+
class _renameInstalled(_install_lib):
269+
def __init__(self, *args, **kwargs):
270+
_install_lib.__init__(self, *args, **kwargs)
271+
272+
def install(self):
273+
log.info("Renaming libraries")
274+
outfiles = _install_lib.install(self)
275+
for file in outfiles:
276+
if "c_object_store" in file and system == "darwin":
277+
direc = os.path.dirname(file)
278+
install_name_command = "install_name_tool -change lib/libcharm.dylib "
279+
install_name_command += direc
280+
install_name_command += "/.libs/libcharm.dylib "
281+
install_name_command += direc
282+
install_name_command += "/c_object_store.*.so"
283+
log.info(install_name_command)
284+
os.system(install_name_command)
285+
elif "charmlib_cython" in file and system == "darwin":
286+
direc = os.path.dirname(file)
287+
install_name_command = "install_name_tool -change lib/libcharm.dylib "
288+
install_name_command += direc
289+
install_name_command += "/.libs/libcharm.dylib "
290+
install_name_command += direc
291+
install_name_command += "/charmlib_cython.*.so"
292+
log.info(install_name_command)
293+
os.system(install_name_command)
294+
return outfiles
295+
296+
260297

261298
extensions = []
262299
py_impl = platform.python_implementation()
@@ -369,6 +406,7 @@ def run(self):
369406
ext_modules=extensions,
370407
cmdclass = {'build_py': custom_build_py,
371408
'build_ext': custom_build_ext,
372-
'install': custom_install},
409+
'install': custom_install,
410+
'install_lib': _renameInstalled,},
373411
**additional_setup_keywords
374412
)

0 commit comments

Comments
 (0)