diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2019-01-09 12:33:47 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-01-17 21:17:32 +0000 |
commit | a74dd39b232ae8c54517446089316b9643b3a84a (patch) | |
tree | b4d6a15a17f6a45570a804331cba34eab5d7994b | |
parent | b78bcbb9b1217d6aada0ab98f3053cb8f151a8a3 (diff) | |
download | libgit2-a74dd39b232ae8c54517446089316b9643b3a84a.tar.gz |
Use cdecl calling conventions on Win32
The recommendation from engineers within Microsoft is that libraries
should have a calling convention specified in the public API, and that
calling convention should be cdecl unless there are strong reasons to
use a different calling convention.
We previously offered end-users the choice between cdecl and stdcall
calling conventions. We did this for presumed wider compatibility: most
Windows applications will use cdecl, but C# and PInvoke default to
stdcall for WINAPI compatibility. (On Windows, the standard library
functions are are stdcall so PInvoke also defaults to stdcall.)
However, C# and PInvoke can easily call cdecl APIs by specifying an
annotation.
Thus, we will explicitly declare ourselves cdecl and remove the option
to build as stdcall.
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | include/git2/common.h | 2 |
3 files changed, 3 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index eff2500d5..f1da8c9f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,14 +74,6 @@ IF (APPLE) ENDIF() IF(MSVC) - # This option is only available when building with MSVC. By default, libgit2 - # is build using the cdecl calling convention, which is useful if you're - # writing C. However, the CLR and Win32 API both expect stdcall. - # - # If you are writing a CLR program and want to link to libgit2, you'll want - # to turn this on by invoking CMake with the "-DSTDCALL=ON" argument. - OPTION(STDCALL "Build libgit2 with the __stdcall convention" OFF) - # This option must match the settings used in your program, in particular if you # are linking statically OPTION(STATIC_CRT "Link the static CRT libraries" ON) @@ -125,10 +117,8 @@ IF (MSVC) # /MP - Parallel build SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") - IF (STDCALL) - # /Gz - stdcall calling convention - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz") - ENDIF () + # /Gd - explicitly set cdecl calling convention + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") IF (STATIC_CRT) SET(CRT_FLAG_DEBUG "/MTd") @@ -255,7 +255,6 @@ The following CMake variables are declared: - `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON) - `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON) - `THREADSAFE`: Build libgit2 with threading support (defaults to ON) -- `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON) To list all build options and their current value, you can do the following: diff --git a/include/git2/common.h b/include/git2/common.h index 82f6ba48b..b97f9ef8a 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -43,7 +43,7 @@ typedef size_t size_t; __attribute__((visibility("default"))) \ type #elif defined(_MSC_VER) -# define GIT_EXTERN(type) __declspec(dllexport) type +# define GIT_EXTERN(type) __declspec(dllexport) type __cdecl #else # define GIT_EXTERN(type) extern type #endif |