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

Allowing compiling without DBUS. #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

skilau
Copy link

@skilau skilau commented Feb 14, 2025

There is a minor bug in CMakeLists.txt that always brings in common/dbus.c, even though later in the CMakeLists.txt file it is properly bounded by the check of "if(LIBSYSTEMD_FOUND)" (See line ~373 in CMakeLists.txt for it)

Because the line always brings in common/dbus.c, building without dbus isn't possible.
Removing the 1 line from the CMakeLists.txt fixes this issue.

@MathisMARION
Copy link
Collaborator

Hello, and thank you for pointing this out. Can you add back common/dbus.c in the D-Bus conditional sources?

@skilau
Copy link
Author

skilau commented Feb 14, 2025

Sorry about that. I actually thought that the line down in ~373 would bring it in. I should have tested it first.
I updated the PR to do:
$<$BOOL:${LIBSYSTEMD_FOUND}:common/dbus.c>

Instead, which does fix the compilation for both non-DBUS and DBUS builds.

CMakeLists.txt Outdated
@@ -146,6 +146,7 @@ add_library(libwsbrd STATIC
common/bus_uart.c
common/capture.c
common/commandline.c
$<$<BOOL:${LIBSYSTEMD_FOUND}>:common/dbus.c>
Copy link
Collaborator

@jerome-pouiller jerome-pouiller Feb 14, 2025

Choose a reason for hiding this comment

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

I am not sure a generator-expression makes sense here.

BTW, the project tries hard to keep atomic commit in the history. Can you squash this commit?

Copy link
Author

Choose a reason for hiding this comment

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

Hi! I did the squash.
I am not too familiar with CMake, so I wasn't exactly sure how to do the conditional include of the source file in the CMakeLists.txt file.

Copy link
Collaborator

@jerome-pouiller jerome-pouiller Feb 14, 2025

Choose a reason for hiding this comment

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

diff --git i/CMakeLists.txt w/CMakeLists.txt
index 62f972f368..21a1f4e03b 100644
--- i/CMakeLists.txt
+++ w/CMakeLists.txt
@@ -270,7 +270,7 @@ if(LIBCAP_FOUND)
 endif()
 if(LIBSYSTEMD_FOUND)
     target_compile_definitions(libwsbrd PRIVATE HAVE_LIBSYSTEMD)
-    target_sources(libwsbrd PRIVATE app_wsbrd/app/dbus.c)
+    target_sources(libwsbrd PRIVATE common/dbus.c app_wsrd/app/dbus.c)
     if(AUTH_LEGACY)
         target_sources(libwsbrd PRIVATE app_wsbrd/app/dbus_auth_legacy.c)
     else()

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! Fixed!

@skilau skilau force-pushed the Allow-building-without-DBUS branch 2 times, most recently from 907dcd6 to fc85483 Compare February 16, 2025 20:35
@skilau
Copy link
Author

skilau commented Feb 16, 2025

NOTE: Added a second minor patch on this PR as well.

I had to tag "wsbrd_dbus_vtable" as unused, or otherwise we get this error:

`[22/135] Building C object CMakeFiles/libwsbrd.dir/app_wsbrd/app/wsbr_mac.c.o
In file included from app_wsbrd/app/wsbr_mac.c:48:

app_wsbrd/app/dbus.h:24:36: warning: ‘wsbrd_dbus_vtable’ defined but not used [-Wunused-variable]
24 | static const struct sd_bus_vtable *wsbrd_dbus_vtable;
| ^~~~~~~~~~~~~~~~~`

@@ -21,7 +21,7 @@ struct wsbr_ctxt;

extern const struct sd_bus_vtable wsbrd_dbus_vtable[];
#else
static const struct sd_bus_vtable *wsbrd_dbus_vtable;
static const struct sd_bus_vtable *wsbrd_dbus_vtable __attribute__ ((unused));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Weird, no warning should happen unless you compile with -Wunused-const-variable=2 (which is not the default). What compiler version are you using?

Copy link
Collaborator

Choose a reason for hiding this comment

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

GCC's -Wall does report this:

$ echo 'static int foo; int main() { }' | gcc -Wall -xc -
<stdin>:1:12: warning: ‘foo’ defined but not used [-Wunused-variable]

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would remove the need for __attribute__((unused)) but I am not convinced that it is any better:

diff --git a/app_wsbrd/app/dbus.h b/app_wsbrd/app/dbus.h
index 3b5c4d6a18..3918c5c107 100644
--- a/app_wsbrd/app/dbus.h
+++ b/app_wsbrd/app/dbus.h
@@ -21,7 +21,7 @@ struct wsbr_ctxt;
 
 extern const struct sd_bus_vtable wsbrd_dbus_vtable[];
 #else
-static const struct sd_bus_vtable *wsbrd_dbus_vtable;
+#define wsbrd_dbus_vtable NULL
 #endif
 
 #endif

Copy link
Collaborator

@jerome-pouiller jerome-pouiller Feb 17, 2025

Choose a reason for hiding this comment

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

The warning does not happen is the variable is declared in a header file:

$ cat foo.h
static const int foo;
$ cat foo.c
#include "foo.h"
int main() { }
$ gcc -Wall -c foo.c
$

Copy link
Collaborator

@MathisMARION MathisMARION Feb 17, 2025

Choose a reason for hiding this comment

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

That's only partially true. It seems to also be a matter of constness:

$ echo 'static int foo;' > foo.h
$ gcc -Wall foo.c
In file included from foo.c:1:
foo.h:1:12: warning: ‘foo’ defined but not used [-Wunused-variable]
    1 | static int foo;
      |            ^~~

$ echo 'static const int foo;' > foo.h
$ gcc -Wall foo.c

And it gets a bit tricker with pointers:

$ echo 'static int *foo;' > foo.h
$ gcc -Wall foo.c
In file included from foo.c:1:
foo.h:1:13: warning: ‘foo’ defined but not used [-Wunused-variable]
    1 | static int *foo;
      |             ^~~

$ echo 'static const int *foo;' > foo.h
$ gcc -Wall foo.c
In file included from foo.c:1:
foo.h:1:19: warning: ‘foo’ defined but not used [-Wunused-variable]
    1 | static const int *foo;
      |                   ^~~

$ echo 'static int *const foo;' > foo.h
$ gcc -Wall foo.c

$ echo 'static const int *const foo;' > foo.h
$ gcc -Wall foo.c

So in our case the solution would be:

diff --git a/app_wsbrd/app/dbus.h b/app_wsbrd/app/dbus.h
index 3b5c4d6a18..16bf44dcf2 100644
--- a/app_wsbrd/app/dbus.h
+++ b/app_wsbrd/app/dbus.h
@@ -21,7 +21,7 @@ struct wsbr_ctxt;
 
 extern const struct sd_bus_vtable wsbrd_dbus_vtable[];
 #else
-static const struct sd_bus_vtable *wsbrd_dbus_vtable;
+static const struct sd_bus_vtable *const wsbrd_dbus_vtable;
 #endif
 
 #endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

struct sd_bus_vtable is anomymous when we do not have systemd/sd-bus.h, so this would not compile. That is why we use a pointer instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Arf, indeed.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure if you still need my compiler version, but it is:
arm-linux-musleabi-gcc (GCC) 13.2.0

Yeah, I wasn't too happy using the "attribute ((unused)", but I couldn't find any particular better way to do it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As @MathisMARION said, static const struct sd_bus_vtable *const wsbrd_dbus_vtable; will do the job.

Copy link
Author

Choose a reason for hiding this comment

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

Awesome, thank you!
I changed it and squashed/pushed it.

There is a minor bug in CMakeLists.txt that always brings
in common/dbus.c, even when DBUS is not enabled.
@skilau skilau force-pushed the Allow-building-without-DBUS branch from fc85483 to 8e97107 Compare February 17, 2025 16:04
@MathisMARION
Copy link
Collaborator

Applied onto our private development branch, thank you very much for your contribution! This should be released in version 2.3.1.

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

Successfully merging this pull request may close these issues.

3 participants