Project development
Here is an example of a simple example of project to build. The example taken is helloword, first with a native build and then via a crossbuild.
In this part, rp-cli will be used to enter the container to execute the commands directly inside.
Native build
To enter in the container by using rp-cli, do the following command in your host:
rp-cli local exec -- bash
If there are any project dependencies missing, just use sudo dnf install
to
install them, then execute the following:
cd /home/devel/gitsources
git clone https://github.com/redpesk-samples/helloworld-binding.git
cd helloworld-binding
mkdir build && cd build
cmake ..
If everything is correct, you will have somehing like:
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is GNU 8.3.1
-- The CXX compiler identification is GNU 8.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Distribution detected (separated by ';' choose one of them) rhel;fedora;centos
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/01-build_options.cmake
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.4.2")
-- Checking for module 'json-c'
-- Found json-c, version 0.13.1
-- Checking for module 'afb-binding'
-- Found afb-binding, version 4.0.2
-- Checking for module 'afb-libhelpers'
-- Found afb-libhelpers, version 10.0.0
-- Checking for module 'libsystemd'
-- Found libsystemd, version 239
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/02-variables.cmake
-- Check gcc_minimal_version (found gcc version 8.3.1) (found g++ version 8.3.1)
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/03-macros.cmake
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/04-extra_targets.cmake
-- Overwrite the CMAKE default install prefix with /home/devel/opt
.. Warning: RSYNC_TARGET RSYNC_PREFIX not defined 'make remote-target-populate' not instanciated
-- Notice: Using default test widget configuration's file.
-- If you want to use a customized test-config.xml template then specify TEST_WIDGET_CONFIG_TEMPLATE in your config.cmake file.
.. Warning: RSYNC_TARGET not defined 'make widget-target-install' not instanciated
-- Configuring done
-- Generating done
-- Build files have been written to: /home/devel/gitsources/helloworld-binding/build
Then, just do a make:
make -j
The build will be launched:
Scanning dependencies of target test-files
Scanning dependencies of target prepare_package
Scanning dependencies of target helloworld-skeleton
Scanning dependencies of target htdocs
Scanning dependencies of target helloworld-config
Scanning dependencies of target prepare_package_test
Scanning dependencies of target fixture-files
Scanning dependencies of target helloworld-subscribe-event
[ 3%] Generating htdocs
Scanning dependencies of target autobuild
[ 7%] Generating test-files
[ 11%] Generating helloworld-config
[ 14%] Generating package-test
[ 18%] Generating package
[ 22%] Generating package-test/htdocs
[ 25%] Building C object helloworld-subscribe-event/CMakeFiles/helloworld-subscribe-event.dir/helloworld-event-service-binding.c.o
[ 29%] Generating fixture-files
[ 33%] Building C object helloworld-skeleton/CMakeFiles/helloworld-skeleton.dir/helloworld-service-binding.c.o
[ 40%] Generating package-test/bin
[ 40%] Built target autobuild
[ 44%] Generating package-test/etc
[ 48%] Generating package-test/lib
[ 51%] Generating package-test/var
[ 51%] Built target htdocs
[ 55%] Generating package/bin
Warning: LUA_CHECKER not found. Not verification made on files !
[ 59%] Generating package/etc
Warning: JSON_CHECKER not found. Not verification made on files !
Warning: LUA_CHECKER not found. Not verification made on files !
[ 62%] Generating package/lib
[ 66%] Generating package/htdocs
[ 70%] Generating package/var
[ 70%] Built target test-files
[ 70%] Built target helloworld-config
Scanning dependencies of target project_populate_htdocs
[ 70%] Built target fixture-files
[ 70%] Built target prepare_package_test
[ 70%] Built target prepare_package
Scanning dependencies of target project_populate_test-files
[ 74%] Generating package/htdocs/htdocs
Scanning dependencies of target project_populate_helloworld-config
Scanning dependencies of target project_populate_fixture-files
[ 81%] Generating package-test/etc/helloworld-config
[ 81%] Generating package-test/var/test-files
[ 85%] Generating package-test/var/fixture-files
[ 85%] Built target project_populate_htdocs
[ 85%] Built target project_populate_test-files
[ 85%] Built target project_populate_fixture-files
[ 85%] Built target project_populate_helloworld-config
/home/devel/gitsources/helloworld-binding/helloworld-subscribe-event/helloworld-event-service-binding.c: In function ‘timerCount’:
/home/devel/gitsources/helloworld-binding/helloworld-subscribe-event/helloworld-event-service-binding.c:33:6: warning: variable ‘listeners’ set but not used [-Wunused-but-set-variable]
int listeners;
^~~~~~~~~
[ 88%] Linking C shared module afb-helloworld-skeleton.so
[ 92%] Linking C shared module afb-helloworld-subscribe-event.so
[ 92%] Built target helloworld-skeleton
[ 92%] Built target helloworld-subscribe-event
Scanning dependencies of target project_populate_helloworld-skeleton
Scanning dependencies of target project_populate_helloworld-subscribe-event
[ 96%] Generating package/lib/afb-helloworld-skeleton.so
[100%] Generating package/lib/afb-helloworld-subscribe-event.so
[100%] Built target project_populate_helloworld-skeleton
[100%] Built target project_populate_helloworld-subscribe-event
Scanning dependencies of target populate
[100%] Built target populate
Scanning dependencies of target helloworld-binding_build_done
++ Debug from afb-binder --port=1234 --ldpaths=package --workdir=. --roothttp=../htdocs --verbose
[100%] Built target helloworld-binding_build_done
# leave the container
exit
Crossbuild
To enter the container by using rp-cli, do the following command in your host:
rp-cli local exec -- bash
The container comes with a generic aarch64
ready build environment.
To be in a cross-compiling environment you will have to source a script to setup your environment for cross-compilation (cross-compiler and libraries paths) with the following command line:
$ . /usr/aarch64-linux-gnu/bin/cross-profile-setup-sdk-aarch64.sh
After sourcing the generic cross environment, you can export or source your project specific environment with for example :
$ export CROSS_COMPILE="aarch64-linux-gnu-"
$ export ARCH="arm64"
Let’s see with an example of how to crossbuild a helloworld binding:
cd home/devel/gitsources
git clone https://github.com/redpesk-samples/helloworld-binding.git
cd helloworld-binding
mkdir build && cd build
. /usr/aarch64-linux-gnu/bin/cross-profile-setup-sdk-aarch64.sh
# Project specific environment can be sourced/exported here if needed
cmake ..
If everything goes as planned, you will have an output like that:
Distribution detected (separated by ';' choose one of them) redpesk
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/01-build_options.cmake
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/02-variables.cmake
-- Check gcc_minimal_version (found gcc version 8.1.1) (found g++ version 8.1.1)
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/03-macros.cmake
Include: /usr/share/cmake/Modules/CMakeAfbTemplates/cmake/cmake.d/04-extra_targets.cmake
.. Warning: RSYNC_TARGET RSYNC_PREFIX not defined 'make remote-target-populate' not instanciated
.. Warning: RSYNC_TARGET not defined 'make widget-target-install' not instanciated
-- Configuring done
-- Generating done
-- Build files have been written to: /home/devel/gitsources/helloworld-binding/build
Then you can continue with a make:
make -j
Scanning dependencies of target test-files
Scanning dependencies of target prepare_package
Scanning dependencies of target helloworld-skeleton
Scanning dependencies of target htdocs
Scanning dependencies of target prepare_package_test
Scanning dependencies of target helloworld-subscribe-event
Scanning dependencies of target fixture-files
Scanning dependencies of target helloworld-config
[ 7%] Generating package
[ 7%] Building C object helloworld-skeleton/CMakeFiles/helloworld-skeleton.dir/helloworld-service-binding.c.o
[ 11%] Generating htdocs
[ 14%] Generating package-test
Scanning dependencies of target autobuild
[ 18%] Generating test-files
[ 22%] Generating fixture-files
[ 25%] Generating package-test/htdocs
[ 29%] Generating helloworld-config
[ 33%] Building C object helloworld-subscribe-event/CMakeFiles/helloworld-subscribe-event.dir/helloworld-event-service-binding.c.o
[...]
[ 96%] Generating package/lib/afb-helloworld-skeleton.so
[ 96%] Built target project_populate_helloworld-skeleton
[ 96%] Built target helloworld-subscribe-event
Scanning dependencies of target project_populate_helloworld-subscribe-event
[100%] Generating package/lib/afb-helloworld-subscribe-event.so
[100%] Built target project_populate_helloworld-subscribe-event
Scanning dependencies of target populate
[100%] Built target populate
Scanning dependencies of target helloworld-binding_build_done
++ Debug from afb-binder --port=1234 --ldpaths=package --workdir=. --roothttp=../htdocs --token= --verbose
[100%] Built target helloworld-binding_build_done