Skip to content

Commit

Permalink
Some changes WRT Android build
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Nov 3, 2023
1 parent 0abab20 commit 1ea482a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ endif()

# Add stubs (pyi) generation step after building bindings
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "from mypy import api" RESULT_VARIABLE error OUTPUT_QUIET ERROR_QUIET)
if(error)
message(WARNING "Mypy not available - stubs won't be generated or checked")
if(error OR CMAKE_CROSSCOMPILING)
message(WARNING "Mypy not available or cross compiling - stubs won't be generated or checked")
else()
get_target_property(bindings_directory ${TARGET_NAME} LIBRARY_OUTPUT_DIRECTORY)
if(NOT bindings_directory)
Expand Down
2 changes: 1 addition & 1 deletion depthai-core
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def build_extension(self, ext):
freeMemory = 4000

# Configure and build

# Add additional cmake build args from environment
if 'CMAKE_BUILD_ARGS' in os.environ:
build_args += [os.environ['CMAKE_BUILD_ARGS']]

# Windows
if platform.system() == "Windows":
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
Expand Down
26 changes: 25 additions & 1 deletion src/py_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,33 @@ PYBIND11_MODULE(depthai, m)
// ignore
}

// Apply JavaVM pointer
std::string javavmEnvStr;
constexpr static const char* javavmEnvKey = "DEPTHAI_LIBUSB_ANDROID_JAVAVM";
try {
auto sysModule = py::module_::import("sys");
if(py::hasattr(sysModule, javavmEnvKey)){
javavmEnvStr = sysModule.attr(javavmEnvKey).cast<std::string>();
}
} catch (...) {
// ignore
}
try {
auto builtinsModule = py::module_::import("builtins");
if(py::hasattr(builtinsModule, javavmEnvKey)){
javavmEnvStr = builtinsModule.attr(javavmEnvKey).cast<std::string>();
}
} catch (...){
// ignore
}
// JNIEnv handling
void* javavm = nullptr;
// Read the uintptr_t value from the decimal string
sscanf(javavmEnvStr.c_str(), "%" SCNuPTR, reinterpret_cast<uintptr_t*>(&javavm));

// Call dai::initialize on 'import depthai' to initialize asap with additional information to print
try {
dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME, installSignalHandler);
dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME, installSignalHandler, javavm);
} catch (const std::exception&) {
// ignore, will be initialized later on if possible
}
Expand Down

0 comments on commit 1ea482a

Please sign in to comment.