From d780ed915352dcb2b3b9718cea50a47965cb587f Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 9 Oct 2024 19:07:46 -0500 Subject: add example monero_c static lib build script courtesy of cypherstack/flutter_libmonero and MrCyjaneK & julian-CStack's work there remove wownero update docs and script add gitignore --- impls/monero_rust/.gitignore | 2 + impls/monero_rust/README.md | 40 +++++++++++++++ impls/monero_rust/scripts/build_monero_c.sh | 79 +++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 impls/monero_rust/.gitignore create mode 100644 impls/monero_rust/README.md create mode 100755 impls/monero_rust/scripts/build_monero_c.sh diff --git a/impls/monero_rust/.gitignore b/impls/monero_rust/.gitignore new file mode 100644 index 0000000..3638ffd --- /dev/null +++ b/impls/monero_rust/.gitignore @@ -0,0 +1,2 @@ +scripts/build +lib/ diff --git a/impls/monero_rust/README.md b/impls/monero_rust/README.md new file mode 100644 index 0000000..eeb3524 --- /dev/null +++ b/impls/monero_rust/README.md @@ -0,0 +1,40 @@ +# `monero_rust` +`monero_c` bindings for Rust. + +## Getting started +1. Build `monero_c` +2. Copy the `monero_c` static library to `monero_rust`. +3. Run `monero_rust` example + +### Build `monero_c` +Build a monero_c static Library for your architecture. Follow the upstream docs +at https://github.com/MrCyjaneK/monero_c or for example: +``` +./scripts/build_monero_c.sh +``` + + +or manually: +``` +git clone https://git.mrcyjanek.net/sneurlax/monero_c --branch rust +cd monero_c +git submodule update --init --recursive +rm -rf monero wownero release # Clean any previous builds. +git submodule update --init --recursive --force +./apply_patches.sh monero +./build_single.sh monero x86_64-linux-gnu -j$(nproc) +``` + + +### Copy the `monero_c` static library to `monero_rust`. +Copy your `libwallet` static library to `monero_c/impls/monero_rust/lib`. +``` +cp build/release/monero/x86_64-linux-gnu_libwallet2_api_c.so ../lib +``` + + +### Run `monero_rust` example +From `monero_c/impls/monero_rust`: +``` +cargo run +``` diff --git a/impls/monero_rust/scripts/build_monero_c.sh b/impls/monero_rust/scripts/build_monero_c.sh new file mode 100755 index 0000000..56af25e --- /dev/null +++ b/impls/monero_rust/scripts/build_monero_c.sh @@ -0,0 +1,79 @@ +# See https://github.com/MrCyjaneK/monero_c for the most up-to-date build docs, +# this is an example and a starting point for building monero_c for use in Rust +# but it should be automated either using CMake or Cargo (preferred). + +# From https://github.com/cypherstack/flutter_libmonero/blob/main/scripts/linux/build_all.sh +# flutter_libmonero/scripts/linux/build_all.sh: + +set -x -e + +# Build monero_c. +cd "$(dirname "$0")" + +if [[ ! "x$(uname)" == "xLinux" ]]; +then + echo "Only Linux hosts can build linux"; + exit 1 +fi + +#../prepare_moneroc.sh +# See https://github.com/cypherstack/flutter_libmonero/blob/main/scripts/prepare_moneroc.sh +# scripts/prepare_moneroc.sh: + +#!/bin/bash + +set -x -e + +cd "$(dirname "$0")" + +# Allow script caller to pass commit hash. +# dirty hack to handle broken monero_c on android. Uses same hash on linux as well to make dev life easier +# CHASH="$1" +# if [ -z "$CHASH" ]; then +# CHASH="294b593db30e8803586dfd0f47e716ce1200c766" +# fi + +# # We should be in monero_c/impls/monero_rust/scripts... +# cd ../../.. +# Instead of building the monero_c we already have, let's clone another, "fresher" one (: + +#rm -rf build +if [[ ! -d "build" ]]; +then + git clone https://github.com/sneurlax/monero_c build --branch rust + cd build +else + cd build +fi +# git checkout "6eb571ea498ed7b854934785f00fabfd0dadf75b" # TODO update. +git checkout rust +git reset --hard +# TODO migrate all git repos to github (or back to the official wow repo, which is spotty). +# git config submodule.libs/wownero.url https://git.cypherstack.com/Cypher_Stack/wownero +# git config submodule.libs/wownero-seed.url https://git.cypherstack.com/Cypher_Stack/wownero-seed +git submodule update --init --force --recursive +./apply_patches.sh monero +#./apply_patches.sh wownero + +if [[ ! -f "monero/.patch-applied" ]]; +then + ./apply_patches.sh monero +fi + +# if [[ ! -f "wownero/.patch-applied" ]]; +# then +# ./apply_patches.sh wownero +# fi +# cd .. + +echo "monero_c source prepared" + +# flutter_libmonero/scripts/linux/build_all.sh cont. ... + +pushd ../build + ./build_single.sh monero x86_64-linux-gnu -j8 # TODO use nproc or similar. +# ./build_single.sh wownero x86_64-linux-gnu -j8 +popd + +unxz -f build/release/monero/x86_64-linux-gnu_libwallet2_api_c.so.xz +#unxz -f build/release/wownero/x86_64-linux-gnu_libwallet2_api_c.so.xz -- cgit v1.2.3