woodser / monero-java

Java library for using Monero
https://woodser.github.io/monero-java/javadocs/
MIT License
105 stars 39 forks source link

building static libraries with shared library wrapper #105

Open nsec1 opened 2 months ago

nsec1 commented 2 months ago

Ref. #74 haveno-dex/haveno#795

Now, there is only monero-java.so. It wraps monero, monero-cpp, boost etc. Working with haveno on linux (--useNativeXmrWallet=true). Depends woodser/monero-cpp#64

nsec1 commented 2 weeks ago
In file included from /Users/woodser/git/monero-java/external/monero-cpp/external/monero-project/src/cryptonote_basic/connection_context.cpp:33:
/Users/woodser/git/monero-java/external/monero-cpp/external/monero-project/src/p2p/p2p_protocol_defs.h:195:7: error: static assertion failed due to requirement 'std::is_pod<boost::uuids::uuid>::value': t_type must be a POD type.
      KV_SERIALIZE_VAL_POD_AS_BLOB(network_id)

I was able to reproduce this error on debian-test using clang. Then I downgraded boost to 1.84 and the build has succeeded.

woodser commented 2 weeks ago

Bounty bumped to 4 XMR.

nsec1 commented 1 week ago

@woodser , could you send me this command output: export | grep CMAKE ?

woodser commented 1 week ago

It doesn't return any output.

image
woodser commented 1 week ago

Hey, happy to see more changes coming in. Please just let me know when it's ready for retesting.

nsec1 commented 1 week ago

I finally figured out what was happening with sodium include path. Monero-project considers that include path for sodium is the same for boost and openssl. Now with this PR, it is not true. I have to modify monero-project in my fork. I have problems with macos emulation, cmake is stucking on darling for example. I emulated the problem installing monero dependencies using homebrew on linux. I have kept Trezor support off because it failed to load Monero native libraries: java.lang.UnsatisfiedLinkError: /tmp/libmonero15436476446366776625/libmonero-java.so: undefined symbol: _ZTIN6google8protobuf7MessageE. Monero-cpp and monero-project are pointing to my branches in forked repos, to test more easily. We need change this before go upstream. Dont run bin/update_submodules.sh because branches will back to master. Use git submodule update --init --force --recursive. If your test were succeed on macos, I will send a PR to monero-project. For now, we could apply a patch of monero-project modifications in monero-cpp until PR merged and released. I had to put libsodium as module in monero-java and build with -fPIC. Could delete monero-cpp external/libsodium? Using boost-1.84 (1.86 incompatible with monero). I have tested haveno with native lib on linux. Hope this work on macos.

woodser commented 1 week ago

I'm hitting this error with your PR, which is probably related to your monero-project branch not having the latest fix for macOS:

/Users/woodser/git/monero-java/external/monero-cpp/external/monero-project/src/p2p/p2p_protocol_defs.h:195:7: error: static assertion failed due to requirement 'std::is_pod<boost::uuids::uuid>::value': t_type must be a POD type.
      KV_SERIALIZE_VAL_POD_AS_BLOB(network_id)

monero-cpp/external/libsodium is being used in the monero-ts project.

Perhaps it's better to move your libsodium solution to monero-cpp/external so it can be used by monero-ts as well?

woodser commented 1 week ago

Applying that fix from monero-project myself, I then get this error with your PRs:

/Users/woodser/git/monero-java/external/monero-cpp/external/monero-project/contrib/epee/include/span.h:165:5: error: static assertion failed due to requirement 'std::is_trivially_copyable<epee::mlocked<tools::scrubbed<crypto::ec_scalar>>>()': type must be trivially copyable

nsec1 commented 1 week ago

These errors are about boost-1.85+. I just downgraded boost to 1.84 in this solution because this. Could you send me out log?

nsec1 commented 1 week ago

I would confirm it with output log but for now, could you try to remove boost from homebrew and do a clean build again?

woodser commented 1 week ago

I was able to finally successfully build libmonero-cpp.a and libmonero-java.dylib. :)

By uninstallingn boost through brew and by making these changes to CMakeLists.txt to include hidapi: patch.txt

However, basic tests to execute the libraries through JNI are hitting an error.

To recreate the error, simply run the tests within TestMoneroUtils.java. They can easily be invoked by importing the project into Visual Studio Code (or Eclipse if you prefer):

image
nsec1 commented 1 week ago

I was able to finally successfully build libmonero-cpp.a and libmonero-java.dylib. :)

Cool!!

By uninstallingn boost through brew and by making these changes to CMakeLists.txt to include hidapi: patch.txt

Hidapi is needed only for Trezor support but it is off on monero build. I didnt understand why it is needed on mac. If we had to include hidapi on monero-java build (your patch), maybe it should become a module build with fPIC because it is dynamically linked.

However, basic tests to execute the libraries through JNI are hitting an error.

I will fix this.

nsec1 commented 6 days ago

@woodser , any problem keep on without hardware wallet support? Because this has new dependencies that we will have to build with static and fPIC.

woodser commented 4 days ago

Ideally we can keep existing hardware wallet dependencies, unless they are not already included? In which case, no need to add them as part of this PR.