crownstone / bluenet

Bluenet is the in-house firmware on Crownstone hardware. Functions: switching, dimming, energy monitoring, presence detection, indoor localization, switchcraft.
https://crownstone.rocks
91 stars 62 forks source link

Make compilation for host work again #126

Closed mrquincle closed 2 years ago

mrquincle commented 3 years ago

It is not so hard to restore the functionality to compile for host. For this we need to have the proper source/CMakeLists.txt file, for example, this set_cmakefile.sh

#!/bin/sh

platform=${1:? "Usage: $0 <host|nrf>"}

this_script=$(readlink -f "$0")
this_script_path=$(dirname "$this_script")
cpd=$(echo "$this_script_path/..")

rm -f $cpd/CMakeLists.txt

if [ "$platform" = "host" ]; then
    ln -s $cpd/conf/cmake/CMakeLists.host_target.txt $cpd/CMakeLists.txt
fi

if [ "$platform" = "nrf" ]; then
    ln -s $cpd/conf/cmake/CMakeLists.nrf_target.txt $cpd/CMakeLists.txt
fi 

Now, when compiling there are some small issues with respect to configuration, but it's easy to fix.

Dependencies

Then we'll run into issues like the following:

[ 50%] Building CXX object CMakeFiles/test_InterleavedBuffer.dir/test/host/test_InterleavedBuffer.cpp.obj
In file included from /home/anne/workspace/bluenet/source/include/structs/cs_BleCentralPackets.h:10,
                 from /home/anne/workspace/bluenet/source/include/common/cs_Types.h:18,
                 from /home/anne/workspace/bluenet/source/include/structs/buffer/cs_CircularBuffer.h:10,
                 from /home/anne/workspace/bluenet/source/test/host/test_InterleavedBuffer.cpp:5:
/home/anne/workspace/bluenet/source/include/ble/cs_UUID.h:43:17: error: expected ')' before 'uuid'
  UUID(ble_uuid_t uuid);
      ~          ^~~~~

The file test_InterleavedBuffer.cpp obviously uses cs_CircularBuffer.h and it goes all the way to cs_BleCentralPackets.h, but this is not a standalone file and requires the Nordic SDK for type definitions.

Constrain dependencies

It would be great to constrain the dependencies on Nordic file in one location. This has been before the file https://github.com/crownstone/bluenet/blob/master/source/include/ble/cs_Nordic.h.

What this would mean is that we can have one location where we can provide host-specific functions.

#ifdef HOST_TARGET
 // include to file which contains host functions or dummies/stubs
#else
  // all headers from Nordic  
#endif 

Consequences

If we build this out, we will be able to run more and more on the host side. This will accelerate development a lot. A tool like this will be indispensable.

What can be better

Ideally we always want to run the host compilation, or else we'll have "code rot" like now. So no fancy symbolic links as in the script in this bug report. It must be something more solid.

mrquincle commented 3 years ago

See https://github.com/crownstone/bluenet/commit/0eb43e6769a89dd5b47e045d66e9c2ec9f2150cc

mrquincle commented 2 years ago

The branch with host compilation has been merged. There's now also continuous integration of that part. The choice have been to bit by bit add the same Nordic files as present in the SDK, but then compiling on host. In the end we will be basically "emulating" the Nordic SDK on the host.