summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--impls/monero_rust/.gitignore3
-rw-r--r--impls/monero_rust/Cargo.lock7
-rw-r--r--impls/monero_rust/Cargo.toml14
-rw-r--r--impls/monero_rust/LICENSE22
-rw-r--r--impls/monero_rust/README.md42
-rw-r--r--impls/monero_rust/build.rs15
-rwxr-xr-ximpls/monero_rust/scripts/build_monero_c.sh102
-rw-r--r--impls/monero_rust/src/main.rs10
9 files changed, 216 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 4d94944..1070540 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
release/
-build/ \ No newline at end of file
+build/
diff --git a/impls/monero_rust/.gitignore b/impls/monero_rust/.gitignore
new file mode 100644
index 0000000..e5eea29
--- /dev/null
+++ b/impls/monero_rust/.gitignore
@@ -0,0 +1,3 @@
+target/
+scripts/monero_c
+lib/
diff --git a/impls/monero_rust/Cargo.lock b/impls/monero_rust/Cargo.lock
new file mode 100644
index 0000000..bb713b5
--- /dev/null
+++ b/impls/monero_rust/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "monero_rust"
+version = "0.0.1"
diff --git a/impls/monero_rust/Cargo.toml b/impls/monero_rust/Cargo.toml
new file mode 100644
index 0000000..0815b9e
--- /dev/null
+++ b/impls/monero_rust/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "monero_rust"
+version = "0.0.1"
+edition = "2021"
+description = "monero_c Rust bindings."
+repository = "https://github.com/ManyMath/monero_rust"
+license = "MIT"
+build = "build.rs"
+
+[[bin]]
+name = "monero_rust"
+path = "src/main.rs"
+
+[dependencies]
diff --git a/impls/monero_rust/LICENSE b/impls/monero_rust/LICENSE
new file mode 100644
index 0000000..45a85f9
--- /dev/null
+++ b/impls/monero_rust/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2024 Joshua Babb
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/impls/monero_rust/README.md b/impls/monero_rust/README.md
new file mode 100644
index 0000000..5affbd1
--- /dev/null
+++ b/impls/monero_rust/README.md
@@ -0,0 +1,42 @@
+# `monero_rust`
+Proof of concept `monero_c` bindings for Rust.
+
+## Getting started
+<!--
+### Prerequisites
+You may need
+```
+sudo apt-get install libhidapi-dev
+```
+-->
+### Build `monero_c`
+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:
+```
+cd scripts
+./build_monero_c.sh
+```
+
+or build it manually as in:
+```
+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)
+
+# 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`:
+```
+cargo run
+```
diff --git a/impls/monero_rust/build.rs b/impls/monero_rust/build.rs
new file mode 100644
index 0000000..47c41a6
--- /dev/null
+++ b/impls/monero_rust/build.rs
@@ -0,0 +1,15 @@
+use std::env;
+use std::path::PathBuf;
+
+fn main() {
+ println!("cargo:rerun-if-changed=build.rs");
+
+ let lib_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("lib");
+
+ println!("cargo:rustc-link-search=native={}", lib_dir.display());
+ println!("cargo:rustc-link-lib=dylib=wallet2_api_c");
+ println!("cargo:rustc-link-lib=dylib=stdc++");
+ println!("cargo:rustc-link-lib=dylib=hidapi-hidraw");
+
+ println!("cargo:rustc-link-arg-bin=monero_rust=-Wl,-rpath,$ORIGIN/../../lib");
+}
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..a92adfe
--- /dev/null
+++ b/impls/monero_rust/scripts/build_monero_c.sh
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+set -x -e
+
+# 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).
+
+# 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
+# flutter_libmonero/scripts/prepare_moneroc.sh:
+
+if [[ ! -d "monero_c" ]];
+then
+ #rm -rf monero_c
+ git clone https://github.com/sneurlax/monero_c --branch rust
+fi
+cd monero_c
+#git checkout "6eb571ea498ed7b854934785f00fabfd0dadf75b"
+git reset --hard
+#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
+
+# flutter_libmonero/scripts/linux/build_all.sh cont. ...
+
+pushd ../monero_c
+ ./build_single.sh monero "$TARGET_ARCH" -j$(nproc)
+ #./build_single.sh wownero "$TARGET_ARCH" -j$(nproc)
+popd
+
+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
diff --git a/impls/monero_rust/src/main.rs b/impls/monero_rust/src/main.rs
new file mode 100644
index 0000000..0e76a13
--- /dev/null
+++ b/impls/monero_rust/src/main.rs
@@ -0,0 +1,10 @@
+fn main() {
+ unsafe {
+ MONERO_DEBUG_test0();
+ }
+ println!("Called MONERO_DEBUG_test0 successfully.");
+}
+
+extern "C" {
+ fn MONERO_DEBUG_test0();
+}