mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 08:48:13 +00:00
Cleanups/fixes for the library issue conglomerate (#897)
* Python: Disable distribution of static library on linux and macos; add environment variable LIBUNICORN_PATH to let user specify location of native library; prevent build of native library if this option is enabled; closes #869 * Python: Update README.TXT to describe how to manage the building and usage of the native library
This commit is contained in:
parent
13007eb12a
commit
12642c2555
3 changed files with 22 additions and 8 deletions
|
@ -8,6 +8,11 @@ from source.
|
|||
This will build the core C library, package it with the python bindings,
|
||||
and install it to your system.
|
||||
|
||||
If you want to prevent the build of the native library during the python installation,
|
||||
set the environment variable LIBUNICORN_PATH. You may also set this to a directory
|
||||
containing libunicorn.so if you wish to use a verison of the native library other than
|
||||
the globally installed one.
|
||||
|
||||
|
||||
2. Installing on Windows:
|
||||
|
||||
|
|
|
@ -65,13 +65,13 @@ else:
|
|||
|
||||
if SYSTEM == 'darwin':
|
||||
LIBRARY_FILE = "libunicorn.dylib"
|
||||
STATIC_LIBRARY_FILE = 'libunicorn.a'
|
||||
STATIC_LIBRARY_FILE = None
|
||||
elif SYSTEM in ('win32', 'cygwin'):
|
||||
LIBRARY_FILE = "unicorn.dll"
|
||||
STATIC_LIBRARY_FILE = "unicorn.lib"
|
||||
else:
|
||||
LIBRARY_FILE = "libunicorn.so"
|
||||
STATIC_LIBRARY_FILE = 'libunicorn.a'
|
||||
STATIC_LIBRARY_FILE = None
|
||||
|
||||
def clean_bins():
|
||||
shutil.rmtree(LIBS_DIR, ignore_errors=True)
|
||||
|
@ -153,9 +153,11 @@ def build_libraries():
|
|||
# check if a prebuilt library exists
|
||||
# if so, use it instead of building
|
||||
if os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE)) \
|
||||
and os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE)):
|
||||
and (STATIC_LIBRARY_FILE is None \
|
||||
or os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE))):
|
||||
shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE), LIBS_DIR)
|
||||
shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE), LIBS_DIR)
|
||||
if STATIC_LIBRARY_FILE is not None:
|
||||
shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE), LIBS_DIR)
|
||||
return
|
||||
|
||||
# otherwise, build!!
|
||||
|
@ -181,7 +183,8 @@ def build_libraries():
|
|||
shutil.copy(LIBRARY_FILE, LIBS_DIR)
|
||||
try:
|
||||
# static library may fail to build on windows if user doesn't have visual studio installed. this is fine.
|
||||
shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR)
|
||||
if STATIC_LIBRARY_FILE is not None:
|
||||
shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR)
|
||||
except:
|
||||
print('Warning: Could not build static library file! This build is not appropriate for a binary distribution')
|
||||
# enforce this
|
||||
|
@ -198,8 +201,11 @@ class custom_sdist(sdist):
|
|||
|
||||
class custom_build(build):
|
||||
def run(self):
|
||||
log.info("Building C extensions")
|
||||
build_libraries()
|
||||
if 'LIBUNICORN_PATH' in os.environ:
|
||||
log.info("Skipping building C extensions since LIBUNICORN_PATH is set")
|
||||
else:
|
||||
log.info("Building C extensions")
|
||||
build_libraries()
|
||||
return build.run(self)
|
||||
|
||||
class custom_bdist_egg(bdist_egg):
|
||||
|
|
|
@ -71,13 +71,15 @@ def _load_lib(path):
|
|||
_uc = None
|
||||
|
||||
# Loading attempts, in order
|
||||
# - user-provided environment variable
|
||||
# - pkg_resources can get us the path to the local libraries
|
||||
# - we can get the path to the local libraries by parsing our filename
|
||||
# - global load
|
||||
# - python's lib directory
|
||||
# - last-gasp attempt at some hardcoded paths on darwin and linux
|
||||
|
||||
_path_list = [pkg_resources.resource_filename(__name__, 'lib'),
|
||||
_path_list = [os.getenv('LIBUNICORN_PATH', None),
|
||||
pkg_resources.resource_filename(__name__, 'lib'),
|
||||
os.path.join(os.path.split(__file__)[0], 'lib'),
|
||||
'',
|
||||
distutils.sysconfig.get_python_lib(),
|
||||
|
@ -88,6 +90,7 @@ _path_list = [pkg_resources.resource_filename(__name__, 'lib'),
|
|||
#print("-" * 80)
|
||||
|
||||
for _path in _path_list:
|
||||
if _path is None: continue
|
||||
_uc = _load_lib(_path)
|
||||
if _uc is not None: break
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue