incubator-milagro-crypto-c
incubator-milagro-crypto-c copied to clipboard
Enable MSVC compilation
Hello,
We've prepared bunch of changes that enable milagro compilation in MS Visual Studio.
The changes can be divided into 3 groups:
- trivial name<->type clash
- variable array stack allocation (this is C99, which VS does not fully support, solutions below)
- static and dynamic symbol export (most intrusive part)
Re 2. In case of C code adding const
to array length vars doesn't change anything (in VS). There are 2 various solutions applied:
- where possible, variable holding length is turned into define (i.e.
int n -> #define NUM_SHARES
) - where it's not possible _alloca is used (i.e. where length is passed via function arg)
Re 3. Static libs should compile with modifications from 1 and 2, dynamic libs, require few more changes.
Cmake's CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS is used to export most of the symbols, this however does not work for data exported via amcl_curve_*
libraries
To fix that:
- definitions are prefixed with
SYMBOL_EXPORT
defined as emtpy for non-msvc inamcl.h.in
- declarations are prefixed with
EXTERNAL_SYMBOL_DECLARATION
,- in case of non-vs, this is ==
extern
- in vs case this is either
declspec(dllexport)
in case ofamcl_curve_*
libraries anddeclspec(dllimport)
for all other libraries including those header files.
- in case of non-vs, this is ==
Finally my question is following: would you prefer this change split into some smaller chunks, or is ok to issue it as a single pull request?
FYI: whole change is here: https://github.com/apache/incubator-milagro-crypto-c/compare/develop...nemtech:msvc-compilation