Skip to content

Commit

Permalink
Proposal: Move languages to live under the relevant crate (#26)
Browse files Browse the repository at this point in the history
Now that we've split the internal from public sdk we can clean up the
languages directory by moving the remaining language bindings to live
under the relevant crate that produces them.

This should ideally result in less jumping around in the terminal and
editors to go between output and code that produces it.
  • Loading branch information
Hinton authored Nov 12, 2024
1 parent eee1b54 commit 1b10d83
Show file tree
Hide file tree
Showing 82 changed files with 69 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8

- name: Move artifacts
working-directory: languages/kotlin/sdk/src/main/jniLibs
working-directory: crates/bitwarden-uniffi/kotlin/sdk/src/main/jniLibs
run: |
mkdir armeabi-v7a arm64-v8a x86 x86_64
mv /home/runner/work/sdk-internal/sdk-internal/android-armv7-linux-androideabi/libbitwarden_uniffi.so ./armeabi-v7a/libbitwarden_uniffi.so
Expand All @@ -97,14 +97,14 @@ jobs:
mv /home/runner/work/sdk-internal/sdk-internal/android-x86_64-linux-android/libbitwarden_uniffi.so ./x86_64/libbitwarden_uniffi.so
- name: Generate bindings
working-directory: languages/kotlin
working-directory: crates/bitwarden-uniffi/kotlin
run: ./build-schemas.sh

- name: Setup gradle
uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0

- name: Publish
run: ./gradlew sdk:publish
working-directory: languages/kotlin
working-directory: crates/bitwarden-uniffi/kotlin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/build-swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Build
shell: bash
working-directory: languages/swift
working-directory: crates/bitwarden-uniffi/swift
id: build
run: |
./build.sh
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Zip BitwardenFFI.xcframework
run: |
mkdir artifacts
cp -rf languages/swift/BitwardenFFI.xcframework artifacts
cp -rf crates/bitwarden-uniffi/swift/BitwardenFFI.xcframework artifacts
- name: Upload BitwardenFFI.xcframework artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand All @@ -76,7 +76,7 @@ jobs:
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: BitwardenSdk-${{ env._VERSION }}-${{ steps.build.outputs.short-sha }}-sources
path: languages/swift/Sources/BitwardenSdk
path: crates/bitwarden-uniffi/swift/Sources/BitwardenSdk
if-no-files-found: error

trigger-swift-release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wasm-internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: sdk-internal
path: ${{ github.workspace }}/languages/js/sdk-internal/*
path: ${{ github.workspace }}/crates/bitwarden-wasm-internal/npm/*
if-no-files-found: error

trigger-wasm-publish:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-wasm-internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:

defaults:
run:
working-directory: languages/js/sdk-internal
working-directory: crates/bitwarden-wasm-internal/npm

jobs:
setup:
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: sdk-internal
path: languages/js/sdk-internal
path: crates/bitwarden-wasm-internal/npm

- name: Set version
run: |
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release-swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:
workflow_conclusion: success
artifacts: "BitwardenSdk-${{ env._PKG_VERSION }}-${{ needs.validate.outputs.short_sha }}-sources"
run_id: ${{ env._BUILD_RUN_ID }}
path: sdk/languages/swift/Sources/BitwardenSdk
path: sdk/crates/bitwarden-uniffi/swift/Sources/BitwardenSdk

- name: Install Swift formatter
run: |
Expand All @@ -186,21 +186,21 @@ jobs:
sed -i 's|.binaryTarget(name: "BitwardenFFI", path: "BitwardenFFI.xcframework")|.binaryTarget(\
name: "BitwardenFFI",\
url: "https://github.com/bitwarden/sdk-swift/releases/download/v${{ env._RELEASE_NAME }}/BitwardenFFI-${{ env._PKG_VERSION }}-${{ needs.validate.outputs.short_sha }}.xcframework.zip",\
checksum: "${{ env._SWIFT_CHECKSUM }}" )|' sdk/languages/swift/Package.swift
checksum: "${{ env._SWIFT_CHECKSUM }}" )|' sdk/crates/bitwarden-uniffi/swift/Package.swift
# Run swiftformat
swiftformat sdk/languages/swift/Package.swift
swiftformat sdk/crates/bitwarden-uniffi/swift/Package.swift
find sdk/languages/swift/Sources/ -name ".gitignore" -exec rm -f {} \;
find sdk/crates/bitwarden-uniffi/swift/Sources/ -name ".gitignore" -exec rm -f {} \;
rm -rf sdk-swift/Sources
rm -rf sdk-swift/Tests
# Copy files to local sdk-swift repo path
cp --verbose -rf sdk/languages/swift/README.md sdk-swift/README.md
cp --verbose -rf sdk/languages/swift/Package.swift sdk-swift/Package.swift
cp --verbose -rf sdk/languages/swift/Sources sdk-swift
cp --verbose -rf sdk/languages/swift/Tests sdk-swift
cp --verbose -rf sdk/crates/bitwarden-uniffi/swift/README.md sdk-swift/README.md
cp --verbose -rf sdk/crates/bitwarden-uniffi/swift/Package.swift sdk-swift/Package.swift
cp --verbose -rf sdk/crates/bitwarden-uniffi/swift/Sources sdk-swift
cp --verbose -rf sdk/crates/bitwarden-uniffi/swift/Tests sdk-swift
- name: Push changes
working-directory: sdk-swift
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ jobs:
args: >
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.projectKey=${{ github.repository_owner }}_${{ github.event.repository.name }}
-Dsonar.exclusions=languages/**
-Dsonar.exclusions=crates/bitwarden-uniffi/kotlin/**,crates/bitwarden-uniffi/swift/**
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ node_modules/
THIRDPARTY.html

# Uniffi
languages/swift/BitwardenFFI.xcframework
languages/swift/tmp
languages/swift/.build
languages/swift/.swiftpm
languages/kotlin/sdk/src/main/java/com/bitwarden/**/*.kt
crates/bitwarden-uniffi/swift/BitwardenFFI.xcframework
crates/bitwarden-uniffi/swift/tmp
crates/bitwarden-uniffi/swift/.build
crates/bitwarden-uniffi/swift/.swiftpm
crates/bitwarden-uniffi/kotlin/sdk/src/main/java/com/bitwarden/**/*.kt
10 changes: 5 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
target
languages/*
!languages/js
languages/js/*
!languages/js/sdk-internal
languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm.js
schemas
about.hbs

# Language bindings
crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm.js
crates/bitwarden-uniffi/kotlin/*
crates/bitwarden-uniffi/swift/*

# Test fixtures
crates/bitwarden-exporters/resources/*
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ You can also browse the latest published documentation:
The project is structured as a monorepo using cargo workspaces. Some of the more noteworthy crates
are:

- [`bitwarden`](./crates/bitwarden/): Rust friendly API for interacting with the secrets manager.
- [`bitwarden-api-api`](./crates/bitwarden-api-api/): Auto-generated API bindings for the API
server.
- [`bitwarden-api-identity`](./crates/bitwarden-api-identity/): Auto-generated API bindings for the
Identity server.
- [`bitwarden-core`](./crates/bitwarden-core/): The core functionality consumed by the other crates.
- [`bitwarden-crypto`](./crates/bitwarden-crypto/): Crypto library.
- [`bitwarden-wasm-internal`](./crates/bitwarden-wasm-internal/): WASM bindings for the internal
SDK.
- [`bitwarden-uniffi`](./crates/bitwarden-uniffi/): Mobile bindings for swift and kotlin using
[UniFFI](https://github.com/mozilla/uniffi-rs/).

## API Bindings

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Note that the latest published version is very old, so we need to use a newer Gi
cargo install cross --locked --git https://github.com/cross-rs/cross.git --rev 185398b1b885820515a212de720a306b08e2c8c9
```

## Development

When building the Android SDK using Android Studio on MacOS you will need access to the local
`$PATH`, where cargo is installed. This can be done by starting Android Studio from the terminal.

```bash
open -a /Applications/Android\ Studio.app
```

## Building

Depending on which CPU architecture you will need to specify different targets. Please refer to the
Expand All @@ -18,16 +27,16 @@ Depending on which CPU architecture you will need to specify different targets.
mkdir -p ./sdk/src/main/jniLibs/{arm64-v8a,armeabi-v7a,x86_64,x86}

cross build -p bitwarden-uniffi --release --target=aarch64-linux-android
mv ../../target/aarch64-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/arm64-v8a/libbitwarden_uniffi.so
mv ../../../target/aarch64-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/arm64-v8a/libbitwarden_uniffi.so

cross build -p bitwarden-uniffi --release --target=armv7-linux-androideabi
mv ../../target/armv7-linux-androideabi/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/armeabi-v7a/libbitwarden_uniffi.so
mv ../../../target/armv7-linux-androideabi/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/armeabi-v7a/libbitwarden_uniffi.so

cross build -p bitwarden-uniffi --release --target=x86_64-linux-android
mv ../../target/x86_64-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/x86_64/libbitwarden_uniffi.so
mv ../../../target/x86_64-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/x86_64/libbitwarden_uniffi.so

cross build -p bitwarden-uniffi --release --target=i686-linux-android
mv ../../target/i686-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/x86/libbitwarden_uniffi.so
mv ../../../target/i686-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/x86/libbitwarden_uniffi.so
```

### Schemas
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import javax.net.ssl.X509TrustManager
*
* Note that this SDK uses the system trust store to perform TLS certificate validation. If you want to use this SDK with
* self hosted servers using self-signed certificates, make sure to configure the Android Network Security Config correctly.
* We provide an example configuration in `languages/kotlin/app/src/main/res/xml/network_security_config.xml`
* We provide an example configuration in `crates/bitwarden-uniffi/kotlin/app/src/main/res/xml/network_security_config.xml`
* https://developer.android.com/privacy-and-security/security-config
*/

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ publishing {
def branchName = 'git branch --show-current'.execute().text.trim()

if (branchName == 'main') {
def content = ['grep', '-o', '^version = ".*"', '../../Cargo.toml'].execute().text.trim()
def content = ['grep', '-o', '^version = ".*"', rootDir.toString() + '/../../../Cargo.toml'].execute().text.trim()
def match = ~/version = "(.*)"/
def matcher = match.matcher(content)
matcher.find()
Expand Down Expand Up @@ -94,7 +94,7 @@ publishing {
File findRustlsPlatformVerifierClassesJar() {
def dependencyText = providers.exec {
it.workingDir = new File('../../')
commandLine('cargo', 'metadata', '--format-version', '1', '--manifest-path', 'crates/bitwarden-uniffi/Cargo.toml')
commandLine('cargo', 'metadata', '--format-version', '1')
}.standardOutput.asText.get()

def dependencyJson = new groovy.json.JsonSlurper().parseText(dependencyText)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ cargo build --package bitwarden-uniffi --target aarch64-apple-ios --release
cargo build --package bitwarden-uniffi --target x86_64-apple-ios --release

# Create universal libraries
lipo -create ../../target/aarch64-apple-ios-sim/release/libbitwarden_uniffi.a \
../../target/x86_64-apple-ios/release/libbitwarden_uniffi.a \
lipo -create ../../../target/aarch64-apple-ios-sim/release/libbitwarden_uniffi.a \
../../../target/x86_64-apple-ios/release/libbitwarden_uniffi.a \
-output ./tmp/target/universal-ios-sim/release/libbitwarden_uniffi.a

# Generate swift bindings
cargo run -p uniffi-bindgen generate \
../../target/aarch64-apple-ios-sim/release/libbitwarden_uniffi.dylib \
../../../target/aarch64-apple-ios-sim/release/libbitwarden_uniffi.dylib \
--library \
--language swift \
--no-format \
Expand All @@ -37,7 +37,7 @@ cat ./tmp/bindings/*.modulemap > ./tmp/Headers/module.modulemap

# Build xcframework
xcodebuild -create-xcframework \
-library ../../target/aarch64-apple-ios/release/libbitwarden_uniffi.a \
-library ../../../target/aarch64-apple-ios/release/libbitwarden_uniffi.a \
-headers ./tmp/Headers \
-library ./tmp/target/universal-ios-sim/release/libbitwarden_uniffi.a \
-headers ./tmp/Headers \
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions crates/bitwarden-wasm-internal/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ cd ../../
if [ "$1" != "-r" ]; then
# Dev
cargo build -p bitwarden-wasm-internal --target wasm32-unknown-unknown
wasm-bindgen --target bundler --out-dir languages/js/sdk-internal ./target/wasm32-unknown-unknown/debug/bitwarden_wasm_internal.wasm
wasm-bindgen --target nodejs --out-dir languages/js/sdk-internal/node ./target/wasm32-unknown-unknown/debug/bitwarden_wasm_internal.wasm
wasm-bindgen --target bundler --out-dir crates/bitwarden-wasm-internal/npm ./target/wasm32-unknown-unknown/debug/bitwarden_wasm_internal.wasm
wasm-bindgen --target nodejs --out-dir crates/bitwarden-wasm-internal/npm/node ./target/wasm32-unknown-unknown/debug/bitwarden_wasm_internal.wasm
else
# Release
cargo build -p bitwarden-wasm-internal --target wasm32-unknown-unknown --release
wasm-bindgen --target bundler --out-dir languages/js/sdk-internal ./target/wasm32-unknown-unknown/release/bitwarden_wasm_internal.wasm
wasm-bindgen --target nodejs --out-dir languages/js/sdk-internal/node ./target/wasm32-unknown-unknown/release/bitwarden_wasm_internal.wasm
wasm-bindgen --target bundler --out-dir crates/bitwarden-wasm-internal/npm ./target/wasm32-unknown-unknown/release/bitwarden_wasm_internal.wasm
wasm-bindgen --target nodejs --out-dir crates/bitwarden-wasm-internal/npm/node ./target/wasm32-unknown-unknown/release/bitwarden_wasm_internal.wasm
fi

# Format
npx prettier --write ./languages/js/sdk-internal
npx prettier --write ./crates/bitwarden-wasm-internal/npm

# Optimize size
wasm-opt -Os ./languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm -o ./languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm
wasm-opt -Os ./crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm -o ./crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm

# Transpile to JS
wasm2js ./languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm -o ./languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm.js
npx terser ./languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm.js -o ./languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm.js
wasm2js ./crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm -o ./crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm.js
npx terser ./crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm.js -o ./crates/bitwarden-wasm-internal/npm/bitwarden_wasm_internal_bg.wasm.js
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

This file was deleted.

0 comments on commit 1b10d83

Please sign in to comment.