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

Usage in Linux kernel modules #80

Closed
mloy opened this issue Sep 7, 2020 · 8 comments
Closed

Usage in Linux kernel modules #80

mloy opened this issue Sep 7, 2020 · 8 comments

Comments

@mloy
Copy link

mloy commented Sep 7, 2020

Hi,
we are using this nice library within Linux kernel modules. Since we only need the writer, a colleague took only the necessary code and changed/removed stuff to make it compile.

This works but is of course not that nice. I haven't found any clean way of configuring the project accordingly.

Did I miss something?

best regards,
Matthias

@edsiper
Copy link

edsiper commented Sep 7, 2020

@mloy just curious, what's the use case for that specific module?

@mloy
Copy link
Author

mloy commented Sep 7, 2020

We are doing signal processing in kernel space and use msgpack to transfer structured information.

@mloy
Copy link
Author

mloy commented Sep 7, 2020

In a former solution we had to use json which is a pain to compose in kernel space if floating point numbers are to be expressed.

In json you have to convert everything to a string. In msgpack you simply copy the value (after changing into the correct endianness...)

@bernardoaraujor
Copy link

@mloy interesting!

I wrote a CMake file to fetch and build mpack as a static library.
I'm using all the sources, but as soon as I set in stone what I'm using and (most importantly) what I'm not using, I'll clean it up (${sources} and ${headers}) so libmpack.a is as small as possible.

here's the contents of mpack.cmake:

include(ExternalProject)

include(FetchContent)
FetchContent_Declare(
  mpack
  GIT_REPOSITORY http://github.com/ludocode/mpack.git
  GIT_TAG e150cb7455cefdab0df6359414e9e4c792723d73 #v1.0
)

message(STATUS "Fetching mpack")
FetchContent_MakeAvailable(mpack)

set(MPACK_SRC ${CMAKE_CURRENT_BINARY_DIR}/_deps/mpack-src/src/mpack)

set(sources
  ${MPACK_SRC}/mpack-common.c
  ${MPACK_SRC}/mpack-expect.c
  ${MPACK_SRC}/mpack-node.c
  ${MPACK_SRC}/mpack-platform.c
  ${MPACK_SRC}/mpack-reader.c
  ${MPACK_SRC}/mpack-writer.c
)

set(headers
  ${MPACK_SRC}/mpack-common.h
  ${MPACK_SRC}/mpack-defaults.h
  ${MPACK_SRC}/mpack-expect.h
  ${MPACK_SRC}/mpack.h
  ${MPACK_SRC}/mpack-node.h
  ${MPACK_SRC}/mpack-platform.h
  ${MPACK_SRC}/mpack-reader.h
  ${MPACK_SRC}/mpack-writer.h
)

add_library(mpack STATIC ${sources})

install(TARGETS mpack DESTINATION lib)
install(FILES ${headers} DESTINATION include)

@bernardoaraujor
Copy link

Although I will likely not have time to do so, I can imagine an interesting case where the mpack.cmake above morphs into a CMakeLists.txt (with a potential for a PR into upstream, in case the authors are open to having CMake integrated into the repo).

Instead of building a single libmpack.a, it would ideally provide:

  • libmpack-common.a
  • libmpack-expect.a
  • libmpack-node.a
  • libmpack-platform.a
  • libmpack-reader.a
  • libmpack-writer.a

with the appropriate dependencies between eachother.

Too much extra complexity for too little profit? maybe...

However, from my perspective it's an interesting angle becase I'm a system integrator before I'm a developer, and automating builds (especially in the context of OpenEmbedded and Yocto Project) are always handy.

@mloy
Copy link
Author

mloy commented Sep 11, 2020

The problem is in the headers included by mpack-platform.h. You can have a config for disable or enable features but I need a switch for kernel/user space headers.

@ludocode
Copy link
Owner

Which headers does MPack use that are not available in Linux kernel space? I'd love to add a configuration option or some sort of auto-detection to remove the dependency on headers that aren't available in the kernel (would __STDC_HOSTED__ work for this?)

ludocode added a commit that referenced this issue Jul 30, 2021
This hopefully completes AVR support for #80 and #79.
ludocode added a commit that referenced this issue Jul 30, 2021
This hopefully completes AVR support for #80 and #79.
@ludocode
Copy link
Owner

ludocode commented Aug 3, 2021

Building in the Linux kernel is now supported. There is a new MPACK_CONFORMING configuration that can be turned off to make MPack avoid the standard headers, and the Linux-specific headers can be included in an mpack-config.h instead. These includes are kept out of the main MPack tree so that MPack stays pure of the GPL.

The sample mpack-config.h as well as a shim to build the MPack unit test suite as a Linux kernel module are in a separate project here: https://github.com/ludocode/mpack-linux-kernel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants