I think you need to fix this on samples/bpf side
I tried to play with the samples/bpf/ includes, but couldn't find a way to make this work.. selftests base includes on tools/include, while samples have $(objtree)/usr/include as first include and AFAICS the __must_check is defined under __KERNEL__ ifdef
I guess the reason samples use $(objtree)/usr/include is to get some struct definitions which are not in tools/include, but looks like some samples objects already use vmlinux.h include, so that could be the way forward to fix that
I tried the method you suggested, and some unexpected problems occurred. Maybe, we can apply v5 [0] first, and then solve this problem?
Best wishes, Rong Tao
[0] v5: https://lore.kernel.org/lkml/tencent_0E9E1A1C0981678D5E7EA9E4BDBA8EE2200A@qq...