Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Add builds & dynamic loading for four targets #67

Merged
merged 33 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
14742d3
Add GitHub Workflow
KendallWeihe Jul 4, 2024
3876668
Reduce upload to solely the dylib
KendallWeihe Jul 4, 2024
cbca333
Adjust runs-on to match expected arch
KendallWeihe Jul 4, 2024
dca9eb0
Build dylib for both mac architectures
KendallWeihe Jul 4, 2024
85c8503
Make local dev experience identical to prior, but compatible w/ multi…
KendallWeihe Jul 4, 2024
f81c572
Remove fix-load script
KendallWeihe Jul 5, 2024
4665ece
Fix dylib filename
KendallWeihe Jul 5, 2024
c0c7a8c
Add openssl dependency
KendallWeihe Jul 5, 2024
74149a6
Latest dylib's
KendallWeihe Jul 5, 2024
7271683
Begin MultiArchitecture
KendallWeihe Jul 5, 2024
b24ac3a
Remove MultiArchitecture approach, add SystemArchitecture.set()
KendallWeihe Jul 5, 2024
c63e516
Add linux builds
KendallWeihe Jul 5, 2024
980915b
Add log statements in example PFI
KendallWeihe Jul 5, 2024
6bf2a07
Add linux targets
KendallWeihe Jul 5, 2024
b28ba5c
Add linux support in SystemArchitecture.set(), add Dockerfile's in ex…
KendallWeihe Jul 5, 2024
c2bef35
Add debug logging to SystemArchitecture.set()
KendallWeihe Jul 5, 2024
ab76ba7
Add libgcc to alpine dockerfile, add dbg log prefix
KendallWeihe Jul 5, 2024
5d7f7dc
Remove tmp/
KendallWeihe Jul 5, 2024
d096977
Fix branch triggers
KendallWeihe Jul 5, 2024
7ed41b6
Fix workflow title
KendallWeihe Jul 5, 2024
d2aad1a
Consolidate workflow to run-on macos-latest
KendallWeihe Jul 5, 2024
777e2bb
Fix upload names
KendallWeihe Jul 5, 2024
9083cb5
Fix title, branch trigger, and aarch64 path
KendallWeihe Jul 5, 2024
063cc3b
Fix alpine build
KendallWeihe Jul 5, 2024
5451648
Move build to bindings/tbdex_uniff/libtargets and update workflow
KendallWeihe Jul 6, 2024
66cb509
Fix linux builds
KendallWeihe Jul 6, 2024
b783268
Add load test and workflow
KendallWeihe Jul 6, 2024
499d82c
Fix directory
KendallWeihe Jul 6, 2024
9c712c5
Fix alpine, remove ubuntu
KendallWeihe Jul 6, 2024
d7f1f95
Add ubuntu test
KendallWeihe Jul 7, 2024
b6b4216
Removed unnecessary test names
KendallWeihe Jul 7, 2024
39b027e
Optional RFQ private data, latest web5 (#68)
KendallWeihe Jul 8, 2024
9ce5e58
Update to latest web5
KendallWeihe Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/bound-kt-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Kotlin CI

on:
push:
branches:
- main
pull_request:

jobs:
aarch64-apple-darwin:
runs-on: macos-latest
name: Load shared library on aarch64-apple-darwin target
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- name: Run tests
run: |
cd bound/kt
mvn '-Dtest=SystemArchitectureTest#can load shared library' test

x86_64-apple-darwin:
runs-on: macos-12
name: Load shared library on x86_64-apple-darwin target
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- name: Run tests
run: |
cd bound/kt
mvn '-Dtest=SystemArchitectureTest#can load shared library' test

x86_64-unknown-linux-gnu:
runs-on: ubuntu-latest
name: Load shared library on x86_64-unknown-linux-gnu target
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- name: Run tests
run: |
cd bound/kt
mvn '-Dtest=SystemArchitectureTest#can load shared library' test

x86_64-unknown-linux-musl:
runs-on: ubuntu-latest
container:
image: alpine:latest
name: Load shared library on x86_64-unknown-linux-musl target
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
apk update
apk add openjdk11
apk add maven
apk add bash
- name: Set JAVA_HOME
run: |
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
export PATH=$JAVA_HOME/bin:$PATH
- name: Change directory to bound/kt and run tests
run: |
cd bound/kt
mvn '-Dtest=SystemArchitectureTest#can load shared library' test
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ license-file = "LICENSE"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.50"
web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "ede4a64286cfaa3c4b5fcad71445c319488b892a" }
web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "76adcba82bc2547f09cb70435b5528b7b64090bd" }
13 changes: 7 additions & 6 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ setup:
#!/bin/bash
if [[ "$(cargo 2>&1)" == *"rustup could not choose a version of cargo to run"* ]]; then
rustup default 1.78.0
rustup target add aarch64-apple-darwin
fi

# Build a release variant
Expand All @@ -26,12 +27,12 @@ bind: setup
just bind-kotlin

bind-kotlin: setup
cargo build --release --package tbdex_uniffi
cargo run --package tbdex_uniffi \
cargo build --release --package tbdex_uniffi --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/libtbdex_uniffi.dylib \
bound/kt/src/main/resources/libtbdex_uniffi_aarch64_apple_darwin.dylib
cargo run --release --package tbdex_uniffi \
--bin uniffi-bindgen \
generate --library target/release/libtbdex_uniffi.dylib \
generate --library bound/kt/src/main/resources/libtbdex_uniffi_aarch64_apple_darwin.dylib \
--language kotlin \
--out-dir target/bindgen-kotlin
cp target/release/libtbdex_uniffi.dylib bound/kt/src/main/resources/natives
cp target/bindgen-kotlin/tbdex/sdk/rust/tbdex.kt bound/kt/src/main/kotlin/tbdex/sdk/rust
cd bound/kt && ./fix-load.sh
cp target/bindgen-kotlin/tbdex/sdk/rust/tbdex.kt bound/kt/src/main/kotlin/tbdex/sdk/rust/UniFFI.kt
11 changes: 10 additions & 1 deletion bindings/tbdex_uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ tbdex = { path = "../../crates/tbdex" }
thiserror = { workspace = true }
uniffi = { version = "0.27.1", features = ["cli"] }
web5 = { workspace = true }
web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "ede4a64286cfaa3c4b5fcad71445c319488b892a" }
web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "76adcba82bc2547f09cb70435b5528b7b64090bd" }

[dependencies.openssl]
version = "0.10"
optional = true
features = ["vendored"]

[features]
default = []
x86_64_apple_darwin = ["openssl"]

[build-dependencies]
uniffi = { version = "0.27.1", features = ["build"] }
Expand Down
14 changes: 14 additions & 0 deletions bindings/tbdex_uniffi/libtargets/aarch64_apple_darwin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

REPO_DIR=../../../../

rustup target add aarch64-apple-darwin

(
cd $REPO_DIR;
cargo build --target aarch64-apple-darwin --release --package tbdex_uniffi;
cp target/aarch64-apple-darwin/release/libtbdex_uniffi.dylib \
bound/kt/src/main/resources/libtbdex_uniffi_aarch64_apple_darwin.dylib
)
16 changes: 16 additions & 0 deletions bindings/tbdex_uniffi/libtargets/x86_64_apple_darwin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

REPO_DIR=../../../../

rustup target add x86_64-apple-darwin

(
cd $REPO_DIR;
cargo build --target x86_64-apple-darwin --release \
--package tbdex_uniffi \
--features x86_64_apple_darwin;
cp target/x86_64-apple-darwin/release/libtbdex_uniffi.dylib \
bound/kt/src/main/resources/libtbdex_uniffi_x86_64_apple_darwin.dylib
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM --platform=linux/amd64 ubuntu:22.04

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
build-essential \
libssl-dev \
pkg-config

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Copy the source code to the container
WORKDIR /usr/src/myapp
COPY Cargo.toml ./
COPY bindings/tbdex_uniffi ./bindings/tbdex_uniffi
COPY crates/pfi_exemplar_integration_test ./crates/pfi_exemplar_integration_test
COPY crates/tbdex ./crates/tbdex

# Execute the build
RUN cargo build --release --package tbdex_uniffi

# Set the entrypoint, so that we can `docker cp` the build output
CMD tail -f /dev/null
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Known system dependencies

> [!NOTE]
>
> If we decide to bundle all transitive dependencies into the shared library, then these are the set of dependencies for which we need to include.

```shell
root@237b102e4327:/usr/src/myapp# ldd target/release/libtbdex_uniffi.so
libssl.so.3 => /lib/x86_64-linux-gnu/libssl.so.3 (0x00007ffffee3c000)
libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007ffffe9f8000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ffffe9d8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffffe8f1000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffffe6c8000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffffffc4000)
```
17 changes: 17 additions & 0 deletions bindings/tbdex_uniffi/libtargets/x86_64_unknown_linux_gnu/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

REPO_DIR=../../../../
IMAGE_NAME=tbdex_uniffi_x86_64-unknown-linux-gnu_image
CONTAINER_NAME=tbdex_uniffi_x86_64-unknown-linux-gnu_container

docker build -f $(pwd)/Dockerfile -t $IMAGE_NAME $REPO_DIR

docker run -d --name $CONTAINER_NAME $IMAGE_NAME

docker cp $CONTAINER_NAME:/usr/src/myapp/target/release/libtbdex_uniffi.so \
$REPO_DIR/bound/kt/src/main/resources/libtbdex_uniffi_x86_64_unknown_linux_gnu.so

docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM --platform=linux/amd64 alpine:latest

# Install system dependencies
RUN apk add --no-cache \
build-base \
musl-dev \
openssl-dev \
linux-headers \
rustup \
libgcc \
libstdc++ \
curl \
git \
openssl-libs-static

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Copy the source code to the container
WORKDIR /usr/src/myapp
COPY Cargo.toml ./
COPY bindings/tbdex_uniffi ./bindings/tbdex_uniffi
COPY crates/pfi_exemplar_integration_test ./crates/pfi_exemplar_integration_test
COPY crates/tbdex ./crates/tbdex

# Build the static lib (override the lib type)
RUN sed -i 's/crate-type = \["cdylib"\]/crate-type = \["staticlib"\]/' bindings/tbdex_uniffi/Cargo.toml
RUN cargo build --release --package tbdex_uniffi

# Compile as a dynamic lib (.so) from our static lib (.a) while keeping dependencies self-contained
RUN gcc -shared -o target/release/libtbdex_uniffi.so -Wl,--whole-archive \
target/release/libtbdex_uniffi.a -Wl,--no-whole-archive -static-libgcc \
-Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -fPIC

# Set the entrypoint, so that we can `docker cp` the build output
CMD tail -f /dev/null
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Known system dependencies

> [!NOTE]
>
> To build as a dynamic library, disable static linking.
>
> `RUSTFLAGS="-C target-feature=-crt-s
tatic" cargo build --release --package tbdex_uniffi`

> [!NOTE]
>
> If we decide to dynamically install system dependencies using a maven feature, then these are the list of dependencies we will need to ensure are installed.

```shell
/usr/src/myapp # ldd target/release/libtbdex_uniffi.so
/lib/ld-musl-x86_64.so.1 (0x7ffffff5d000)
libssl.so.3 => /lib/libssl.so.3 (0x7ffffedbd000)
libcrypto.so.3 => /lib/libcrypto.so.3 (0x7ffffe975000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7ffffe951000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7ffffff5d000)
```
17 changes: 17 additions & 0 deletions bindings/tbdex_uniffi/libtargets/x86_64_unknown_linux_musl/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

REPO_DIR=../../../../
IMAGE_NAME=tbdex_uniffi_x86_64-unknown-linux-musl_image
CONTAINER_NAME=tbdex_uniffi_x86_64-unknown-linux-musl_container

docker build -f $(pwd)/Dockerfile -t $IMAGE_NAME $REPO_DIR

docker run -d --name $CONTAINER_NAME $IMAGE_NAME

docker cp $CONTAINER_NAME:/usr/src/myapp/target/release/libtbdex_uniffi.so \
$REPO_DIR/bound/kt/src/main/resources/libtbdex_uniffi_x86_64_unknown_linux_musl.so

docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
8 changes: 6 additions & 2 deletions bindings/tbdex_uniffi/src/messages/rfq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ impl Rfq {
.read()
.map_err(|e| RustCoreError::from_poison_error(e, "RwLockReadError"))?;
let json_serialized_data = serde_json::to_string(&inner_rfq.data.clone())?;
let json_serialized_private_data = serde_json::to_string(&inner_rfq.private_data.clone())?;
let json_serialized_private_data = if let Some(private_data) = &inner_rfq.private_data {
Some(serde_json::to_string(private_data)?)
} else {
None
};
Ok(data::Rfq {
metadata: inner_rfq.metadata.clone(),
json_serialized_data,
Expand Down Expand Up @@ -108,7 +112,7 @@ pub mod data {
pub struct Rfq {
pub metadata: MessageMetadata,
pub json_serialized_data: String,
pub json_serialized_private_data: String,
pub json_serialized_private_data: Option<String>,
pub signature: String,
}
}
4 changes: 2 additions & 2 deletions bindings/tbdex_uniffi/src/tbdex.udl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ interface Rfq {
dictionary RfqData {
MessageMetadataData metadata;
string json_serialized_data;
string json_serialized_private_data;
string? json_serialized_private_data;
string signature;
};

Expand Down Expand Up @@ -248,7 +248,7 @@ interface CreateExchangeRequestBody {


dictionary JwkData {
string alg;
string? alg;
string kty;
string crv;
string? d;
Expand Down
18 changes: 0 additions & 18 deletions bound/kt/fix-load.sh

This file was deleted.

Loading
Loading