Skip to content

Commit

Permalink
Libxmtp Versioning (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa authored Feb 12, 2024
1 parent 9ab31f2 commit 42c3630
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@ _site

# Generated Uniffi definitions
xmtpv3.kt

# Libxmtp build version
libxmtp-version.txt

# Directories from v2 branch
bindings_swift/
ecies_bindings_wasm/
9 changes: 8 additions & 1 deletion bindings_ffi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ARCHS_MAC = x86_64-apple-darwin aarch64-apple-darwin
# ARCHS_MACCATALYST = x86_64-apple-ios-macabi aarch64-apple-ios-macabi
LIB=libxmtpv3.a
JAR_DIR=$(shell pwd)/tests/jar
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT_HASH=$(shell git log -1 --pretty=format:"%h")
GIT_COMMIT_DATE=$(shell TZ=UTC git log -1 --date=iso-local --pretty=format:"%ad")

install-jar:
mkdir -p $(JAR_DIR) && \
Expand All @@ -27,6 +30,9 @@ download-toolchains:

all: framework

libxmtp-version:
echo "Version: $(GIT_COMMIT_HASH)\nBranch: $(GIT_BRANCH)\nDate: $(GIT_COMMIT_DATE)" > libxmtp-version.txt

$(ARCHS_IOS): %:
cross build --target $@ --target-dir ./target --release --no-default-features
mkdir -p build/$@
Expand Down Expand Up @@ -63,7 +69,7 @@ framework: lipo
-output LibXMTPRust.xcframework

# build uniffi bindings for swift
swift:
swift: libxmtp-version
cargo build --release
rm -rf build/swift
target/release/ffi-uniffi-bindgen generate \
Expand All @@ -75,6 +81,7 @@ swift:
mkdir -p build/swift/include
mv build/swift/$(PROJECT_NAME)FFI.h build/swift/include/
mv build/swift/$(PROJECT_NAME)FFI.modulemap build/swift/include/module.modulemap
cp libxmtp-version.txt build/swift/

swiftlocal: libxmtpv3.a swift framework

Expand Down
6 changes: 6 additions & 0 deletions bindings_ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use std::process::Command;

fn main() {
uniffi::generate_scaffolding("./src/xmtpv3.udl").expect("Building the UDL file failed");
Command::new("make")
.args(&["libxmtp-version"])
.status()
.expect("failed to make libxmtp-version");
}
2 changes: 1 addition & 1 deletion bindings_ffi/examples/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MainActivity : AppCompatActivity() {
walletSignature = inboxOwner.sign(textToSign)
}
client.registerIdentity(walletSignature);
textView.text = "Client constructed, wallet address: " + client.accountAddress()
textView.text = "Libxmtp version\n" + uniffi.xmtpv3.getVersionInfo() + "\n\nClient constructed, wallet address: " + client.accountAddress()
Log.i("App", "Setting up conversation streaming")
client.conversations().stream(ConversationCallback());
} catch (e: Exception) {
Expand Down
2 changes: 2 additions & 0 deletions bindings_ffi/gen_kotlin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ bindings_ffi/target/release/ffi-uniffi-bindgen generate \
$CRATE_NAME/src/$PROJECT_NAME.udl \
--language kotlin
popd > /dev/null
make libxmtp-version
cp libxmtp-version.txt src/uniffi/$PROJECT_NAME/
1 change: 1 addition & 0 deletions bindings_ffi/run_swift_local.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Assumes libxmtp is in a peer directory of libxmtp-swift
make swift
cp build/swift/xmtpv3.swift ../../libxmtp-swift/Sources/LibXMTP/xmtpv3.swift
cp build/swift/libxmtp-version.txt ../../libxmtp-swift/Sources/LibXMTP/libxmtp-version.txt
2 changes: 2 additions & 0 deletions bindings_ffi/setup_android_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ cp -r jniLibs $APP_PATH/app/src/main/

# Copy the .kt files to the example project
rm -f $APP_PATH/app/src/main/java/$PROJECT_NAME.kt
rm -f $APP_PATH/app/src/main/java/libxmtp-version.txt
cp src/uniffi/$PROJECT_NAME/$PROJECT_NAME.kt $APP_PATH/app/src/main/java/
cp src/uniffi/$PROJECT_NAME/libxmtp-version.txt $APP_PATH/app/src/main/java/

# Copy MainActivity.kt and ExampleInstrumentedTest.kt to the example project (comment this out if copying to a different app)
rm -f $APP_PATH/app/src/main/java/com/example/xmtpv3_example/MainActivity.kt
Expand Down
15 changes: 15 additions & 0 deletions bindings_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ fn stringify_error_chain<T: Error>(error: &T) -> String {

result
}

#[uniffi::export]
pub fn get_version_info() -> String {
include_str!("../libxmtp-version.txt").to_string()
}

#[cfg(test)]
mod tests {
use crate::get_version_info;

#[test]
pub fn test_get_version_info() {
print!("{}", get_version_info());
}
}

0 comments on commit 42c3630

Please sign in to comment.