Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DepthAI and bumped API to 24 #1010

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Common {
public static final String MIN_AGP_VERSION = "7.0.0";

// This should match api_level in target/build-common.sh.
public static final int MIN_SDK_VERSION = 21;
public static final int MIN_SDK_VERSION = 24;

public static final int COMPILE_SDK_VERSION = 30;

Expand Down
4 changes: 3 additions & 1 deletion server/pypi/build-wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def parse_args(self):

ap.add_argument("--abi", metavar="ABI", required=True, choices=ABIS,
help="Android ABI: choices=[%(choices)s]")
ap.add_argument("--api-level", metavar="LEVEL", type=int, default=21,
ap.add_argument("--api-level", metavar="LEVEL", type=int, default=24,
help="Android API level: default=%(default)s")
ap.add_argument("--python", metavar="X.Y", help="Python version (required for "
"Python packages)"),
Expand Down Expand Up @@ -535,6 +535,7 @@ def update_environ(self):
pythonpath.append(os.environ["PYTHONPATH"])
env["PYTHONPATH"] = os.pathsep.join(pythonpath)

# NOTE(themarpe) - causes direct issues with pybind11 and PyInit_... symbols
# This flag often catches errors in .so files which would otherwise be delayed
# until runtime. (Some of the more complex build.sh scripts need to remove this, or
# use it more selectively.)
Expand Down Expand Up @@ -610,6 +611,7 @@ def generate_cmake_toolchain(self, env):
set(ANDROID_ABI {self.abi})
set(ANDROID_PLATFORM {self.api_level})
set(ANDROID_STL c++_shared)
set(ANDROID_USE_LEGACY_TOOLCHAIN_FILE OFF) # Legacy does NOT play well with certain forwarded LDFLAGS (cmake_example error)
include({ndk}/build/cmake/android.toolchain.cmake)

list(INSERT CMAKE_FIND_ROOT_PATH 0 {self.host_env}/chaquopy)
Expand Down
12 changes: 7 additions & 5 deletions server/pypi/packages/chaquopy-libcxx/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/bash
set -eu

toolchain=$(realpath $(dirname $CC)/..)
RESOLVED_CC=$($CC -print-prog-name=clang)
toolchain=$(realpath $(dirname $RESOLVED_CC)/..)

header_version=$(cat $toolchain/sysroot/usr/include/c++/v1/__libcpp_version)
if [[ $header_version != $PKG_VERSION ]]; then
echo "Header version '$header_version' doesn't match meta.yaml version '$PKG_VERSION'"
actual_version=$(printf "#include <ciso646>\nint main () {}" | $CC -E -stdlib=libc++ -x c++ -dM - | grep -w "#define _LIBCPP_VERSION" | cut -d' ' -f3)
# actual_version=$(cat $toolchain/sysroot/usr/include/c++/v1/__libcpp_version)
if [[ $actual_version != $PKG_VERSION ]]; then
echo "Actual version '$actual_version' doesn't match meta.yaml version '$PKG_VERSION'"
exit 1
fi

mkdir -p $PREFIX/lib
cp $toolchain/sysroot/usr/lib/$CHAQUOPY_TRIPLET/libc++_shared.so $PREFIX/lib
cp $toolchain/sysroot/usr/lib/$HOST/libc++_shared.so $PREFIX/lib
2 changes: 1 addition & 1 deletion server/pypi/packages/chaquopy-libcxx/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package:
name: chaquopy-libcxx
version: "11000" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py.
version: "170000" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py.

source: null
19 changes: 19 additions & 0 deletions server/pypi/packages/depthai/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package:
name: depthai
version: "2.23.0.0" # If a release is picked
# version: "2.23.0.0.dev0+9f00516f332ac22e76ae34bcd7dc4de683436a9d"

source:
git_url: https://github.com/luxonis/depthai-python.git
git_rev: 9f00516f332ac22e76ae34bcd7dc4de683436a9d
# path: [path/to/depthai-python]

requirements:
build:
- cmake
host:
- python

build:
script_env:
- CI=1 # Set for a release
40 changes: 40 additions & 0 deletions server/pypi/packages/depthai/patches/bindings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
diff --git a/src/py_bindings.cpp b/src/py_bindings.cpp
index e6db7796..9238ed37 100644
--- a/src/py_bindings.cpp
+++ b/src/py_bindings.cpp
@@ -82,9 +82,34 @@ PYBIND11_MODULE(depthai, m)
// ignore
}

+ // Apply JNIEnv pointer
+ constexpr static const char* javavmEnvKey = "DEPTHAI_LIBUSB_ANDROID_JAVAVM";
+ // Retrieve from env first
+ std::string javavmEnvStr = std::getenv(javavmEnvKey) != nullptr ? std::string(std::getenv(javavmEnvKey)) : "";
+ 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, &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
}
24 changes: 24 additions & 0 deletions server/pypi/packages/depthai/patches/chaquopy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/setup.py b/setup.py
index 341ab5f2..efdde517 100644
--- a/setup.py
+++ b/setup.py
@@ -111,6 +111,8 @@ class CMakeBuild(build_ext):
env = {key:env[key] for key in env if key.upper() != 'pythonLocation'.upper()}
env['pythonLocation'] = str(Path(sys.executable).parent.absolute())

+ # Chaquopy added
+ cmake_args += ["-DCMAKE_TOOLCHAIN_FILE=" + os.path.abspath("../chaquopy.toolchain.cmake")]

# Pass a commit hash
if buildCommitHash != None :
@@ -141,6 +143,10 @@ class CMakeBuild(build_ext):
except:
freeMemory = 4000

+ # Add additional cmake build args from environment
+ if 'CMAKE_BUILD_ARGS' in os.environ:
+ build_args += [os.environ['CMAKE_BUILD_ARGS']]
+
# Configure and build
# Windows
if platform.system() == "Windows":
15 changes: 15 additions & 0 deletions server/pypi/packages/depthai/patches/crosscompilation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d8fc4fee..ac3c4859 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
22 changes: 22 additions & 0 deletions server/pypi/packages/depthai/patches/dependencies.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/depthai-core/cmake/Hunter/config.cmake b/depthai-core/cmake/Hunter/config.cmake
index 8b1ec798..1e4c58d8 100644
--- a/depthai-core/cmake/Hunter/config.cmake
+++ b/depthai-core/cmake/Hunter/config.cmake
@@ -8,8 +8,8 @@ hunter_config(
hunter_config(
XLink
VERSION "luxonis-2021.4.2-develop"
- URL "https://github.com/luxonis/XLink/archive/c940feaf9321f06a7d9660f28e686a9718135f38.tar.gz"
- SHA1 "52935b6ceb470ee632de3348b9d2aaa2c6c24ac0"
+ URL "https://github.com/luxonis/XLink/archive/6862ec0e5f82efb1148a0b0a21486aaf9831451c.tar.gz"
+ SHA1 "450614ab33425b34a62d9de6d65441d95d708710"
CMAKE_ARGS
XLINK_ENABLE_LIBUSB=${DEPTHAI_ENABLE_LIBUSB}
)
@@ -124,5 +124,5 @@ hunter_config(
CMAKE_ARGS
WITH_UDEV=OFF
# Build shared libs by default to not cause licensing issues
- BUILD_SHARED_LIBS=ON
+ BUILD_SHARED_LIBS=OFF
)
4 changes: 2 additions & 2 deletions target/build-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# You may also override the following:
: ${abi:=$(basename $prefix)}
: ${api_level:=21} # Should match MIN_SDK_VERSION in Common.java.
: ${api_level:=24} # Should match MIN_SDK_VERSION in Common.java.

# When moving to a new version of the NDK, carefully review the following:
#
Expand All @@ -16,7 +16,7 @@
# * According to https://github.com/kivy/python-for-android/pull/2615, the mzakharo
# build of gfortran is not compatible with NDK version 23, which is the version in
# which they removed the GNU binutils.
ndk_version=22.1.7171670 # See ndkDir in product/runtime/build.gradle.
ndk_version=26.1.10909125 # See ndkDir in product/runtime/build.gradle.

ndk=${ANDROID_HOME:?}/ndk/$ndk_version
if ! [ -e $ndk ]; then
Expand Down