xJonathanLEI / starkware-crypto-rs

Rust FFI bindings for StarkWare's crypto-cpp library
Apache License 2.0
15 stars 2 forks source link

Unable to build on Windows #3

Open xJonathanLEI opened 2 years ago

xJonathanLEI commented 2 years ago

After the macOS build issue was resolved, it's discovered that the library also fails to build on Windows, for both x86_64-pc-windows-gnu and x86_64-pc-windows-msvc targets.

Target triples to fix:

xJonathanLEI commented 2 years ago

Building for x86_64-pc-windows-gnu seems to work under MinGW-w64 after dealing with the endian.h issue, but x86_64-pc-windows-msvc continues to not work.

xJonathanLEI commented 2 years ago

It seems that #5 has made the library compile for x86_64-pc-windows-gnu. The only target left is x86_64-pc-windows-msvc.

milancermak commented 2 years ago

I just noticed that starkware-libs/crypto-cpp#8 contains more fancy endian.h, maybe it supports the MSVC Win version?

xJonathanLEI commented 2 years ago

Interesting! Will definitely look into it.

However, for the endian.h part, as mentioned in #4, I actually removed that on purpose for all platforms for the sake of saving library users from thinking about host endianess for good.

Unfortunately, that repository doesn't seem to be monitored by Starkware lol.

xJonathanLEI commented 2 years ago

Just tried using the PR branch to build with MSVC. No luck.

I think right now the issue is mostly about the lack of 128-bit integer support. Maybe we can try replacing that with Boost?

milancermak commented 2 years ago

The only thing I know about Boost is that I'm scared of it 😆

xJonathanLEI commented 2 years ago

I just tried replacing __int128_t with boost::multiprecision::uint128_t, and most of the errors are now gone. I'm still having issue with __builtin_clzll though. Making progress.

xJonathanLEI commented 2 years ago

Made some further changes and now it compiles on MSVC. FINALLY.

However, one of the tests is failing. Not sure why:

warning: cl : Command line warning D9002 : ignoring unknown option '-static'
warning: cl : Command line warning D9002 : ignoring unknown option '-static'
warning: cl : Command line warning D9002 : ignoring unknown option '-static'
warning: cl : Command line warning D9002 : ignoring unknown option '-static'
warning: cl : Command line warning D9002 : ignoring unknown option '-static'
warning: cl : Command line warning D9002 : ignoring unknown option '-static'
warning: cl : Command line warning D9002 : ignoring unknown option '-static'
    Finished test [unoptimized + debuginfo] target(s) in 0.09s
     Running unittests (target\debug\deps\starkware_crypto_sys-e779f33c123515e6.exe)

running 5 tests
test tests::test_hash ... ok
test tests::test_verify_invalid_message ... FAILED
test tests::test_verify_valid_message ... ok
test tests::test_get_public_key ... ok
test tests::test_sign ... ok

failures:

---- tests::test_verify_invalid_message stdout ----
thread 'tests::test_verify_invalid_message' panicked at 'assertion failed: `(left == right)`
  left: `true`,
 right: `false`', src\lib.rs:261:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    tests::test_verify_invalid_message

test result: FAILED. 4 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 3.56s

error: test failed, to rerun pass '--lib'

Looking into the issue now.