# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

RUST_MIN_VER="1.82.0"
CRATES="
    addr2line@0.20.0
    adler2@2.0.0
    adler@1.0.2
    aead@0.5.2
    aes-gcm@0.10.2
    aes@0.8.4
    ahash@0.7.6
    aho-corasick@1.0.3
    alloc-no-stdlib@2.0.4
    alloc-stdlib@0.2.2
    anstream@0.6.4
    anstyle-parse@0.2.1
    anstyle-query@1.0.0
    anstyle-wincon@3.0.1
    anstyle@1.0.1
    anyhow@1.0.72
    argon2@0.5.1
    arrayref@0.3.7
    async-trait@0.1.83
    atk-sys@0.15.1
    atk@0.15.1
    atomic-waker@1.1.2
    attohttpc@0.22.0
    atty@0.2.14
    autocfg@1.1.0
    backtrace@0.3.68
    base16ct@0.2.0
    base64@0.13.1
    base64@0.21.4
    base64@0.22.1
    base64ct@1.6.0
    bincode@1.3.3
    bip32@0.5.2
    bip39@2.0.0
    bitcoin_hashes@0.11.0
    bitflags@1.3.2
    bitflags@2.4.0
    blake2@0.10.6
    blake2@0.8.1
    block-buffer@0.10.4
    block-buffer@0.9.0
    block@0.1.6
    bnum@0.8.1
    brotli-decompressor@2.3.4
    brotli@3.3.4
    bs58@0.5.1
    bstr@1.6.0
    bumpalo@3.13.0
    byte-tools@0.3.1
    bytemuck@1.13.1
    byteorder@1.5.0
    bytes@1.5.0
    cairo-rs@0.15.12
    cairo-sys-rs@0.15.1
    camino@1.1.7
    cargo-platform@0.1.8
    cargo_metadata@0.18.1
    cargo_toml@0.13.3
    cc@1.0.82
    celes@2.4.0
    cesu8@1.1.0
    cfb@0.6.1
    cfg-expr@0.15.4
    cfg-expr@0.9.1
    cfg-if@1.0.0
    chacha@0.3.0
    cipher@0.4.4
    clap@4.4.7
    clap_builder@4.4.7
    clap_derive@4.4.7
    clap_lex@0.6.0
    cocoa-foundation@0.1.1
    cocoa@0.24.1
    color_quant@1.1.0
    colorchoice@1.0.0
    colored@1.9.4
    colored@2.0.4
    combine@4.6.6
    const-oid@0.9.5
    const-str@0.5.6
    convert_case@0.4.0
    core-foundation-sys@0.8.4
    core-foundation@0.9.3
    core-graphics-types@0.1.2
    core-graphics@0.22.3
    cosmos-sdk-proto@0.20.0
    cosmrs@0.15.0
    cosmwasm-crypto@1.5.3
    cosmwasm-derive@1.5.3
    cosmwasm-schema-derive@1.4.3
    cosmwasm-schema@1.4.3
    cosmwasm-std@1.4.3
    cpufeatures@0.2.9
    crc32fast@1.3.2
    crossbeam-channel@0.5.8
    crossbeam-utils@0.8.16
    crypto-bigint@0.5.2
    crypto-common@0.1.6
    crypto-mac@0.7.0
    cssparser-macros@0.6.1
    cssparser@0.27.2
    ctor@0.1.26
    ctr@0.9.2
    curve25519-dalek-derive@0.1.0
    curve25519-dalek-ng@4.1.1
    curve25519-dalek@3.2.0
    curve25519-dalek@4.1.2
    cw-controllers@1.1.0
    cw-storage-plus@1.2.0
    cw-utils@1.0.1
    cw20@1.1.2
    cw2@1.1.2
    cw3@1.1.2
    cw4@1.1.2
    darling@0.13.4
    darling_core@0.13.4
    darling_macro@0.13.4
    der@0.7.8
    deranged@0.3.9
    derivative@2.2.0
    derive_more@0.99.17
    digest@0.10.7
    digest@0.8.1
    digest@0.9.0
    dirs-next@2.0.0
    dirs-sys-next@0.1.2
    dirs-sys@0.3.7
    dirs-sys@0.4.1
    dirs@4.0.0
    dirs@5.0.1
    dispatch@0.2.0
    dotenvy@0.15.7
    dtoa-short@0.3.4
    dtoa@1.0.9
    dunce@1.0.4
    dyn-clone@1.0.12
    ecdsa@0.16.8
    ed25519-consensus@2.1.0
    ed25519-dalek@2.1.1
    ed25519-zebra@3.1.0
    ed25519@2.2.2
    either@1.9.0
    elliptic-curve@0.13.5
    embed_plist@1.2.2
    encoding_rs@0.8.32
    env_logger@0.7.1
    equivalent@1.0.1
    errno-dragonfly@0.1.2
    errno@0.3.2
    eyre@0.6.12
    fastrand@2.0.0
    fdeflate@0.3.0
    fern@0.6.2
    ff@0.13.0
    fiat-crypto@0.2.1
    field-offset@0.3.6
    filetime@0.2.22
    flate2@1.0.34
    flex-error@0.4.4
    fnv@1.0.7
    foreign-types-shared@0.1.1
    foreign-types@0.3.2
    form_urlencoded@1.2.1
    forward_ref@1.0.0
    futf@0.1.5
    futures-channel@0.3.28
    futures-core@0.3.28
    futures-executor@0.3.28
    futures-io@0.3.28
    futures-macro@0.3.28
    futures-sink@0.3.28
    futures-task@0.3.28
    futures-util@0.3.28
    futures@0.3.28
    fxhash@0.2.1
    gdk-pixbuf-sys@0.15.10
    gdk-pixbuf@0.15.11
    gdk-sys@0.15.1
    gdk@0.15.4
    gdkx11-sys@0.15.1
    generator@0.7.5
    generic-array@0.12.4
    generic-array@0.14.7
    getrandom@0.1.16
    getrandom@0.2.10
    getset@0.1.3
    ghash@0.5.0
    gimli@0.27.3
    gio-sys@0.15.10
    gio@0.15.12
    glib-macros@0.15.13
    glib-sys@0.15.10
    glib@0.15.12
    glob@0.3.1
    globset@0.4.13
    gobject-sys@0.15.10
    group@0.13.0
    gtk-sys@0.15.3
    gtk3-macros@0.15.6
    gtk@0.15.5
    h2@0.3.20
    h2@0.4.5
    handlebars@3.5.5
    hashbrown@0.12.3
    hashbrown@0.14.5
    heck@0.3.3
    heck@0.4.1
    heck@0.5.0
    hermit-abi@0.1.19
    hermit-abi@0.3.9
    hex-literal@0.3.4
    hex@0.4.3
    hkdf@0.12.4
    hmac@0.12.1
    html5ever@0.25.2
    http-body-util@0.1.1
    http-body@0.4.5
    http-body@1.0.0
    http-range@0.1.5
    http@0.2.9
    http@1.1.0
    httparse@1.8.0
    httpdate@1.0.3
    humantime-serde@1.1.1
    humantime@1.3.0
    humantime@2.1.0
    hyper-rustls@0.24.2
    hyper-rustls@0.26.0
    hyper-tls@0.6.0
    hyper-util@0.1.3
    hyper@0.14.27
    hyper@1.3.1
    ico@0.2.0
    ident_case@1.0.1
    idna@0.5.0
    ignore@0.4.20
    image@0.24.7
    indenter@0.3.3
    indexmap@1.9.3
    indexmap@2.5.0
    infer@0.7.0
    inout@0.1.3
    instant@0.1.12
    ipnet@2.8.0
    is-terminal@0.4.9
    itertools@0.10.5
    itertools@0.11.0
    itertools@0.13.0
    itoa@0.4.8
    itoa@1.0.9
    javascriptcore-rs-sys@0.4.0
    javascriptcore-rs@0.16.0
    jni-sys@0.3.0
    jni@0.20.0
    js-sys@0.3.64
    json-patch@0.2.7
    k256@0.13.1
    keystream@1.0.0
    kuchiki@0.8.1
    lazy_static@1.4.0
    libc@0.2.151
    libm@0.2.7
    line-wrap@0.1.1
    linux-raw-sys@0.4.5
    lioness@0.1.2
    lock_api@0.4.10
    log@0.4.21
    loom@0.5.6
    mac@0.1.1
    malloc_buf@0.0.6
    markup5ever@0.10.1
    matchers@0.1.0
    matches@0.1.10
    memchr@2.5.0
    memoffset@0.9.0
    mime@0.3.17
    minisign-verify@0.2.1
    miniz_oxide@0.7.1
    miniz_oxide@0.8.0
    mio@1.0.1
    native-tls@0.2.11
    ndk-context@0.1.1
    ndk-sys@0.3.0
    ndk@0.6.0
    new_debug_unreachable@1.0.4
    nodrop@0.1.14
    nu-ansi-term@0.46.0
    num-conv@0.1.0
    num-derive@0.3.3
    num-integer@0.1.45
    num-rational@0.4.1
    num-traits@0.2.16
    num_enum@0.5.11
    num_enum_derive@0.5.11
    num_threads@0.1.6
    objc-foundation@0.1.1
    objc@0.2.7
    objc_exception@0.1.2
    objc_id@0.1.1
    object@0.31.1
    once_cell@1.18.0
    opaque-debug@0.2.3
    opaque-debug@0.3.0
    open@3.2.0
    openssl-macros@0.1.1
    openssl-probe@0.1.5
    openssl-sys@0.9.91
    openssl@0.10.56
    option-ext@0.2.0
    overload@0.1.1
    pairing@0.23.0
    pango-sys@0.15.10
    pango@0.15.10
    parking_lot@0.12.1
    parking_lot_core@0.9.8
    password-hash@0.5.0
    paste@1.0.14
    pathdiff@0.2.1
    peg-macros@0.8.4
    peg-runtime@0.8.3
    peg@0.8.4
    pem@0.8.3
    percent-encoding@2.3.1
    pest@2.7.2
    pest_derive@2.7.2
    pest_generator@2.7.2
    pest_meta@2.7.2
    phf@0.10.1
    phf@0.8.0
    phf_codegen@0.8.0
    phf_generator@0.10.0
    phf_generator@0.8.0
    phf_macros@0.10.0
    phf_macros@0.8.0
    phf_shared@0.10.0
    phf_shared@0.8.0
    pin-project-internal@1.1.3
    pin-project-lite@0.2.12
    pin-project@1.1.3
    pin-utils@0.1.0
    pkcs8@0.10.2
    pkg-config@0.3.27
    platforms@3.1.2
    plist@1.5.0
    png@0.17.9
    polyval@0.6.1
    powerfmt@0.2.0
    ppv-lite86@0.2.17
    precomputed-hash@0.1.1
    pretty_env_logger@0.4.0
    proc-macro-crate@1.3.1
    proc-macro-error-attr2@2.0.0
    proc-macro-error-attr@1.0.4
    proc-macro-error2@2.0.1
    proc-macro-error@1.0.4
    proc-macro-hack@0.5.20+deprecated
    proc-macro2@1.0.89
    prost-derive@0.12.3
    prost-types@0.12.3
    prost@0.12.3
    quick-error@1.2.3
    quick-error@2.0.1
    quick-xml@0.29.0
    quote@1.0.35
    rand@0.7.3
    rand@0.8.5
    rand_chacha@0.2.2
    rand_chacha@0.3.1
    rand_core@0.5.1
    rand_core@0.6.4
    rand_distr@0.4.3
    rand_hc@0.2.0
    rand_pcg@0.2.1
    raw-window-handle@0.5.2
    redox_syscall@0.2.16
    redox_syscall@0.3.5
    redox_users@0.4.3
    regex-automata@0.1.10
    regex-automata@0.3.6
    regex-syntax@0.6.29
    regex-syntax@0.7.4
    regex@1.9.3
    reqwest@0.11.22
    reqwest@0.12.4
    rfc6979@0.4.0
    rfd@0.10.0
    ring@0.17.3
    ripemd@0.1.3
    rustc-demangle@0.1.23
    rustc_version@0.4.0
    rustix@0.38.8
    rustls-native-certs@0.6.3
    rustls-pemfile@1.0.4
    rustls-pemfile@2.1.2
    rustls-pki-types@1.7.0
    rustls-webpki@0.101.7
    rustls-webpki@0.102.4
    rustls@0.21.9
    rustls@0.22.4
    rustversion@1.0.14
    ryu@1.0.15
    safemem@0.3.3
    same-file@1.0.6
    schannel@0.1.22
    schemars@0.8.21
    schemars_derive@0.8.21
    scoped-tls@1.0.1
    scopeguard@1.2.0
    sct@0.7.1
    sec1@0.7.3
    security-framework-sys@2.9.1
    security-framework@2.9.2
    selectors@0.22.0
    semver@1.0.23
    serde-json-wasm@0.5.0
    serde@1.0.214
    serde_bytes@0.11.15
    serde_derive@1.0.214
    serde_derive_internals@0.29.1
    serde_json@1.0.132
    serde_repr@0.1.16
    serde_spanned@0.6.7
    serde_urlencoded@0.7.1
    serde_with@1.14.0
    serde_with_macros@1.5.2
    serdect@0.2.0
    serdect@0.3.0-pre.0
    serialize-to-javascript-impl@0.1.1
    serialize-to-javascript@0.1.1
    servo_arc@0.1.1
    sha2@0.10.8
    sha2@0.9.9
    sharded-slab@0.1.4
    signal-hook-registry@1.4.1
    signature@2.1.0
    simd-adler32@0.3.7
    siphasher@0.3.10
    slab@0.4.8
    smallvec@1.13.2
    socket2@0.4.9
    socket2@0.5.5
    soup2-sys@0.2.0
    soup2@0.2.1
    sphinx-packet@0.1.1
    spin@0.9.8
    spki@0.7.2
    stable_deref_trait@1.2.0
    state@0.5.3
    string_cache@0.8.7
    string_cache_codegen@0.5.2
    strsim@0.10.0
    strum@0.23.0
    strum@0.26.3
    strum_macros@0.23.1
    strum_macros@0.26.4
    subtle-encoding@0.5.1
    subtle-ng@2.5.0
    subtle@1.0.0
    subtle@2.5.0
    syn@1.0.109
    syn@2.0.85
    sync_wrapper@0.1.2
    system-configuration-sys@0.5.0
    system-configuration@0.5.1
    system-deps@5.0.0
    system-deps@6.1.1
    tao@0.15.8
    tap@1.0.1
    tar@0.4.40
    target-lexicon@0.12.11
    tauri-build@1.2.1
    tauri-codegen@1.2.1
    tauri-macros@1.2.1
    tauri-runtime-wry@0.12.2
    tauri-runtime@0.12.1
    tauri-utils@1.2.1
    tauri@1.2.3
    tempfile@3.7.1
    tendermint-config@0.37.0
    tendermint-proto@0.34.0
    tendermint-proto@0.37.0
    tendermint-rpc@0.37.0
    tendermint@0.34.0
    tendermint@0.37.0
    tendril@0.4.3
    termcolor@1.2.0
    thin-slice@0.1.1
    thiserror-impl@1.0.64
    thiserror@1.0.64
    thread_local@1.1.7
    time-core@0.1.2
    time-macros@0.2.18
    time@0.3.36
    tinyvec@1.6.0
    tinyvec_macros@0.1.1
    tokio-macros@2.4.0
    tokio-native-tls@0.3.1
    tokio-rustls@0.24.1
    tokio-rustls@0.25.0
    tokio-util@0.7.8
    tokio@1.39.2
    toml@0.5.11
    toml@0.7.6
    toml@0.8.19
    toml_datetime@0.6.8
    toml_edit@0.19.14
    toml_edit@0.22.22
    tower-layer@0.3.2
    tower-service@0.3.2
    tower@0.4.13
    tracing-attributes@0.1.26
    tracing-core@0.1.31
    tracing-log@0.1.3
    tracing-subscriber@0.3.17
    tracing@0.1.37
    treediff@3.0.2
    try-lock@0.2.4
    ts-rs-macros@10.0.0
    ts-rs@10.0.0
    typenum@1.16.0
    ucd-trie@0.1.6
    unicode-bidi@0.3.13
    unicode-ident@1.0.11
    unicode-normalization@0.1.22
    unicode-segmentation@1.10.1
    universal-hash@0.5.1
    untrusted@0.9.0
    url@2.5.2
    utf-8@0.7.6
    utf8parse@0.2.1
    utoipa-gen@4.3.0
    utoipa@4.2.3
    uuid@0.8.2
    uuid@1.10.0
    valuable@0.1.0
    vcpkg@0.2.15
    vergen@8.3.1
    version-compare@0.0.11
    version-compare@0.1.1
    version_check@0.9.4
    walkdir@2.3.3
    want@0.3.1
    wasi@0.11.0+wasi-snapshot-preview1
    wasi@0.9.0+wasi-snapshot-preview1
    wasm-bindgen-backend@0.2.87
    wasm-bindgen-futures@0.4.37
    wasm-bindgen-macro-support@0.2.87
    wasm-bindgen-macro@0.2.87
    wasm-bindgen-shared@0.2.87
    wasm-bindgen@0.2.87
    wasmtimer@0.2.0
    web-sys@0.3.64
    webkit2gtk-sys@0.18.0
    webkit2gtk@0.18.2
    webpki-roots@0.26.1
    webview2-com-macros@0.6.0
    webview2-com-sys@0.19.0
    webview2-com@0.19.1
    winapi-i686-pc-windows-gnu@0.4.0
    winapi-util@0.1.5
    winapi-x86_64-pc-windows-gnu@0.4.0
    winapi@0.3.9
    windows-bindgen@0.39.0
    windows-implement@0.39.0
    windows-metadata@0.39.0
    windows-sys@0.42.0
    windows-sys@0.48.0
    windows-sys@0.52.0
    windows-targets@0.48.1
    windows-targets@0.52.6
    windows-tokens@0.39.0
    windows@0.37.0
    windows@0.39.0
    windows@0.48.0
    windows_aarch64_gnullvm@0.42.2
    windows_aarch64_gnullvm@0.48.0
    windows_aarch64_gnullvm@0.52.6
    windows_aarch64_msvc@0.37.0
    windows_aarch64_msvc@0.39.0
    windows_aarch64_msvc@0.42.2
    windows_aarch64_msvc@0.48.0
    windows_aarch64_msvc@0.52.6
    windows_i686_gnu@0.37.0
    windows_i686_gnu@0.39.0
    windows_i686_gnu@0.42.2
    windows_i686_gnu@0.48.0
    windows_i686_gnu@0.52.6
    windows_i686_gnullvm@0.52.6
    windows_i686_msvc@0.37.0
    windows_i686_msvc@0.39.0
    windows_i686_msvc@0.42.2
    windows_i686_msvc@0.48.0
    windows_i686_msvc@0.52.6
    windows_x86_64_gnu@0.37.0
    windows_x86_64_gnu@0.39.0
    windows_x86_64_gnu@0.42.2
    windows_x86_64_gnu@0.48.0
    windows_x86_64_gnu@0.52.6
    windows_x86_64_gnullvm@0.42.2
    windows_x86_64_gnullvm@0.48.0
    windows_x86_64_gnullvm@0.52.6
    windows_x86_64_msvc@0.37.0
    windows_x86_64_msvc@0.39.0
    windows_x86_64_msvc@0.42.2
    windows_x86_64_msvc@0.48.0
    windows_x86_64_msvc@0.52.6
    winnow@0.5.10
    winnow@0.6.19
    winreg@0.50.0
    winreg@0.52.0
    winres@0.1.12
    wry@0.23.4
    x11-dl@2.21.0
    x11@2.21.0
    x25519-dalek@2.0.0
    xattr@1.0.1
    zeroize@1.6.0
    zeroize_derive@1.4.2
    zip@0.6.6
"

declare -A GIT_CRATES=(
    [bls12_381]='https://github.com/jstuczyn/bls12_381;22cd0a16b674af1629110a2dc8b6cf6c73ea4cd9;bls12_381-%commit%'
    [cosmos-sdk-proto]='https://github.com/cosmos/cosmos-rust;4b1332e6d8258ac845cef71589c8d362a669675a;cosmos-rust-%commit%/cosmos-sdk-proto'
    [cosmrs]='https://github.com/cosmos/cosmos-rust;4b1332e6d8258ac845cef71589c8d362a669675a;cosmos-rust-%commit%/cosmrs'
)

inherit cargo desktop xdg

DESCRIPTION="NYM(VPN) is a privacy platform providing strong network-level privacy."
HOMEPAGE="https://nymtech.net"
SRC_URI="
    https://github.com/nymtech/nym/archive/refs/tags/${PN}-v${PV}.tar.gz
    https://vendors.simple-co.de/${CATEGORY}/${PN}/${P}-vendor.tar.xz
    ${CARGO_CRATE_URIS}
"

SLOT="0"
KEYWORDS="~amd64"
LICENSE="GPL-3 Apache-2.0 BSD-2 BSD CC0-1.0 ISC MIT MPL-2.0 Unicode-DFS-2016 ZLIB"

# TODO
RESTICT="tests"

DEPEND="
    sys-apps/yarn
    net-libs/webkit-gtk:4
"

src_prepare() {
    default

    # don't asked - they messed up their packages
    cp -a "${WORKDIR}/nym-${PN}-v${PV}"/* "${S}"

    # patching proklen rendering (under wayland at least)
    eapply "${FILESDIR}/${P}_disable-webkit-compositing.patch"

    # do NOT bundle anything!
    sed -ri 's/"targets": .+,/"targets": ["app"],/' ${S}/${PN}/src-tauri/tauri.conf.json

    cargo_gen_config
    rust_pkg_setup
}

src_compile() {    
    cd ${S}/${PN}
    CYPRESS_INSTALL_BINARY=0 yarn build || die
}

src_install() {
    insinto /usr/bin
    dobin ${S}/${PN}/target/release/${PN}

    # desktop entry
    newicon -s 32 ${S}/${PN}/src-tauri/icons/32x32.png ${PN}.png
    newicon -s 128 ${S}/${PN}/src-tauri/icons/128x128.png ${PN}.png

    make_desktop_entry ${PN} "NYM Wallet" ${PN} "Utility"

    # docs
    dodoc ${S}/${PN}/README.md
}

pkg_postrm() {
    xdg_pkg_postrm
}

pkg_postinst() {
    xdg_pkg_postinst
}