Skip to content

Commit

Permalink
support building other archs, copy file to correct path
Browse files Browse the repository at this point in the history
and touch gitignore
  • Loading branch information
sneurlax committed Oct 10, 2024
1 parent 2a31615 commit eb7cc58
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 74 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
release/
build/
impls/monero_rust/target/
3 changes: 2 additions & 1 deletion impls/monero_rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
scripts/build
target/
scripts/monero_c
lib/
30 changes: 12 additions & 18 deletions impls/monero_rust/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# `monero_rust`
`monero_c` bindings for Rust.
Proof of concept `monero_c` bindings for Rust.

## Getting started
<!--
Expand All @@ -9,19 +9,17 @@ You may need
sudo apt-get install libhidapi-dev
```
-->
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 <!-- TODO: use example CMakeLists --> 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
```
<!-- TODO add param for arch -->

or manually:
or build it manually as in:
```
git clone https://git.mrcyjanek.net/sneurlax/monero_c --branch rust
cd monero_c
Expand All @@ -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)
```
<!-- TODO add unxz etc -->
### 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.
```
<!-- TODO automatically copy and rename using arch param IAW TODO above -->

### Run `monero_rust` example
From `monero_c/impls/monero_rust`:
Expand Down
131 changes: 77 additions & 54 deletions impls/monero_rust/scripts/build_monero_c.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit eb7cc58

Please sign in to comment.