Skip to content

Commit

Permalink
nostr: add git_hash_version func
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 16, 2023
1 parent a555c52 commit c08849a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bindings/nostr-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ mod ffi {
pub use crate::types::{Contact, ImageDimensions, Metadata, Profile, Timestamp};
pub use crate::util::generate_shared_key;

pub fn git_hash_version() -> String {
nostr::git_hash_version().to_string()
}

// UDL
uniffi::include_scaffolding!("nostr");
}
Expand Down
2 changes: 2 additions & 0 deletions bindings/nostr-ffi/src/nostr.udl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Distributed under the MIT software license

namespace nostr {
string git_hash_version();

[Throws=NostrError]
sequence<u8> generate_shared_key(SecretKey secret_key, PublicKey public_key);

Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ trait FromResult<T>: Sized {
mod ffi {
// External
pub use nostr_ffi::{
generate_shared_key, get_nip05_profile, nip04_decrypt, nip04_encrypt, verify_nip05,
ClientMessage, Contact, Event, EventBuilder, EventId, FileMetadata, Filter,
generate_shared_key, get_nip05_profile, git_hash_version, nip04_decrypt, nip04_encrypt,
verify_nip05, ClientMessage, Contact, Event, EventBuilder, EventId, FileMetadata, Filter,
ImageDimensions, Keys, Metadata, NostrConnectURI, NostrError, Profile, PublicKey,
RelayInformationDocument, RelayMessage, SecretKey, Tag, TagEnum, TagKind, TagKindKnown,
Timestamp, UnsignedEvent, ZapRequestData,
Expand Down
2 changes: 2 additions & 0 deletions bindings/nostr-sdk-ffi/src/nostr_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Distributed under the MIT software license

namespace nostr_sdk {
string git_hash_version();

// Nostr
[Throws=NostrError]
sequence<u8> generate_shared_key(SecretKey secret_key, PublicKey public_key);
Expand Down
14 changes: 14 additions & 0 deletions crates/nostr/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2022-2023 Yuki Kishimoto
// Distributed under the MIT software license

#[cfg(feature = "std")]
use std::process::Command;

fn main() {
#[cfg(feature = "std")]
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
if let Ok(git_hash) = String::from_utf8(output.stdout) {
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}
}
}
6 changes: 6 additions & 0 deletions crates/nostr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ pub use self::util::SECP256K1;
/// Result
#[cfg(feature = "std")]
pub type Result<T, E = alloc::boxed::Box<dyn std::error::Error>> = std::result::Result<T, E>;

/// Git Hash
#[cfg(feature = "std")]
pub fn git_hash_version() -> &'static str {
env!("GIT_HASH")
}

0 comments on commit c08849a

Please sign in to comment.