From eb7cc583ef7ce825520795fde2b514a304c5548c Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 10 Oct 2024 17:03:38 -0500 Subject: support building other archs, copy file to correct path and touch gitignore --- .gitignore | 1 - impls/monero_rust/.gitignore | 3 +- impls/monero_rust/README.md | 30 +++---- impls/monero_rust/scripts/build_monero_c.sh | 131 ++++++++++++++++------------ 4 files changed, 91 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index abc4113..1070540 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ release/ build/ -impls/monero_rust/target/ diff --git a/impls/monero_rust/.gitignore b/impls/monero_rust/.gitignore index 3638ffd..e5eea29 100644 --- a/impls/monero_rust/.gitignore +++ b/impls/monero_rust/.gitignore @@ -1,2 +1,3 @@ -scripts/build +target/ +scripts/monero_c lib/ diff --git a/impls/monero_rust/README.md b/impls/monero_rust/README.md index fa851fa..5affbd1 100644 --- a/impls/monero_rust/README.md +++ b/impls/monero_rust/README.md @@ -1,5 +1,5 @@ # `monero_rust` -`monero_c` bindings for Rust. +Proof of concept `monero_c` bindings for Rust. ## Getting started -1. Build `monero_c` -2. Copy the `monero_c` 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: +Build the monero_c Library for your architecture. Follow the upstream docs at +https://github.com/MrCyjaneK/monero_c and +place the library at `monero_c/impls/monero_rust/lib/libwallet2_api_c.so` or use +the provided script: ``` -./scripts/build_monero_c.sh +cd scripts +./build_monero_c.sh ``` - -or manually: +or build it manually as in: ``` git clone https://git.mrcyjanek.net/sneurlax/monero_c --branch rust cd monero_c @@ -30,16 +28,12 @@ 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` library to `monero_rust`. -Copy your `libwallet` library to `monero_c/impls/monero_rust/lib`. -``` -cp build/release/monero/x86_64-linux-gnu_libwallet2_api_c.so ../lib -mv ../lib/x86_64-linux-gnu_libwallet2_api_c.so ../lib/libx86_64-linux-gnu_libwallet2_api_c.so +# Adjust the commands below for your arch. +unxz -f release/monero/x86_64-linux-gnu_libwallet2_api_c.so.xz +mv release/monero/x86_64-linux-gnu_libwallet2_api_c.so ../lib/libwallet2_api_c.so +# The library should be at monero_c/impls/monero_rust/lib/libwallet2_api_c.so. ``` - ### Run `monero_rust` example From `monero_c/impls/monero_rust`: diff --git a/impls/monero_rust/scripts/build_monero_c.sh b/impls/monero_rust/scripts/build_monero_c.sh index 56af25e..a92adfe 100755 --- a/impls/monero_rust/scripts/build_monero_c.sh +++ b/impls/monero_rust/scripts/build_monero_c.sh @@ -1,56 +1,69 @@ -# 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: +#!/bin/bash set -x -e -# Build monero_c. -cd "$(dirname "$0")" +# 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). -if [[ ! "x$(uname)" == "xLinux" ]]; -then - echo "Only Linux hosts can build linux"; - exit 1 -fi +# Detect architecture. +ARCH=$(uname -m) +OS=$(uname -s) + +case $ARCH-$OS in + x86_64-Linux) + TARGET_ARCH="x86_64-linux-gnu" + ;; + i686-Linux) + TARGET_ARCH="i686-linux-gnu" + ;; + aarch64-Linux) + TARGET_ARCH="aarch64-linux-gnu" + ;; + x86_64-Android) + TARGET_ARCH="x86_64-linux-android" + ;; + i686-Android) + TARGET_ARCH="i686-linux-android" + ;; + aarch64-Android) + TARGET_ARCH="aarch64-linux-android" + ;; + armv7l-Android) + TARGET_ARCH="arm-linux-androideabi" + ;; + i686-Windows) + TARGET_ARCH="i686-w64-mingw32" + ;; + x86_64-Windows) + TARGET_ARCH="x86_64-w64-mingw32" + ;; + x86_64-Darwin) + TARGET_ARCH="host-apple-darwin" + ;; + arm64-Darwin) + TARGET_ARCH="host-apple-ios" + ;; + *) + echo "Unsupported architecture: $ARCH on OS: $OS" + exit 1 + ;; +esac #../prepare_moneroc.sh # See https://github.com/cypherstack/flutter_libmonero/blob/main/scripts/prepare_moneroc.sh -# scripts/prepare_moneroc.sh: - -#!/bin/bash +# flutter_libmonero/scripts/prepare_moneroc.sh: -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" ]]; +if [[ ! -d "monero_c" ]]; then - git clone https://github.com/sneurlax/monero_c build --branch rust - cd build -else - cd build + #rm -rf monero_c + git clone https://github.com/sneurlax/monero_c --branch rust fi -# git checkout "6eb571ea498ed7b854934785f00fabfd0dadf75b" # TODO update. -git checkout rust +cd monero_c +#git checkout "6eb571ea498ed7b854934785f00fabfd0dadf75b" 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 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 @@ -60,20 +73,30 @@ then ./apply_patches.sh monero fi -# if [[ ! -f "wownero/.patch-applied" ]]; -# then -# ./apply_patches.sh wownero -# fi -# cd .. - -echo "monero_c source prepared" +#if [[ ! -f "wownero/.patch-applied" ]]; +#then +# ./apply_patches.sh wownero +#fi # 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 +pushd ../monero_c + ./build_single.sh monero "$TARGET_ARCH" -j$(nproc) + #./build_single.sh wownero "$TARGET_ARCH" -j$(nproc) 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 +unxz -f release/monero/${TARGET_ARCH}_libwallet2_api_c.so.xz +#unxz -f release/wownero/${TARGET_ARCH}_libwallet2_api_c.so.xz + +# Navigate back to /scripts. +cd .. + +# Copy the built .so file to a generic name. +SO_FILE="monero_c/release/monero/${TARGET_ARCH}_libwallet2_api_c.so" +if [[ -f "$SO_FILE" ]]; then + cp "$SO_FILE" "../lib/libwallet2_api_c.so" + echo "Copied $SO_FILE to libwallet2_api_c.so" +else + echo "Error: $SO_FILE not found." + exit 1 +fi -- cgit v1.2.3