Skip to content

Conversation

@maribu
Copy link
Member

@maribu maribu commented Apr 8, 2025

Contribution description

This fixes two related compilation issues when using the can module under native:

  1. can/can.h from the can module includes libsocketcan.h from the libsocketcan package on native%, but does not depend on it. The missing dep is added
  2. The libsocketcan package does not compile with the posix_headers package is used, as it really needs to include the host headers. The INCLUDES variable is stripped of the posix headers include path locally within the package's Makefile (so with no side-effect on other packages and modules).

Testing procedure

$ USEMODULE=posix_headers BOARD=native64 RIOT_CI_BUILD=1 make -C tests/drivers/candev

Will fail spectacularly on master, but work fine with this PR.

Issues/PRs references

None

@github-actions github-actions bot added Area: pkg Area: External package ports Area: sys Area: System labels Apr 8, 2025
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 8, 2025
@riot-ci
Copy link

riot-ci commented Apr 8, 2025

Murdock results

✔️ PASSED

9a63343 cpu/native: configure FD-CAN loop delay

Success Failures Total Runtime
10295 0 10295 10m:47s

Artifacts

@crasbe
Copy link
Contributor

crasbe commented Apr 8, 2025

Unrelated, but while you're working on CAN stuff, these lines can probably go? That doesn't do anything.

RIOT/sys/Makefile.dep

Lines 357 to 360 in 87352ee

ifneq (,$(filter can_%,$(USEMODULE)))
endif

@crasbe
Copy link
Contributor

crasbe commented Apr 8, 2025

Super small nitpick: The commit message sys/can: depen on libsocketcan for (native%) has a typo, it should be depend.

By the way: I like that you're writing an elaborate commit message for every commit 👍

@crasbe crasbe added this to the Release 2025.04 milestone Apr 8, 2025
@crasbe
Copy link
Contributor

crasbe commented Apr 8, 2025

I'm not sure if I'm following correctly, but tests/drivers/can without posix_headers builds fine:

cbuec@W11nMate:~/RIOTstuff/riot-canfix/RIOT$ RIOT_CI_BUILD=1 BOARD=native64 make -C tests/drivers/candev/
make: Entering directory '/home/cbuec/RIOTstuff/riot-canfix/RIOT/tests/drivers/candev'
Building application "tests_candev" for "native64" with CPU "native".

   text    data     bss     dec     hex filename
  47820    1552   59680  109052   1a9fc /home/cbuec/RIOTstuff/riot-canfix/RIOT/tests/drivers/candev/bin/native64/tests_candev.elf
make: Leaving directory '/home/cbuec/RIOTstuff/riot-canfix/RIOT/tests/drivers/candev'

And if I apply the "hack" from the tests/drivers/candev to let it build on native on the command line, I can see that the libsocketcan is build:

cbuec@W11nMate:~/RIOTstuff/riot-canfix/RIOT$ CFLAGS+=-DCONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY BOARD=native64 make -C tests/drivers/candev
make: Entering directory '/home/cbuec/RIOTstuff/riot-canfix/RIOT/tests/drivers/candev'
Building application "tests_candev" for "native64" with CPU "native".

"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/pkg/libsocketcan/
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/build/pkg/libsocketcan/src -f /home/cbuec/RIOTstuff/riot-canfix/RIOT/pkg/libsocketcan/Makefile.libsocketcan
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/boards
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/boards/common/init
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/boards/native64
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/boards/common/native
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/boards/common/native/drivers
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/core
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/core/lib
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/cpu/native
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/cpu/native/periph
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/cpu/native/stdio_native
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/drivers
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/drivers/periph_common
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/auto_init
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/can
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/isrpipe
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/libc
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/memarray
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/preprocessor
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/shell
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/stdio
"make" -C /home/cbuec/RIOTstuff/riot-canfix/RIOT/sys/tsrb
   text    data     bss     dec     hex filename
  47836    1552   59680  109068   1aa0c /home/cbuec/RIOTstuff/riot-canfix/RIOT/tests/drivers/candev/bin/native64/tests_candev.elf
make: Leaving directory '/home/cbuec/RIOTstuff/riot-canfix/RIOT/tests/drivers/candev'

The package is included when periph_can is used:

ifneq (,$(filter periph_can,$(FEATURES_USED)))
USEPKG += libsocketcan
endif

@maribu
Copy link
Member Author

maribu commented Apr 8, 2025

I'm not sure if I'm following correctly, but tests/drivers/can without posix_headers builds fine.

Yes it does, libsocketcan and posix_headers are completely unrelated. But if you were to use an app that for some reason depends on posix_headers and for another reason depends on can, that app will not build on native64.

The package is included when periph_can is used

That is correct. But an application may be interested in the can header only without periph_can. E.g. for unit testing something working on top of CAN, you do not really need an actual CAN interface, but you do every much need the can_frame_t type provided by can/can.h from the can module.

That you cannot use the can package without periph_can (or explicitly pulling in libsocketcan) can be shown with:

diff --git a/examples/basic/hello-world/Makefile b/examples/basic/hello-world/Makefile
index ad1fa6fdcb..790ab0ee52 100644
--- a/examples/basic/hello-world/Makefile
+++ b/examples/basic/hello-world/Makefile
@@ -15,4 +15,6 @@ DEVELHELP ?= 1
 # Change this to 0 show compiler invocation lines by default:
 QUIET ?= 1
 
+USEMODULE += can
+
 include $(RIOTBASE)/Makefile.include
diff --git a/examples/basic/hello-world/main.c b/examples/basic/hello-world/main.c
index 213128ac64..db17103b17 100644
--- a/examples/basic/hello-world/main.c
+++ b/examples/basic/hello-world/main.c
@@ -21,6 +21,8 @@
 
 #include <stdio.h>
 
+#include "can/can.h"
+
 int main(void)
 {
     puts("Hello World!");

And then make BOARD=native64 -C examples/basic/hello-world. This will fail in master due to a missing include. With this PR, it will fail later due to CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY being undefined.

@github-actions github-actions bot added Platform: native Platform: This PR/issue effects the native platform Area: cpu Area: CPU/MCU ports labels Apr 8, 2025
@maribu
Copy link
Member Author

maribu commented Apr 8, 2025

With this PR, it will fail later due to CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY being undefined.

As @Enoch247 could confirm that the nitty-gritty details will be handled by the underlying FD-CAN implementation on Linux, I added a commit to just define this to 0 on native.

So all in all, CAN on native should now just compile out of the box.

@maribu maribu added the CI: no fast fail don't abort PR build after first error label Apr 8, 2025
@crasbe
Copy link
Contributor

crasbe commented Apr 8, 2025

The changes seem reasonable to me, but I'm really neither familiar with the CAN subsystem nor with native, so a Soft-ACK from my side. Perhaps someone else can take a look at it too.

Copy link
Contributor

@Enoch247 Enoch247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Only one minor nit.

maribu and others added 4 commits April 9, 2025 13:10
This simply strips the include path to the posix compat headers from
the includes, but at the level of the local `Makefile` (so without
side effects on other modules/packages). Since libsocketcan is only
ever used on native, this should be fine.
Since `can.h` is including `libsocketcan.h` on `native%`, we need to
depend on that package.

Co-authored-by: crasbe <crasbe@gmail.com>
Drop dead statement
The native CAN implementation relies on the underlying OS to implement
CAN, so we can leave handling the nitty-gritty details such as the loop
delay to the underlying implementation.
@maribu maribu enabled auto-merge April 9, 2025 11:10
@maribu maribu added this pull request to the merge queue Apr 9, 2025
Merged via the queue into RIOT-OS:master with commit 33988b1 Apr 9, 2025
26 checks passed
@maribu maribu deleted the cpu/native/can branch April 9, 2025 14:53
@maribu
Copy link
Member Author

maribu commented Apr 9, 2025

Thx :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports Area: pkg Area: External package ports Area: sys Area: System CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants