Skip to content

Commit

Permalink
Use pkg-config to check for dependencies (#328)
Browse files Browse the repository at this point in the history
* Use pkg config to check for dependencies

* Make python Dockerfile more consistent with source and protocol

* Use the python pkgconfig package instead of cmake CLI

* 6.3.3 -> 6.3.4

* Update CHANGELOG
  • Loading branch information
domire8 authored Dec 20, 2022
1 parent 0dc4d9b commit d305bc3
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Release Versions:

- Add pkg-config files for control libraries (#326)
- Add pkg-config files for clproto (#327)
- Use pkg-config to check for dependencies (#328)

## 6.3.1

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.3
6.3.4
2 changes: 1 addition & 1 deletion demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(control_libraries 6.3.3 CONFIG REQUIRED)
find_package(control_libraries 6.3.4 CONFIG REQUIRED)

set(DEMOS_SCRIPTS
task_space_control_loop
Expand Down
2 changes: 1 addition & 1 deletion doxygen/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Control Libraries"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 6.3.3
PROJECT_NUMBER = 6.3.4

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion protocol/clproto_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(clproto VERSION 6.3.3)
project(clproto VERSION 6.3.4)

# Default to C99
if(NOT CMAKE_C_STANDARD)
Expand Down
11 changes: 8 additions & 3 deletions protocol/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,18 @@ if [ "${BINDINGS_ONLY}" == true ]; then
fi

PROTOBUF_INSTALL=$(ldconfig -p | grep libprotobuf)
if [ -z "${PROTOBUF_INSTALL}" ] ]; then
if [ -z "${PROTOBUF_INSTALL}" ]; then
echo ">>> LIBPROTOBUF NOT FOUND"
install_protobuf || exit 1
fi

STATE_REPRESENTATION_INSTALL=$(ldconfig -p | grep libstate_representation)
if [ -z "${STATE_REPRESENTATION_INSTALL}" ]; then
if [ -z $(which pkg-config) ]; then
echo ">>> INSTALLING pkg-config tool"
apt-get update && apt-get install "${AUTO_INSTALL}" pkg-config || exit 1
fi

pkg-config state_representation --atleast-version=$(cat "$(dirname "${SCRIPT_DIR}")"/VERSION)
if [ "$?" != 0 ]; then
echo ">>> STATE REPRESENTATION LIBRARY NOT FOUND!"
install_state_representation
fi
Expand Down
4 changes: 4 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__pycache__
.cache
.local
build
control_libraries.egg-info
19 changes: 9 additions & 10 deletions python/Dockerfile.python
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ WORKDIR /source
RUN git clone --depth 1 --branch ${BRANCH} https://github.com/epfl-lasa/control-libraries
RUN bash control-libraries/source/install.sh --auto
RUN bash control-libraries/protocol/install.sh --auto

RUN rm -rf control-libraries

FROM source as build

RUN rm -rf control-libraries/python/include control-libraries/python/source
COPY include control-libraries/python/include
COPY source control-libraries/python/source
COPY pyproject.toml setup.py control-libraries/python/
USER developer
WORKDIR ${HOME}/python
# copy these files separately because otherwise any changes in the test directory would trigger the install again
COPY include include
COPY source source
COPY pyproject.toml setup.py .
ENV OSQP_INCLUDE_DIR /usr/local/include/osqp
RUN pip3 install control-libraries/python
RUN pip3 install .


FROM build as testing

USER developer
WORKDIR ${HOME}

COPY test ./test
COPY test test
RUN python3 -m unittest

CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ A Dockerfile and run script are provided to test the installation of the binding

The docker image installs the core control libraries and subsequently installs the python bindings.

The [`run.sh`](./run.sh) script will build the docker image and launch an interactive container
The [`build-test.sh`](./build-test.sh) script will build the docker image and launch an interactive container
with the test files in the [`test`](./test) directory copied to the local path.

The run script tries to the clone the current local git branch when installing the control libraries
Expand Down
8 changes: 4 additions & 4 deletions python/run.sh → python/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BASE_TAG="latest"

BRANCH=$(git branch --show-current)

HELP_MESSAGE="Usage: run.sh [-b <branch>] [--base-tag <base-tag>] [-r] [-v]
HELP_MESSAGE="Usage: build-test.sh [-b <branch>] [--base-tag <base-tag>] [-r] [-v]
Options:
-b, --branch <branch> Specify the branch of control libraries
that should be used to build the image.
Expand All @@ -21,11 +21,11 @@ BUILD_FLAGS=()
while [[ $# -gt 0 ]]; do
opt="$1"
case $opt in
-b|--branch) BRANCH=$2;shift 2;;
-b|--branch) BRANCH=$2; shift 2;;
--base-tag) BASE_TAG=$2; shift 2;;
-r|--rebuild) BUILD_FLAGS+=(--no-cache); shift ;;
-v|--verbose) BUILD_FLAGS+=(--progress=plain); shift ;;
-h|--help) echo "${HELP_MESSAGE}" ; exit 0 ;;
-h|--help) echo "${HELP_MESSAGE}"; exit 0 ;;
*) echo 'Error in command line parsing' >&2
echo -e "\n${HELP_MESSAGE}"
exit 1
Expand All @@ -43,6 +43,6 @@ docker pull ghcr.io/epfl-lasa/control-libraries/development-dependencies:"${BASE
DOCKER_BUILDKIT=1 docker build . --file ./Dockerfile.python "${BUILD_FLAGS[@]}" || exit 1

docker run -it --rm \
--volume "$(pwd)"/test:/home/developer/test:rw \
--volume "$(pwd)":/home/developer/python:rw \
--name "${IMAGE_NAME//[\/.:]/-}" \
"${IMAGE_NAME}"
1 change: 1 addition & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires = [
"setuptools>=42",
"wheel",
"pybind11>=2.7.0",
"pkgconfig>=1.5.5"
]

build-backend = "setuptools.build_meta"
12 changes: 7 additions & 5 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import os
import sys
import warnings
from glob import glob

import pkgconfig
from pybind11.setup_helpers import ParallelCompile, naive_recompile
from pybind11.setup_helpers import Pybind11Extension
from setuptools import setup

# names of the environment variables that define osqp and openrobots include directories
osqp_path_var = 'OSQP_INCLUDE_DIR'

__version__ = "6.3.3"
__version__ = "6.3.4"
__libraries__ = ['state_representation', 'clproto', 'controllers', 'dynamical_systems', 'robot_model']
__include_dirs__ = ['include']

Expand All @@ -20,16 +22,15 @@

# check that necessary libraries can be found
try:
eigen_dir = os.popen(
'cmake --find-package -DNAME=Eigen3 -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=COMPILE').read().strip()
eigen_dir = pkgconfig.cflags('eigen3')
if eigen_dir.startswith('-I'):
__include_dirs__.append(eigen_dir.lstrip('-I'))
else:
raise Exception('Could not find Eigen3 package!')

for lib in __libraries__:
status = os.popen(f'ldconfig -p | grep {lib}').read().strip()
if len(status) == 0:
status = pkgconfig.installed(lib, f'>= {__version__}')
if not status:
msg = f'Could not find library {lib}!'
if lib == 'clproto':
warnings.warn(f'{msg} The clproto module will not be installed.')
Expand Down Expand Up @@ -59,6 +60,7 @@
except Exception as e:
msg = f'Error with control library dependencies: {e.args[0]} Ensure the control libraries are properly installed.'
warnings.warn(msg)
sys.exit(1)

ParallelCompile('NPY_NUM_BUILD_JOBS', needs_recompile=naive_recompile).install()

Expand Down
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(control_libraries VERSION 6.3.3)
project(control_libraries VERSION 6.3.4)

# Build options
option(BUILD_TESTING "Build all tests." OFF)
Expand Down
8 changes: 4 additions & 4 deletions source/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ if [ -z $(which pkg-config) ]; then
apt-get update && apt-get install "${AUTO_INSTALL}" pkg-config || exit 1
fi

INSTALLED_EIGEN=$(pkg-config --modversion eigen3) || exit 0
if [ "${INSTALLED_EIGEN::4}" != "${EIGEN_VERSION::4}" ]; then
pkg-config eigen3 --atleast-version="${EIGEN_VERSION}"
if [ "$?" != 0 ]; then
echo ">>> INSTALLING EIGEN"
mkdir -p "${SOURCE_PATH}"/tmp/lib && cd "${SOURCE_PATH}"/tmp/lib || exit 1
wget -c "https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_VERSION}/eigen-${EIGEN_VERSION}.tar.gz" -O - | tar -xz || exit 1
Expand All @@ -108,8 +108,8 @@ if [ "${BUILD_ROBOT_MODEL}" == "ON" ]; then
echo ">>> INSTALLING ROBOT MODEL DEPENDENCIES"
apt-get update && apt-get install "${AUTO_INSTALL}" libboost-all-dev liburdfdom-dev || exit 1

INSTALLED_PINOCCHIO=$(pkg-config --modversion pinocchio)
if [ "${INSTALLED_PINOCCHIO}" != "${PINOCCHIO_TAG}" ]; then
pkg-config pinocchio --atleast-version=${PINOCCHIO_TAG}
if [ "$?" != 0 ]; then
mkdir -p "${SOURCE_PATH}"/tmp/lib && cd "${SOURCE_PATH}"/tmp/lib || exit 1

echo ">>> INSTALLING OSQP [1/3]"
Expand Down

0 comments on commit d305bc3

Please sign in to comment.