libgit2/pygit2 — pull request #107 by cboos (2012-06-09 14:38:30+00:00)
Title: windows: detailed build instructions

The default build of libgit2 with `__stdcall` calling
convention is inadequate. We need to use a more standard
`__cdecl` build, which can be obtained by specifying
`-DSTDCALL=OFF` while configuring libgit2.

Also mention the LIBGIT2 environment variable (2b4e5504).

----

The default build of libgit2 with `__stdcall` calling convention is inadequate because:

1. in libgit2, the `__stdcall` calling convention is enforced by the use of the `/Gz` compilation flag; but the use of this calling convention is not made visible in the headers, so when building the pygit2 extension the normal `__cdecl` calling convention will be assumed; linking the `_pygit2.pyd` library will then fail with errors such as:
```
pygit2.obj : error LNK2019: unresolved external symbol _git_repository_free referenced in function _init_repository
...
```

2. if one manages nevertheless to link the extension in that mode (for example, by using libgit2/libgit2#749), the next problem is the presence of crashes when running the unit tests. The first one is `test_new_repo`, but there are more.

Trying to debugging this crash proved to be pretty hard for me (i.e. no clue), and the crash actually disappears if one tries to use the debug versions of Python (python_d.exe), libgit2 built in `--config debug` mode and the pygit2 extension built in debug mode (i.e. in this situation, `python_d.exe setup.py build_ext --debug test` *doesn't* trigger a crash!).

OTOH, when building with libgit2 built with the `__cdecl` calling convention, I don't get a crash, only the few known errors (#60/#83).

What I didn't do so far is build the extension with mingw... but I suppose it's the way other people build it, otherwise they would also have run into the problems described above. Would be nice if someone could document that as well (which version of mingw gcc to use, etc.).