diff options
| author | sneurlax <sneurlax@gmail.com> | 2024-10-10 14:05:32 -0500 |
|---|---|---|
| committer | sneurlax <sneurlax@gmail.com> | 2024-10-10 14:05:51 -0500 |
| commit | 2a316156e914e744ed8aae501a5d5c4061df5f73 (patch) | |
| tree | 1d0e9122156db784113cb8a6003d11d985043ff8 /impls | |
| parent | d780ed915352dcb2b3b9718cea50a47965cb587f (diff) | |
add example rust binding
Diffstat (limited to 'impls')
| -rw-r--r-- | impls/monero_rust/Cargo.lock | 7 | ||||
| -rw-r--r-- | impls/monero_rust/Cargo.toml | 14 | ||||
| -rw-r--r-- | impls/monero_rust/LICENSE | 22 | ||||
| -rw-r--r-- | impls/monero_rust/README.md | 16 | ||||
| -rw-r--r-- | impls/monero_rust/build.rs | 15 | ||||
| -rw-r--r-- | impls/monero_rust/src/main.rs | 10 |
6 files changed, 80 insertions, 4 deletions
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 index eeb3524..fa851fa 100644 --- a/impls/monero_rust/README.md +++ b/impls/monero_rust/README.md @@ -2,8 +2,15 @@ `monero_c` bindings for Rust. ## Getting started +<!-- +### Prerequisites +You may need +``` +sudo apt-get install libhidapi-dev +``` +--> 1. Build `monero_c` -2. Copy the `monero_c` static library to `monero_rust`. +2. Copy the `monero_c` library to `monero_rust`. 3. Run `monero_rust` example ### Build `monero_c` @@ -26,12 +33,13 @@ git submodule update --init --recursive --force ``` <!-- TODO add unxz etc --> -### Copy the `monero_c` static library to `monero_rust`. -Copy your `libwallet` static library to `monero_c/impls/monero_rust/lib`. +### 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 ``` -<!-- TODO automatically copy using arch provided as param IAW TODO above --> +<!-- TODO automatically copy and rename using arch param IAW TODO above --> ### Run `monero_rust` example From `monero_c/impls/monero_rust`: 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/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(); +} |
