alex-courtis / way-displays

way-displays: Auto Manage Your Wayland Displays
MIT License
246 stars 12 forks source link

Fails to build on 32-bit architectures (armv7, x86) #17

Closed jirutka closed 2 years ago

jirutka commented 2 years ago
src/log.c: In function 'log_print':
src/log.c:21:59: error: format '%ld' expects argument of type 'long int', but argument 7 has type 'suseconds_t' {aka 'long long int'} [-Werror=format=]
   21 |                 fprintf(__stream, "%s [%02d:%02d:%02d.%03ld]\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec / 1000);
      |                                                       ~~~~^                                                   ~~~~~~~~~~~~~~~~~
      |                                                           |                                                              |
      |                                                           long int                                                       suseconds_t {aka long long int}
      |                                                       %03lld
src/log.c:25:51: error: format '%ld' expects argument of type 'long int', but argument 7 has type 'suseconds_t' {aka 'long long int'} [-Werror=format=]
   25 |         fprintf(__stream, "%s [%02d:%02d:%02d.%03ld] %s", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec / 1000, suffix);
      |                                               ~~~~^                                                    ~~~~~~~~~~~~~~~~~
      |                                                   |                                                               |
      |                                                   long int                                                        suseconds_t {aka long long int}
      |                                               %03lld
cc1: all warnings being treated as errors

alex-courtis commented 2 years ago

I've had a quick go using CC=musl-gcc CXX=musl-gcc CFLAGS="-m32" make however ran into some issues including /usr/include/wayland*

My cross-compiler-fu is very limited. Perhaps you could point me to, say, a docker image that replicates your setup.

Even better, a PR would be gratefully accepted. I can validate x86_64-pc-linux-gnu, you can validate your 32 bit case.

Whatever we do, I will change config.mk to use CC ?= gcc etc. now that I know people are cross compiling.

jbeich commented 2 years ago

CC ?= gcc is pointless because GNU make always defines CC e.g.,

$ env -i gmake -p | grep '^CC'
CC = cc
alex-courtis commented 2 years ago

CC ?= gcc is pointless because GNU make always defines CC e.g.,

I see that you have defined CC here: https://github.com/freebsd/freebsd-ports/blob/a7011e478978bdf10607e39066e2f7a6fa444cd4/x11/way-displays/Makefile#L25-L27

Does that work via the -e flag? make -e CC=ABC -p | grep ^CC

alex-courtis commented 2 years ago

/nudge @jirutka

It would be great if we could resolve this using a virtual environment.

jbeich commented 2 years ago

Does that work via the -e flag? make -e CC=ABC -p | grep ^CC

-e doesn't require extra arguments, so CC=ABC make -e is similar to make CC=ABC.

jbeich commented 2 years ago

src/log.c:21:59: error: format '%ld' expects argument of type 'long int', but argument 7 has type 'suseconds_t' {aka 'long long int'} [-Werror=format=]

Likely caused by musl@38143339646a. I can't reproduce on FreeBSD i386 where suseconds_t is still long on all architectures.

alex-courtis commented 2 years ago

Thanks @jbeich

Something simple like long msec = tv.tv_usec / 1000; before the printf would be fine as we know that it fits into a long.

Could you please try that out @jirutka ?

alex-courtis commented 2 years ago

1.4.1 should resolve this; all the formatting is delegated to strftime which handles unpacking the struct tm.

Removed the milliseconds, which weren't providing much value.

alex-courtis commented 2 years ago

Flagged for update to 1.5.0.

Please reopen or open a new issue if problems persist.

jirutka commented 2 years ago

Thanks for the fix and sorry about the late response. I can confirm that the problem is indeed gone.

alex-courtis commented 2 years ago

Thanks @jirutka

Please keep raising such issues - I cannot build on every possible environment ;)

jirutka commented 2 years ago

Please keep raising such issues

I didn’t find any other compatibility issue, way-displays now builds fine on all architectures.

I cannot build on every possible environment ;)

Actually, you can, using CI, e.g. GitHub Actions. You can take some inspiration from https://github.com/jirutka/tty-copy/blob/master/.github/workflows/ci.yml.

alex-courtis commented 2 years ago

That's really useful, many thanks.

runs-on: macos-latest is incredible!