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

Issues with building on Windows #14

Open
phryneas opened this issue Apr 23, 2017 · 13 comments
Open

Issues with building on Windows #14

phryneas opened this issue Apr 23, 2017 · 13 comments

Comments

@phryneas
Copy link
Contributor

Hi there,
I'm trying to use this library on Windows using the msys2 mingw64.

First of all: if you want to try this yourself, you have to install the mingw gpgme library using pacman -S mingw-w64-x86_64-gpgme and you have to do so in the mingw64 environment.

Now the problems:
For one, it complains when building the unsetenvGPGAgentInfo function:

% go run main.go                                                                                                                                                             # github.com/proglottis/gpgme
could not determine kind of name for C.unsetenv
[1]    13260 exit 2     go run src/main/hostApp.go

when I just comment this line out (as I understand the comment, it is just used for testing?), I get this error:

# github.com/proglottis/gpgme
src\github.com\proglottis\gpgme\data.go:184: cannot use C.off_t(offset) (type C.off_t) as type C.gpgme_off_t in argument to func literal

changing the offending line to
n, err := C.gpgme_data_seek(d.dh, C.gpgme_off_t(offset), C.int(whence))
let's me compile everything.

I still haven't come around to really using the library yet, that will be my next step. I just thought I'd report what I've encountered so far.

Thanks for the wrapper, it's really appreciated.

@proglottis
Copy link
Owner

Thanks for the report. I've never tried compiling this on windows. So I suspect you are paving the way.

Couple of things, unsetenv is the implementation for unsetenvGPGAgentInfo and is only actually used for tests to override GPG_AGENT_INFO. Hopefully there's an alternate way of doing this.

Second, off_t is part of the posix C std. So it's probably missing in windows? I suspect gpgme defines its own in windows for this reason. Happy with that patch, but there're a couple of other usages of off_t that should probably get converted too. It might require a little C wrapper if CGO complains too much. I'm happy to test any patches on my end

@phryneas
Copy link
Contributor Author

Seems like that is the only instance of off_t preventing me from compiling it, which is quite weird.

But for now, I also was compiling against the gpgme v1.6.1 which is included with msys2, not against the version shipped with the GPG 2.1 installer (which I guess might be around 1.9).
So right now, it's not working with my agent and I'll have to try compiling against the other one. I guess everything will be different there, so we'll see ;)

@proglottis
Copy link
Owner

I don't think CGO knows about typedefs in C. I pushed a quick little patch so it can compile in both windows and linux/osx. https://github.com/proglottis/gpgme/tree/windows_data_seek

@phryneas
Copy link
Contributor Author

I'll try that once my libraries finish compiling :)

On the unsetenv issue: that seems to be a mingw issue.
It is documented on https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Function-Portability.html

unsetenv
On MinGW, unsetenv is not available, but a variable ‘FOO’ can be removed with a call putenv ("FOO="), as described under putenv above.

@phryneas
Copy link
Contributor Author

just as a quick feedback: your patch seems to compile fine for me

@phryneas
Copy link
Contributor Author

phryneas commented May 1, 2017

Okay, just got it to compile against the official downloadable GnuPG binaries (>2.1).

I am using vanilla MinGW now, that requires an additional change in go_gpgme.h:

--- a/go_gpgme.h
+++ b/go_gpgme.h
@@ -8,7 +8,7 @@

 extern ssize_t gogpgme_readfunc(void *handle, void *buffer, size_t size);
 extern ssize_t gogpgme_writefunc(void *handle, void *buffer, size_t size);
-extern off_t gogpgme_seekfunc(void *handle, off_t offset, int whence);
+extern gpgme_off_t gogpgme_seekfunc(void *handle, gpgme_off_t offset, int whence);
 extern gpgme_error_t gogpgme_passfunc(void *hook, char *uid_hint, char *passphrase_info, int prev_was_bad, int fd);
 extern gpgme_error_t gogpgme_data_new_from_cbs(gpgme_data_t *dh, gpgme_data_cbs_t cbs, uintptr_t handle);
 extern void gogpgme_set_passphrase_cb(gpgme_ctx_t ctx, gpgme_passphrase_cb_t cb, uintptr_t handle);

Compiling can be done with this batch file - documenting this here in case anyone else wants to do this:

REM ./include should contain header files from C:\Program Files (x86)\GnuPG\include
REM ./lib should contain files from C:\Program Files (x86)\GnuPG\lib, with extension .imp changed to .a (libgpg-err.a, libassuan.a, libgpgme.a)
REM ./ should contain dll files from C:\Program Files (x86)\GnuPG\bin (libassuan-0.dll  libgpg-error-0.dll  libgpgme-11.dll)

set PATH=%PATH%;C:\Go\bin
set PATH=%PATH%;C:\mingw\mingw32\bin
set GOPATH=%~dp0

set CGO_CFLAGS=-I%~dp0\include
set CGO_LDFLAGS=-L%~dp0\lib

go build yourfile.go

@phryneas
Copy link
Contributor Author

phryneas commented May 1, 2017

in case my change does not make real sense for you, here is the original error message:

# github.com/proglottis/gpgme
In file included from $WORK\github.com\proglottis\gpgme\_obj\_cgo_export.c:3:0:
cgo-gcc-export-header-prolog:46:20: error: conflicting types for 'gogpgme_seekfunc'
In file included from src\github.com\proglottis\gpgme\data.go:6:0,
                 from $WORK\github.com\proglottis\gpgme\_obj\_cgo_export.c:3:
src\github.com\proglottis\gpgme/go_gpgme.h:11:14: note: previous declaration of 'gogpgme_seekfunc' was here
 extern off_t gogpgme_seekfunc(void *handle, off_t offset, int whence);
              ^~~~~~~~~~~~~~~~
C:\Users\WEBER~1.VOS\AppData\Local\Temp\go-build897854538\github.com\proglottis\gpgme\_obj\_cgo_export.c:59:13: error: conflicting types for 'gogpgme_seekfunc'
 gpgme_off_t gogpgme_seekfunc(void* p0, gpgme_off_t p1, int p2)
             ^~~~~~~~~~~~~~~~
In file included from src\github.com\proglottis\gpgme\data.go:6:0,
                 from $WORK\github.com\proglottis\gpgme\_obj\_cgo_export.c:3:
src\github.com\proglottis\gpgme/go_gpgme.h:11:14: note: previous declaration of 'gogpgme_seekfunc' was here
 extern off_t gogpgme_seekfunc(void *handle, off_t offset, int whence);
              ^~~~~~~~~~~~~~~~

@phryneas
Copy link
Contributor Author

phryneas commented May 2, 2017

Sorry, that must have been some old version I had checked out in-between. Did a clean checkout on another PC and everything works.. :)

@phryneas
Copy link
Contributor Author

phryneas commented May 2, 2017

Okay,
to make everything reproducible, I've set up a CI that automatically builds proglottis/gpgme from your repo and runs the test.
https://github.com/phryneas/go_gpgme_build_windows
you can see the latest build & test results here:
https://ci.appveyor.com/project/phryneas/go-gpgme-build-windows

There are still some tests that are failing and I'm not really sure what's happening there. It would be great if you could have a look.
Most things I've tried to use so far worked for me though.

@proglottis
Copy link
Owner

Hey that's really cool! I didn't think any of those CI places would let me have gpgme.

Could be coincidence but both those tests are using temp dir/file. I wonder if CI is a bit unhappy about that. The only other test to use tmp is AssuanSend but it doesn't make GPG write to it

@phryneas
Copy link
Contributor Author

phryneas commented May 3, 2017

I guess you'll be getting a pull request that runs the tests on windows with appveyor and on linux with travis from me ;)

As for the failing tests: that reflects what I'm getting locally, so it doesn't seem to be a CI thing. Even worse, the TestContext_Import sometimes just hangs until I manually quit it.

@wagnerma
Copy link

wagnerma commented Jul 4, 2017

Hi, I also try to use this library under Windows. I am a newbie in programing with go, so perhaps my question is silly ;-)
I installed go for windows and also gnupg-w32. All is usable from the command line. I copied gpgme.h and gpg-error.h from the gnupg installation directory to the build directory.
Then I try to prepare the library with:
go get -u github.com/proglottis/gpgme
I get the same error mentioned above:

could not determine kind of name for C.unsetenv

Should be the library useable under Windows? Is this still a problem? I am missing something?
Thanks for your help and also for the work!
Cheers,
Marcel

@phryneas
Copy link
Contributor Author

phryneas commented Jul 4, 2017

just replace the C.unsetenv(v) in gpgme.go with C.putenv(v) - on MinGW, unsetenv is not available.

PS: oh, and v has to be GPG_AGENT_INFO= instead of GPG_AGENT_INFO

see the part about unsetenv in https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Function-Portability.html

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

3 participants