Skip to content

Commit

Permalink
Build python wheel using pregenerated SWIG bindings
Browse files Browse the repository at this point in the history
Signed-off-by: Marcela Melara <[email protected]>
  • Loading branch information
marcelamelara committed Apr 18, 2023
1 parent f09ada8 commit a687bdb
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 176 deletions.
3 changes: 1 addition & 2 deletions build/__tools__/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ try cmake --build . -- ${MAKE_ARGS}
yell --------------- PYTHON ---------------
cd $SRCDIR/python

try make ${MAKE_ARGS}
try make ${MAKE_ARGS} install
python3 -m build --wheel

yell --------------- SSERVICE ---------------
cd $SRCDIR/sservice
Expand Down
1 change: 1 addition & 0 deletions build/python_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build>=0.10.0
colorlog>=6.7.0
lmdb>=1.4.0
loguru>=0.6.0
Expand Down
1 change: 0 additions & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build
dist
*.egg-info
85 changes: 0 additions & 85 deletions python/Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions python/pdo/common/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
crypto.py
crypto_wrap.cpp
*swigPYTHON_wrap.cxx
*swig.py
90 changes: 4 additions & 86 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
script_dir = os.path.dirname(os.path.realpath(__file__))
pdo_root_dir = os.path.abspath(os.path.join(script_dir, '..'))

swig_dir = os.path.join(pdo_root_dir, 'swig-defs/build/')

install_root_dir = os.environ.get('PDO_HOME', '/opt/pdo')
bin_dir = os.path.join(install_root_dir, "bin")
dat_dir = os.path.join(install_root_dir, "data")
Expand All @@ -42,95 +44,11 @@
(etc_dir, [])
]

# -----------------------------------------------------------------
# set up common flags
#
# note that setuptools does not make it easy to pass custom command
# line parameters so we have to use environment variables
# -----------------------------------------------------------------
debug_flag = int(os.environ.get('PDO_DEBUG_BUILD', 0))
if debug_flag :
print("Build debug")

client_only_flag = int(os.environ.get('BUILD_CLIENT', 0))
if client_only_flag :
print("Build client")

compile_args = [
'-std=c++11',
'-Wno-switch',
'-Wno-unused-function',
'-Wno-unused-variable',
'-D_UNTRUSTED_=1',
]

if debug_flag :
compile_args += ['-g']

swig_flags = ['-c++', '-threads']

if client_only_flag :
common_libs = [
'cpdo-common',
'cpdo-crypto'
]
else :
common_libs = [
'updo-common',
'updo-crypto',
]

compile_defs = [
('_UNTRUSTED_', 1),
('PDO_DEBUG_BUILD', debug_flag),
]

if client_only_flag :
compile_defs += [ ('_CLIENT_ONLY_', 1) ]

# -----------------------------------------------------------------
# -----------------------------------------------------------------
version = subprocess.check_output(
os.path.join(pdo_root_dir, 'bin/get_version')).decode('ascii').strip()

# -----------------------------------------------------------------
# set up the key value module
# -----------------------------------------------------------------
key_value_module_files = [
os.path.join('pdo/common/key_value_swig', 'key_value_swig.i'),
os.path.join('pdo/common/key_value_swig', 'block_store.cpp'),
os.path.join('pdo/common/key_value_swig', 'key_value.cpp'),
os.path.join('pdo/common/key_value_swig', 'swig_utils.cpp'),
os.path.join(pdo_root_dir, 'common','c11_support.cpp'),
]

key_value_include_dirs = [
os.path.join(pdo_root_dir, 'common'),
os.path.join(pdo_root_dir, 'common/crypto'),
os.path.join(pdo_root_dir, 'common/state'),
]

if not client_only_flag :
key_value_include_dirs += [ os.path.join(os.environ['SGX_SDK'], "include") ]

key_value_libraries = common_libs + [ 'pdo-lmdb-block-store', 'lmdb' ] + openssl_libs

key_value_library_dirs = [
os.path.join(pdo_root_dir, "common", "build"),
]

key_value_module = Extension(
name = 'pdo.common.key_value_swig._key_value_swig',
sources = key_value_module_files,
swig_opts = swig_flags,
extra_compile_args = compile_args,
include_dirs = key_value_include_dirs,
library_dirs = key_value_library_dirs,
libraries = key_value_libraries,
define_macros = compile_defs,
language = 'c++',
)

# -----------------------------------------------------------------
# -----------------------------------------------------------------
setup(name='pdo_common_library',
Expand All @@ -139,10 +57,10 @@
author='Intel Labs',
packages=find_packages(),
install_requires=[],
python_requires='>3.5',
data_files=data_files,
namespace_packages=['pdo'],
ext_modules=[key_value_module],
package_data={'': ['_crypto.so']},
package_data={'pdo': [swig_dir+'_crypto_swig.so', swig_dir+'_key_value_swig.so']},
entry_points = {
'console_scripts': [
'pdo-configure-services = pdo.scripts.ConfigureCLI:configure_services',
Expand Down

0 comments on commit a687bdb

Please sign in to comment.