#!/bin/bash

#
# Copyright 2021 Signal Messenger, LLC.
# SPDX-License-Identifier: AGPL-3.0-only
#

# To keep code size down, we try to avoid depending on multiple versions of crates.
#
# Sometimes we decide it's okay for certain dependencies.
# You can use the `cargo tree` command below to see where they come from,
# and then document them here.
#
# jni: v0.19 is used by rustls-platform-verifier on Android, v0.21 by us
# pqcrypto-kyber: v0.7 is what we shipped PQXDH on, v0.8 contains the NIST standard version
EXPECTED="
jni v0.19.0
jni v0.21.1
pqcrypto-kyber v0.7.9
pqcrypto-kyber v0.8.1"

check_cargo_tree() {
    # Only check the mobile targets, where we care most about code size.
    cargo tree --quiet --duplicates --edges normal,no-proc-macro \
        --workspace --all-features --locked \
        --target aarch64-apple-ios \
        --target armv7-linux-androideabi \
        --target aarch64-linux-android \
        "$@"
}

if [[ "$(check_cargo_tree --depth 0 | sort -u -V)" != "${EXPECTED}" ]]; then
    check_cargo_tree
    exit 1
fi
