incubator-milagro-crypto-c icon indicating copy to clipboard operation
incubator-milagro-crypto-c copied to clipboard

Enable MSVC compilation

Open gimre-xymcity opened this issue 4 years ago • 6 comments

Hello,

We've prepared bunch of changes that enable milagro compilation in MS Visual Studio.

The changes can be divided into 3 groups:

  1. trivial name<->type clash
  2. variable array stack allocation (this is C99, which VS does not fully support, solutions below)
  3. 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 in amcl.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 of amcl_curve_* libraries and declspec(dllimport) for all other libraries including those header files.

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

gimre-xymcity avatar Sep 08 '20 13:09 gimre-xymcity