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

Add cross-compiled library to RIOT OS #16799

Closed
forellendev opened this issue Sep 2, 2021 · 11 comments
Closed

Add cross-compiled library to RIOT OS #16799

forellendev opened this issue Sep 2, 2021 · 11 comments

Comments

@forellendev
Copy link

Hi guys,

I tried adding a larger library to RIOT OS, but found that it isn't optimized enough. I compiled the library for the appropriate device architecture that I'm using RIOT on, but I have no idea how to add the compiled library to the project? Should I use PKG or MODULE in this case?

Best regards

@miri64
Copy link
Member

miri64 commented Sep 2, 2021

Hi @forellendev, have a look at https://github.com/RIOT-OS/RIOT/blob/master/examples/bindist/README.md. I think that fits your use case.

@forellendev
Copy link
Author

Thank you @miri64, I'll try it out!

@forellendev
Copy link
Author

Unfortunately, I get the following error:

The selected TOOLCHAIN=/usr/share/gcc-arm-none-eabi-10.3-2021.07/bin is not supported.
Supported toolchains: gnu llvm afl

I cross-compiled a library on my ubuntu-x86_64 system to the ARM Cortex-M4 with the arm-none-eabi toolchain and would like to use this cross-compiled library within RIOT OS. Is this actually possible with the arm-non-eabi toolchain?

@miri64
Copy link
Member

miri64 commented Sep 6, 2021

You don't need to set the toolchain. It just need to be in your PATH (which for a selected BOARD is usually the case). Just use a Cortex-M4-based board for testing.

@forellendev
Copy link
Author

Thank you @miri64, I forgot to outcomment a path variable. I thought a little about manual cross-compiling the library, but now want to try to add it as a package (and hopefully as a new pkg to RIOT OS). I have the following Makefile in a new pkg folder:

PKG_NAME = libsafecrypto
PKG_URL = https://github.com/safecrypto/libsafecrypto.git
PKG_VERSION = 65b962f6d608704336ac16f226c8a5ff63b75851 # 0.2.0-52
PKG_LICENSE = MIT

include $(RIOTBASE)/pkg/pkg.mk

.PHONY: libsafecrypto%

LIBSAFECRYPTO_MODULES = \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/include \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/bindings \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/build_tools \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/src \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/src/utils/crypto \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/src/utils/threading \
INCLUDES += -I$(PKGDIRBASE)/libsafecrypto/src/schemes \

all:
	$(MAKE) -C $(PKG_SOURCE_DIR) -f $(RIOTBASE)/Makefile.base

The problem is that nothing is downloaded at all and my bin/native/libsafecrypto folders are empty.

@miri64
Copy link
Member

miri64 commented Sep 14, 2021

Did you include USEPKG += libsafecrypto into your test application's Makefile?

@forellendev
Copy link
Author

I did add this command to the Make of the application. Do you think it would be possible to fetch the project via PKG_URL and PKG_VERSION, but then apply a custom cross-compilation script to this download next? Maybe this library leads to some troubles.

@miri64
Copy link
Member

miri64 commented Sep 14, 2021

but then apply a custom cross-compilation script to this download next? Maybe this library leads to some troubles.

Yes, using custom compile scripts is what we often do e.g. with pkgs that use cmake or other non-make tools for building. Have a look e.g. at ccn-lite, how the building step is handled there:

all: $(BINDIR)/ccn-lite.a
$(BINDIR)/ccn-lite.a: $(PKG_BUILD_DIR)/lib/libccnl-riot.a
cp $< $@
$(PKG_BUILD_DIR)/lib/libccnl-riot.a: $(PKG_BUILD_DIR)/Makefile
$(MAKE) -C $(PKG_BUILD_DIR)
$(PKG_BUILD_DIR)/Makefile: $(PKG_PREPARED) $(TOOLCHAIN_FILE) | ..cmake_version_supported
cmake -B$(PKG_BUILD_DIR) -H$(PKG_SOURCE_DIR)/src \
-DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
-DCCNL_RIOT=1 -DRIOT_CFLAGS="$(RIOT_CFLAGS)" -DBUILD_TESTING=OFF
$(TOOLCHAIN_FILE): FORCE
$(RIOTTOOLS)/cmake/generate-xcompile-toolchain.sh > $(TOOLCHAIN_FILE)

Basically, the make targets are the files you want to have generated, the command section of those targets provide said script (you can also call external scripts there) provide the instructions how this file will be generated.

@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Apr 17, 2022
@miri64
Copy link
Member

miri64 commented Apr 17, 2022

@forellendev did my last comment solve your problem?

@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Apr 17, 2022
@maribu
Copy link
Member

maribu commented Sep 20, 2022

Let's assume the problem has been solved. If not, please reopen the issue - we are happy to help.

@maribu maribu closed this as completed Sep 20, 2022
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

3 participants