build-uniffi.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. function _print_usage() {
  4. echo "Usage: $0 [--no-container]"
  5. echo ""
  6. echo "Options:"
  7. echo " --no-container To not source the dev container environment."
  8. echo " -h,--help Print this help and exit."
  9. }
  10. while [[ "$#" -gt 0 ]]; do
  11. case $1 in
  12. -h | --help)
  13. _print_usage
  14. exit 0
  15. ;;
  16. --no-container)
  17. _no_container=1
  18. ;;
  19. *) echo "Unknown parameter passed: $1"; _print_usage; exit 1 ;;
  20. esac
  21. shift
  22. done
  23. # Clean and load dev container
  24. cd "$(dirname "$0")/.."
  25. [[ -d ./build/uniffi ]] && rm -r ./build/uniffi/
  26. if [[ -z ${_no_container+x} ]] ; then
  27. source ./.devcontainer/env.sh
  28. fi
  29. # Ensure consistent target dir, even if `build.target-dir` config option is set for Cargo
  30. export CARGO_TARGET_DIR=target
  31. # Build library
  32. cargo build --locked -F uniffi -p libthreema --release
  33. # Generate Kotlin bindings
  34. cargo run \
  35. --locked \
  36. -p uniffi-bindgen generate \
  37. --library ./target/release/liblibthreema.so \
  38. --language kotlin \
  39. --out-dir ./build/uniffi/kotlin
  40. # Generate Swift bindings
  41. cargo run \
  42. --locked \
  43. -p uniffi-bindgen generate \
  44. --library ./target/release/liblibthreema.so \
  45. --language swift \
  46. --out-dir ./build/uniffi/swift
  47. # Unload dev container if it was started
  48. if [[ -z ${_no_container+x} ]] ; then
  49. deactivate --only-if-started
  50. fi