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

RNG.cpp include of <Arduino.h> makes native builds for unit testing and debugging fail #84

Open
attermann opened this issue Nov 21, 2023 · 3 comments

Comments

@attermann
Copy link

RNG.cpp include <Arduoino.h> and makes use of Arduino millis() and micros() functions.

It's evident from code in the repo that this issue was circumvented for this project by emulating Arduino (.../host/emulation/Arduino.h), but it's not clear how this emulation can be included by external projects.

I'm using PlatformIO specifically. Any advice for how to include the emulation for a native host build?

Thanks!

@jp-bennett
Copy link

You may be interested in platform-native. https://docs.platformio.org/en/latest/platforms/native.html It's been a long time since a stable release, but the code itself is still under development at https://github.com/meshtastic/platform-native

@Adrian-Samoticha
Copy link

You may be interested in platform-native. https://docs.platformio.org/en/latest/platforms/native.html It's been a long time since a stable release, but the code itself is still under development at https://github.com/meshtastic/platform-native

Unless I’m misunderstanding something, PlatformIO’s platform-native functionality is exactly what @attermann is using for unit testing purposes, and the inclusion of Arduino.h makes it impossible to compile this library on native environments.

I‘ve run into the same issue and am currently looking for a solution.

@Adrian-Samoticha
Copy link

Adrian-Samoticha commented Aug 30, 2024

I couldn’t really find a good solution to this other than replacing the #include<Arduino.h> line in the RNG.cpp file with:

#ifndef NATIVE
#include <Arduino.h>
#else
uint32_t millis() { return 0; }

uint32_t micros() { return 0; }
#endif

EDIT: Make sure to add the -D NATIVE build flag to your native environment in your platformio.ini file:

build_flags =
	-D NATIVE

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