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

Support for MSYS2/MinGW64 #16

Open
fleimgruber opened this issue Sep 27, 2024 · 7 comments
Open

Support for MSYS2/MinGW64 #16

fleimgruber opened this issue Sep 27, 2024 · 7 comments

Comments

@fleimgruber
Copy link

While working on #14 (comment) I tried to build on Windows using the MSYS2/MinGW64 GCC toolchain.

I am getting compilation errors of the form:

C:\Users\LeimgruberF\opt\msys64\mingw64\include/stdio.h:353:16: error: '__format__' attribute argument not supported: gnu_scanf
__attribute__((__format__ (gnu_scanf, 2, 0))) __MINGW_ATTRIB_NONNULL(2)
               ^
C:\Users\LeimgruberF\dev\sigbak\sbk-thread.c:21:10: note: in file included from C:\Users\LeimgruberF\dev\sigbak\sbk-thread.c:21:
#include "sbk-internal.h"
         ^
C:\Users\LeimgruberF\dev\sigbak/sbk-internal.h:20:10: note: in file included from C:\Users\LeimgruberF\dev\sigbak/sbk-internal.h:20:
#include <openssl/evp.h>
         ^
C:\Users\LeimgruberF\opt\msys64\mingw64\include/openssl/evp.h:22:12: note: in file included from C:\Users\LeimgruberF\opt\msys64\mingw64\include/openssl/evp.h:22:
#  include <stdio.h>

and also similarly with gnu_printf. This issue might contain an idea for a fix, but I am not familiar with the details.

Did you already think about supporting MSYS2/MinGW64 similar to Cygwin, e.g. in

#ifdef __CYGWIN__
as the two are related?

If you could give me a pointer or an idea of what the issue is, I could have a look and test myself.

@tbvdm
Copy link
Owner

tbvdm commented Sep 29, 2024

I don't think this is a problem in sigbak. Are you able to compile other code using the same compiler and compiler flags? For example, try this program:

#include <openssl/evp.h>
#include <stdio.h>
int main(){}

@fleimgruber
Copy link
Author

Using the same compiler and flags I can compile the example program without error. Did you mean to also include your compat layer?

@tbvdm
Copy link
Owner

tbvdm commented Sep 30, 2024

I have no idea, sorry. Perhaps you could ask the MSYS2 people? Or just build sigbak in Cygwin or WSL.

@fleimgruber
Copy link
Author

fleimgruber commented Oct 2, 2024

Thanks for consideration.

Or just build sigbak in Cygwin or WSL.

As mentioned in #14 (comment) my goal is to add a way of building with the Zig Build System. Zig does not support Cygwin (and there are no plans for that). The supported ABIs on Windows are MinGW and MSVC of which MinGW is the better choice for compatibility with this C codebase.

My current state of MinGW64 compat is here: fleimgruber@8d79ad8 where I temporarily added a MinGW64 Makefile for testing purposes and guessed compat changes in config.h and compat.h.

I have the feeling that I made some progress, but not all the way yet. make -f mingw64.Makefile output:

protoc --c_out=. backup.proto
protoc --c_out=. database.proto
cc  -I/mingw64/include -Icompat  -c -o cmd-check-backup.o cmd-check-backup.c
cc  -I/mingw64/include -Icompat  -c -o cmd-dump-backup.o cmd-dump-backup.c
cc  -I/mingw64/include -Icompat  -c -o cmd-export-attachments.o cmd-export-attachments.c
cmd-export-attachments.c: In function 'create_unique_file':
cmd-export-attachments.c:69:22: warning: implicit declaration of function 'openat'; did you mean 'open'? [-Wimplicit-function-declaration]
   69 |                 fd = openat(dfd, name, O_WRONLY | O_CREAT | O_EXCL, 0666);
      |                      ^~~~~~
      |                      open
cmd-export-attachments.c: In function 'get_thread_directory':
cmd-export-attachments.c:194:13: warning: implicit declaration of function 'mkdirat'; did you mean 'mkdir'? [-Wimplicit-function-declaration]
  194 |         if (mkdirat(dfd, name, 0777) == -1 && errno != EEXIST) {
      |             ^~~~~~~
      |             mkdir
cmd-export-attachments.c: In function 'set_mtime':
cmd-export-attachments.c:224:13: warning: implicit declaration of function 'futimens' [-Wimplicit-function-declaration]
  224 |         if (futimens(fileno(fp), ts) == -1) {
      |             ^~~~~~~~
In file included from sbk.h:26,
                 from sigbak.h:20,
                 from cmd-export-attachments.c:33:
cmd-export-attachments.c: In function 'cmd_export_attachments':
compat.h:144:23: warning: implicit declaration of function '_mkdir'; did you mean 'mkdir'? [-Wimplicit-function-declaration]
  144 | #  define mkdir(a, b) _mkdir(a)
      |                       ^~~~~~
cmd-export-attachments.c:379:21: note: in expansion of macro 'mkdir'
  379 |                 if (mkdir(outdir, 0777) == -1 && errno != EEXIST) {
      |                     ^~~~~
cc  -I/mingw64/include -Icompat  -c -o cmd-export-avatars.o cmd-export-avatars.c
In file included from sbk.h:26,
                 from sigbak.h:20,
                 from cmd-export-avatars.c:28:
cmd-export-avatars.c: In function 'write_files':
compat.h:144:23: warning: implicit declaration of function '_mkdir'; did you mean 'mkdir'? [-Wimplicit-function-declaration]
  144 | #  define mkdir(a, b) _mkdir(a)
      |                       ^~~~~~
cmd-export-avatars.c:199:21: note: in expansion of macro 'mkdir'
  199 |                 if (mkdir(outdir, 0777) == -1 && errno != EEXIST)
      |                     ^~~~~
cc  -I/mingw64/include -Icompat  -c -o cmd-export-database.o cmd-export-database.c
cc  -I/mingw64/include -Icompat  -c -o cmd-export-messages.o cmd-export-messages.c
cmd-export-messages.c: In function 'get_thread_file':
cmd-export-messages.c:59:14: warning: implicit declaration of function 'openat'; did you mean 'open'? [-Wimplicit-function-declaration]
   59 |         fd = openat(dfd, name, O_WRONLY | O_CREAT | O_EXCL, 0666);
      |              ^~~~~~
      |              open
In file included from sbk.h:26,
                 from sigbak.h:20,
                 from cmd-export-messages.c:32:
cmd-export-messages.c: In function 'cmd_export_messages':
compat.h:144:23: warning: implicit declaration of function '_mkdir'; did you mean 'mkdir'? [-Wimplicit-function-declaration]
  144 | #  define mkdir(a, b) _mkdir(a)
      |                       ^~~~~~
cmd-export-messages.c:572:21: note: in expansion of macro 'mkdir'
  572 |                 if (mkdir(outdir, 0777) == -1 && errno != EEXIST) {
      |                     ^~~~~
cc  -I/mingw64/include -Icompat  -c -o mime.o mime.c
cc  -I/mingw64/include -Icompat  -c -o sbk-attachment-tree.o sbk-attachment-tree.c
cc  -I/mingw64/include -Icompat  -c -o sbk-attachment.o sbk-attachment.c
cc  -I/mingw64/include -Icompat  -c -o sbk-database.o sbk-database.c
cc  -I/mingw64/include -Icompat  -c -o sbk-edit.o sbk-edit.c
cc  -I/mingw64/include -Icompat  -c -o sbk-file.o sbk-file.c
cc  -I/mingw64/include -Icompat  -c -o sbk-frame.o sbk-frame.c
sbk-frame.c: In function 'sbk_get_first_frame':
sbk-frame.c:126:15: warning: implicit declaration of function 'be32toh' [-Wimplicit-function-declaration]
  126 |         len = be32toh(len);
      |               ^~~~~~~
cc  -I/mingw64/include -Icompat  -c -o sbk-mention.o sbk-mention.c
cc  -I/mingw64/include -Icompat  -c -o sbk-message.o sbk-message.c
cc  -I/mingw64/include -Icompat  -c -o sbk-open.o sbk-open.c
cc  -I/mingw64/include -Icompat  -c -o sbk-quote.o sbk-quote.c
cc  -I/mingw64/include -Icompat  -c -o sbk-reaction.o sbk-reaction.c
cc  -I/mingw64/include -Icompat  -c -o sbk-read.o sbk-read.c
cc  -I/mingw64/include -Icompat  -c -o sbk-recipient-tree.o sbk-recipient-tree.c
cc  -I/mingw64/include -Icompat  -c -o sbk-recipient.o sbk-recipient.c
cc  -I/mingw64/include -Icompat  -c -o sbk-sqlite.o sbk-sqlite.c
cc  -I/mingw64/include -Icompat  -c -o sbk-thread.o sbk-thread.c
cc  -I/mingw64/include -Icompat  -c -o sigbak.o sigbak.c
cc  -I/mingw64/include -Icompat  -c -o backup.pb-c.o backup.pb-c.c
cc  -I/mingw64/include -Icompat  -c -o database.pb-c.o database.pb-c.c
cc  -I/mingw64/include -Icompat  -c -o compat/asprintf.o compat/asprintf.c
cc  -I/mingw64/include -Icompat  -c -o compat/bs_cbb.o compat/bs_cbb.c
cc  -I/mingw64/include -Icompat  -c -o compat/err.o compat/err.c
cc  -I/mingw64/include -Icompat  -c -o compat/explicit_bzero.o compat/explicit_bzero.c
cc  -I/mingw64/include -Icompat  -c -o compat/fopen.o compat/fopen.c
cc  -I/mingw64/include -Icompat  -c -o compat/getprogname.o compat/getprogname.c
cc  -I/mingw64/include -Icompat  -c -o compat/hkdf.o compat/hkdf.c
cc  -I/mingw64/include -Icompat  -c -o compat/hmac_ctx_new.o compat/hmac_ctx_new.c
cc  -I/mingw64/include -Icompat  -c -o compat/pledge.o compat/pledge.c
cc  -I/mingw64/include -Icompat  -c -o compat/readpassphrase.o compat/readpassphrase.c
cc  -I/mingw64/include -Icompat  -c -o compat/reallocarray.o compat/reallocarray.c
cc  -I/mingw64/include -Icompat  -c -o compat/unveil.o compat/unveil.c
cc -o sigbak cmd-check-backup.o cmd-dump-backup.o cmd-export-attachments.o cmd-export-avatars.o cmd-export-database.o cmd-export-messages.o mime.o sbk-attachment-tree.o sbk-attachment.o sbk-database.o sbk-edit.o sbk-file.o sbk-frame.o sbk-mention.o sbk-message.o sbk-open.o sbk-quote.o sbk-reaction.o sbk-read.o sbk-recipient-tree.o sbk-recipient.o sbk-sqlite.o sbk-thread.o sigbak.o backup.pb-c.o database.pb-c.o compat/asprintf.o compat/bs_cbb.o compat/err.o compat/explicit_bzero.o compat/fopen.o compat/getprogname.o compat/hkdf.o compat/hmac_ctx_new.o compat/pledge.o compat/readpassphrase.o compat/reallocarray.o compat/unveil.o -lcrypto -lprotobuf-c -lsqlite3
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cmd-export-attachments.o:cmd-export-attachments.c:(.text+0xf3): undefined reference to `openat'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cmd-export-attachments.o:cmd-export-attachments.c:(.text+0x590): undefined reference to `mkdirat'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cmd-export-attachments.o:cmd-export-attachments.c:(.text+0x5e2): undefined reference to `openat'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cmd-export-attachments.o:cmd-export-attachments.c:(.text+0x6d9): undefined reference to `futimens'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cmd-export-messages.o:cmd-export-messages.c:(.text+0x100): undefined reference to `openat'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sbk-frame.o:sbk-frame.c:(.text+0x351): undefined reference to `be32toh'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sbk-frame.o:sbk-frame.c:(.text+0x4f2): undefined reference to `be32toh'
C:/Users/LeimgruberF/opt/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sigbak.o:sigbak.c:(.text+0x12a): undefined reference to `readpassphrase'
collect2.exe: error: ld returned 1 exit status
make: *** [mingw64.Makefile:57: sigbak] Error 1

the gnulib docs say e.g. for openat that it is not supported on MinGW: https://www.gnu.org/software/gnulib/manual/html_node/openat.html.

I have the feeling that some of these issues can only be solved by changing some of the implementation - or adding missing pieces to the compat/ "layer". WDYT?

@tbvdm
Copy link
Owner

tbvdm commented Oct 2, 2024

sigbak is a Unix program and expects POSIX APIs like openat() to be available. I don't know MSYS2 well, but doesn't it have a POSIX emulation mode? Otherwise you'd have to provide compat implementations of the missing APIs in some other way. Perhaps via gnulib? You could also look at the Cygwin source for inspiration.

@fleimgruber
Copy link
Author

fleimgruber commented Oct 2, 2024

Yes, I looked into it a bit more and found that MSYS2 indeed has the Cygwin POSIX emulation layer, but there is no package for protobuf-c. MinGW64 and the other toolchains provided with MSYS2 do have the dependency packages, but use the Windows C stdlib, hence no POSIX.

I will experiment a bit with gnulib.

If this does not lead to anything I will leave it as is for someone with more knowledge regarding the needed API compat.

I achieved part of my goal of adding the Zig Build System as fleimgruber@a053cd5 works on the NixOS distribution. A Windows build would have been a bonus and I still learned something from attempting it.

@tbvdm
Copy link
Owner

tbvdm commented Oct 5, 2024

MSYS2 indeed has the Cygwin POSIX emulation layer, but there is no package for protobuf-c

Can you build protobuf-c as part of your sigbak build? I'm doing something similar in the Cygwin instructions in the README.

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

2 participants