bindings: package ns-3 as a pip wheel
Includes: - Python examples to test Brite, Click and Openflow - CI jobs for manylinux packaging of pip wheel - Support for Linux distributions with lib and lib64 directories - Configuration of RPATH not to require setting LD_LIBRARY_PATH Signed-off-by: Gabriel Ferreira <gabrielcarvfer@gmail.com>
This commit is contained in:
@@ -36,6 +36,9 @@ option(NS3_ENABLE_SUDO
|
||||
"Set executables ownership to root and enable the SUID flag" OFF
|
||||
)
|
||||
|
||||
# a flag that controls some aspects related to pip packaging
|
||||
option(NS3_PIP_PACKAGING "Control aspects related to pip wheel packaging" OFF)
|
||||
|
||||
# Replace default CMake messages (logging) with custom colored messages as early
|
||||
# as possible
|
||||
include(${PROJECT_SOURCE_DIR}/build-support/3rd-party/colored-messages.cmake)
|
||||
@@ -152,6 +155,25 @@ link_directories(${CMAKE_OUTPUT_DIRECTORY}/lib)
|
||||
include(GNUInstallDirs)
|
||||
include(build-support/custom-modules/ns3-cmake-package.cmake)
|
||||
|
||||
# Set RPATH not too need LD_LIBRARY_PATH after installing
|
||||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:$ORIGIN/:$ORIGIN/../lib")
|
||||
|
||||
# Add the 64 suffix to the library path when manually requested with the
|
||||
# -DNS3_USE_LIB64=ON flag. May be necessary depending on the target platform.
|
||||
# This is used to properly build the manylinux pip wheel.
|
||||
if(${NS3_USE_LIB64})
|
||||
link_directories(${CMAKE_OUTPUT_DIRECTORY}/lib64)
|
||||
set(CMAKE_INSTALL_RPATH
|
||||
"${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib64:$ORIGIN/:$ORIGIN/../lib64"
|
||||
)
|
||||
endif()
|
||||
|
||||
# cmake-format: off
|
||||
# You are a wizard, Harry!
|
||||
# source: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
|
||||
# cmake-format: on
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
if(${XCODE})
|
||||
# Is that so hard not to break people's CI, AAPL? Why would you output the
|
||||
# targets to a Debug/Release subfolder? Why?
|
||||
@@ -816,7 +838,7 @@ macro(process_options)
|
||||
find_package(Python3 COMPONENTS Interpreter Development)
|
||||
else()
|
||||
# cmake-format: off
|
||||
set(Python_ADDITIONAL_VERSIONS 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9)
|
||||
set(Python_ADDITIONAL_VERSIONS 3.6 3.7 3.8 3.9 3.10 3.11)
|
||||
# cmake-format: on
|
||||
find_package(PythonInterp)
|
||||
find_package(PythonLibs)
|
||||
@@ -924,6 +946,9 @@ macro(process_options)
|
||||
"Set NS3_BINDINGS_INSTALL_DIR=\"${SUGGESTED_BINDINGS_INSTALL_DIR}\" to install it to the default location."
|
||||
)
|
||||
else()
|
||||
if(${NS3_BINDINGS_INSTALL_DIR} STREQUAL "INSTALL_PREFIX")
|
||||
set(NS3_BINDINGS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
|
||||
endif()
|
||||
install(FILES bindings/python/ns__init__.py
|
||||
DESTINATION ${NS3_BINDINGS_INSTALL_DIR}/ns RENAME __init__.py
|
||||
)
|
||||
|
||||
11
build-support/pip-wheel/auditwheel-exclude-list.py
Normal file
11
build-support/pip-wheel/auditwheel-exclude-list.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
|
||||
ns3_path = os.path.dirname(os.path.abspath(os.sep.join([__file__, "../../"])))
|
||||
|
||||
for variant in ["lib", "lib64"]:
|
||||
lib_dir = os.path.abspath(os.path.join(ns3_path, f"build/{variant}"))
|
||||
if not os.path.exists(lib_dir):
|
||||
continue
|
||||
for lib in os.listdir(lib_dir):
|
||||
if "libns3" in lib:
|
||||
print(f"--exclude {lib}", end=' ')
|
||||
10
build-support/pip-wheel/ns/__init__.py
Normal file
10
build-support/pip-wheel/ns/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# This is a stub module that loads the actual ns-3
|
||||
# bindings from nsnam.ns
|
||||
import sys
|
||||
|
||||
try:
|
||||
import ns3.ns
|
||||
sys.modules['ns'] = ns3.ns
|
||||
except ModuleNotFoundError as e:
|
||||
print("Install the ns3 package with pip install ns3.", file=sys.stderr)
|
||||
exit(-1)
|
||||
11
build-support/pip-wheel/visualizer/__init__.py
Normal file
11
build-support/pip-wheel/visualizer/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# This is a stub module that loads the actual visualizer
|
||||
# from nsnam.visualizer
|
||||
import sys
|
||||
|
||||
try:
|
||||
import ns3.visualizer
|
||||
except ModuleNotFoundError as e:
|
||||
print("Install the ns3 package with pip install ns3.", file=sys.stderr)
|
||||
exit(-1)
|
||||
|
||||
from ns3.visualizer import start, register_plugin, set_bounds, add_initialization_hook
|
||||
Reference in New Issue
Block a user