load("@rules_erlang//:erlang_bytecode2.bzl", "erlang_bytecode", "erlc_opts")
load("@rules_erlang//:erlang_app.bzl", "erlang_app")

erlc_opts(
    name = "erlc_opts",
    values = select({
        "@rules_erlang//:debug_build": [
            "+debug_info",
            "+warnings_as_errors",
        ],
        "//conditions:default": [
            "+debug_info",
            "+deterministic",
            "+warnings_as_errors",
        ],
    }),
    visibility = [":__subpackages__"],
)

erlang_bytecode(
    name = "parse_transforms",
    srcs = ["src/base/jose_base.erl"],
    outs = ["ebin/jose_base.beam"],
    hdrs = [
        "include/jose.hrl",
        "include/jose_base.hrl",
        "include/jose_compat.hrl",
        "include/jose_jwe.hrl",
        "include/jose_jwk.hrl",
        "include/jose_jws.hrl",
        "include/jose_jwt.hrl",
        "include/jose_public_key.hrl",
    ],
    app_name = "jose",
    erlc_opts = "//:erlc_opts",
)

erlang_bytecode(
    name = "behaviours",
    srcs = [
        "src/jose_block_encryptor.erl",
        "src/jose_chacha20_poly1305.erl",
        "src/jose_curve25519.erl",
        "src/jose_curve448.erl",
        "src/jose_sha3.erl",
        "src/jose_xchacha20_poly1305.erl",
        "src/json/jose_json.erl",
        "src/jwe/jose_jwe.erl",
        "src/jwe/jose_jwe_alg.erl",
        "src/jwe/jose_jwe_enc.erl",
        "src/jwk/jose_jwk.erl",
        "src/jwk/jose_jwk_kty.erl",
        "src/jwk/jose_jwk_oct.erl",
        "src/jwk/jose_jwk_use_enc.erl",
        "src/jwk/jose_jwk_use_sig.erl",
        "src/jws/jose_jws.erl",
        "src/jws/jose_jws_alg.erl",
    ],
    outs = [
        "ebin/jose_block_encryptor.beam",
        "ebin/jose_chacha20_poly1305.beam",
        "ebin/jose_curve25519.beam",
        "ebin/jose_curve448.beam",
        "ebin/jose_json.beam",
        "ebin/jose_jwe.beam",
        "ebin/jose_jwe_alg.beam",
        "ebin/jose_jwe_enc.beam",
        "ebin/jose_jwk.beam",
        "ebin/jose_jwk_kty.beam",
        "ebin/jose_jwk_oct.beam",
        "ebin/jose_jwk_use_enc.beam",
        "ebin/jose_jwk_use_sig.beam",
        "ebin/jose_jws.beam",
        "ebin/jose_jws_alg.beam",
        "ebin/jose_sha3.beam",
        "ebin/jose_xchacha20_poly1305.beam",
    ],
    hdrs = [
        "include/jose.hrl",
        "include/jose_base.hrl",
        "include/jose_compat.hrl",
        "include/jose_jwe.hrl",
        "include/jose_jwk.hrl",
        "include/jose_jws.hrl",
        "include/jose_jwt.hrl",
        "include/jose_public_key.hrl",
    ],
    app_name = "jose",
    beam = [":parse_transforms"],
    erlc_opts = "//:erlc_opts",
)

erlang_bytecode(
    name = "other_beam",
    srcs = [
        "src/base/jose_base64.erl",
        "src/base/jose_base64url.erl",
        "src/jose.erl",
        "src/jose_app.erl",
        "src/jose_chacha20_poly1305_crypto.erl",
        "src/jose_chacha20_poly1305_libsodium.erl",
        "src/jose_chacha20_poly1305_unsupported.erl",
        "src/jose_crypto_compat.erl",
        "src/jose_curve25519_libdecaf.erl",
        "src/jose_curve25519_libsodium.erl",
        "src/jose_curve25519_unsupported.erl",
        "src/jose_curve448_libdecaf.erl",
        "src/jose_curve448_unsupported.erl",
        "src/jose_public_key.erl",
        "src/jose_server.erl",
        "src/jose_sha3_keccakf1600_driver.erl",
        "src/jose_sha3_keccakf1600_nif.erl",
        "src/jose_sha3_libdecaf.erl",
        "src/jose_sha3_unsupported.erl",
        "src/jose_sup.erl",
        "src/jose_xchacha20_poly1305_crypto.erl",
        "src/jose_xchacha20_poly1305_unsupported.erl",
        "src/json/jose_json_jason.erl",
        "src/json/jose_json_jiffy.erl",
        "src/json/jose_json_jsone.erl",
        "src/json/jose_json_jsx.erl",
        "src/json/jose_json_ojson.erl",
        "src/json/jose_json_poison.erl",
        "src/json/jose_json_poison_compat_encoder.erl",
        "src/json/jose_json_poison_lexical_encoder.erl",
        "src/json/jose_json_thoas.erl",
        "src/json/jose_json_unsupported.erl",
        "src/jwa/jose_jwa.erl",
        "src/jwa/jose_jwa_aes.erl",
        "src/jwa/jose_jwa_aes_kw.erl",
        "src/jwa/jose_jwa_base64url.erl",
        "src/jwa/jose_jwa_bench.erl",
        "src/jwa/jose_jwa_chacha20.erl",
        "src/jwa/jose_jwa_chacha20_poly1305.erl",
        "src/jwa/jose_jwa_concat_kdf.erl",
        "src/jwa/jose_jwa_curve25519.erl",
        "src/jwa/jose_jwa_curve448.erl",
        "src/jwa/jose_jwa_ed25519.erl",
        "src/jwa/jose_jwa_ed448.erl",
        "src/jwa/jose_jwa_hchacha20.erl",
        "src/jwa/jose_jwa_math.erl",
        "src/jwa/jose_jwa_pkcs1.erl",
        "src/jwa/jose_jwa_pkcs5.erl",
        "src/jwa/jose_jwa_pkcs7.erl",
        "src/jwa/jose_jwa_poly1305.erl",
        "src/jwa/jose_jwa_sha3.erl",
        "src/jwa/jose_jwa_unsupported.erl",
        "src/jwa/jose_jwa_x25519.erl",
        "src/jwa/jose_jwa_x448.erl",
        "src/jwa/jose_jwa_xchacha20.erl",
        "src/jwa/jose_jwa_xchacha20_poly1305.erl",
        "src/jwe/jose_jwe_alg_aes_kw.erl",
        "src/jwe/jose_jwe_alg_c20p_kw.erl",
        "src/jwe/jose_jwe_alg_dir.erl",
        "src/jwe/jose_jwe_alg_ecdh_1pu.erl",
        "src/jwe/jose_jwe_alg_ecdh_es.erl",
        "src/jwe/jose_jwe_alg_pbes2.erl",
        "src/jwe/jose_jwe_alg_rsa.erl",
        "src/jwe/jose_jwe_alg_xc20p_kw.erl",
        "src/jwe/jose_jwe_enc_aes.erl",
        "src/jwe/jose_jwe_enc_c20p.erl",
        "src/jwe/jose_jwe_enc_xc20p.erl",
        "src/jwe/jose_jwe_zip.erl",
        "src/jwk/jose_jwk_der.erl",
        "src/jwk/jose_jwk_kty_ec.erl",
        "src/jwk/jose_jwk_kty_oct.erl",
        "src/jwk/jose_jwk_kty_okp_ed25519.erl",
        "src/jwk/jose_jwk_kty_okp_ed25519ph.erl",
        "src/jwk/jose_jwk_kty_okp_ed448.erl",
        "src/jwk/jose_jwk_kty_okp_ed448ph.erl",
        "src/jwk/jose_jwk_kty_okp_x25519.erl",
        "src/jwk/jose_jwk_kty_okp_x448.erl",
        "src/jwk/jose_jwk_kty_rsa.erl",
        "src/jwk/jose_jwk_openssh_key.erl",
        "src/jwk/jose_jwk_pem.erl",
        "src/jwk/jose_jwk_set.erl",
        "src/jws/jose_jws_alg_ecdsa.erl",
        "src/jws/jose_jws_alg_eddsa.erl",
        "src/jws/jose_jws_alg_hmac.erl",
        "src/jws/jose_jws_alg_none.erl",
        "src/jws/jose_jws_alg_poly1305.erl",
        "src/jws/jose_jws_alg_rsa_pkcs1_v1_5.erl",
        "src/jws/jose_jws_alg_rsa_pss.erl",
        "src/jwt/jose_jwt.erl",
    ],
    outs = [
        "ebin/jose.beam",
        "ebin/jose_app.beam",
        "ebin/jose_base64.beam",
        "ebin/jose_base64url.beam",
        "ebin/jose_chacha20_poly1305_crypto.beam",
        "ebin/jose_chacha20_poly1305_libsodium.beam",
        "ebin/jose_chacha20_poly1305_unsupported.beam",
        "ebin/jose_crypto_compat.beam",
        "ebin/jose_curve25519_libdecaf.beam",
        "ebin/jose_curve25519_libsodium.beam",
        "ebin/jose_curve25519_unsupported.beam",
        "ebin/jose_curve448_libdecaf.beam",
        "ebin/jose_curve448_unsupported.beam",
        "ebin/jose_json_jason.beam",
        "ebin/jose_json_jiffy.beam",
        "ebin/jose_json_jsone.beam",
        "ebin/jose_json_jsx.beam",
        "ebin/jose_json_ojson.beam",
        "ebin/jose_json_poison.beam",
        "ebin/jose_json_poison_compat_encoder.beam",
        "ebin/jose_json_poison_lexical_encoder.beam",
        "ebin/jose_json_thoas.beam",
        "ebin/jose_json_unsupported.beam",
        "ebin/jose_jwa.beam",
        "ebin/jose_jwa_aes.beam",
        "ebin/jose_jwa_aes_kw.beam",
        "ebin/jose_jwa_base64url.beam",
        "ebin/jose_jwa_bench.beam",
        "ebin/jose_jwa_chacha20.beam",
        "ebin/jose_jwa_chacha20_poly1305.beam",
        "ebin/jose_jwa_concat_kdf.beam",
        "ebin/jose_jwa_curve25519.beam",
        "ebin/jose_jwa_curve448.beam",
        "ebin/jose_jwa_ed25519.beam",
        "ebin/jose_jwa_ed448.beam",
        "ebin/jose_jwa_hchacha20.beam",
        "ebin/jose_jwa_math.beam",
        "ebin/jose_jwa_pkcs1.beam",
        "ebin/jose_jwa_pkcs5.beam",
        "ebin/jose_jwa_pkcs7.beam",
        "ebin/jose_jwa_poly1305.beam",
        "ebin/jose_jwa_sha3.beam",
        "ebin/jose_jwa_unsupported.beam",
        "ebin/jose_jwa_x25519.beam",
        "ebin/jose_jwa_x448.beam",
        "ebin/jose_jwa_xchacha20.beam",
        "ebin/jose_jwa_xchacha20_poly1305.beam",
        "ebin/jose_jwe_alg_aes_kw.beam",
        "ebin/jose_jwe_alg_c20p_kw.beam",
        "ebin/jose_jwe_alg_dir.beam",
        "ebin/jose_jwe_alg_ecdh_1pu.beam",
        "ebin/jose_jwe_alg_ecdh_es.beam",
        "ebin/jose_jwe_alg_pbes2.beam",
        "ebin/jose_jwe_alg_rsa.beam",
        "ebin/jose_jwe_alg_xc20p_kw.beam",
        "ebin/jose_jwe_enc_aes.beam",
        "ebin/jose_jwe_enc_c20p.beam",
        "ebin/jose_jwe_enc_xc20p.beam",
        "ebin/jose_jwe_zip.beam",
        "ebin/jose_jwk_der.beam",
        "ebin/jose_jwk_kty_ec.beam",
        "ebin/jose_jwk_kty_oct.beam",
        "ebin/jose_jwk_kty_okp_ed25519.beam",
        "ebin/jose_jwk_kty_okp_ed25519ph.beam",
        "ebin/jose_jwk_kty_okp_ed448.beam",
        "ebin/jose_jwk_kty_okp_ed448ph.beam",
        "ebin/jose_jwk_kty_okp_x25519.beam",
        "ebin/jose_jwk_kty_okp_x448.beam",
        "ebin/jose_jwk_kty_rsa.beam",
        "ebin/jose_jwk_openssh_key.beam",
        "ebin/jose_jwk_pem.beam",
        "ebin/jose_jwk_set.beam",
        "ebin/jose_jws_alg_ecdsa.beam",
        "ebin/jose_jws_alg_eddsa.beam",
        "ebin/jose_jws_alg_hmac.beam",
        "ebin/jose_jws_alg_none.beam",
        "ebin/jose_jws_alg_poly1305.beam",
        "ebin/jose_jws_alg_rsa_pkcs1_v1_5.beam",
        "ebin/jose_jws_alg_rsa_pss.beam",
        "ebin/jose_jwt.beam",
        "ebin/jose_public_key.beam",
        "ebin/jose_server.beam",
        "ebin/jose_sha3_keccakf1600_driver.beam",
        "ebin/jose_sha3_keccakf1600_nif.beam",
        "ebin/jose_sha3_libdecaf.beam",
        "ebin/jose_sha3_unsupported.beam",
        "ebin/jose_sup.beam",
        "ebin/jose_xchacha20_poly1305_crypto.beam",
        "ebin/jose_xchacha20_poly1305_unsupported.beam",
    ],
    hdrs = [
        "include/jose.hrl",
        "include/jose_base.hrl",
        "include/jose_compat.hrl",
        "include/jose_jwe.hrl",
        "include/jose_jwk.hrl",
        "include/jose_jws.hrl",
        "include/jose_jwt.hrl",
        "include/jose_public_key.hrl",
    ],
    app_name = "jose",
    beam = [
        ":parse_transforms",
        ":behaviours",
    ],
    erlc_opts = "//:erlc_opts",
)

filegroup(
    name = "beam_files",
    srcs = [
        ":behaviours",
        ":other_beam",
        ":parse_transforms",
    ],
)

filegroup(
    name = "srcs",
    srcs = [
        "src/base/jose_base.erl",
        "src/base/jose_base64.erl",
        "src/base/jose_base64url.erl",
        "src/jose.app.src",
        "src/jose.erl",
        "src/jose_app.erl",
        "src/jose_block_encryptor.erl",
        "src/jose_chacha20_poly1305.erl",
        "src/jose_chacha20_poly1305_crypto.erl",
        "src/jose_chacha20_poly1305_libsodium.erl",
        "src/jose_chacha20_poly1305_unsupported.erl",
        "src/jose_crypto_compat.erl",
        "src/jose_curve25519.erl",
        "src/jose_curve25519_libdecaf.erl",
        "src/jose_curve25519_libsodium.erl",
        "src/jose_curve25519_unsupported.erl",
        "src/jose_curve448.erl",
        "src/jose_curve448_libdecaf.erl",
        "src/jose_curve448_unsupported.erl",
        "src/jose_public_key.erl",
        "src/jose_server.erl",
        "src/jose_sha3.erl",
        "src/jose_sha3_keccakf1600_driver.erl",
        "src/jose_sha3_keccakf1600_nif.erl",
        "src/jose_sha3_libdecaf.erl",
        "src/jose_sha3_unsupported.erl",
        "src/jose_sup.erl",
        "src/jose_xchacha20_poly1305.erl",
        "src/jose_xchacha20_poly1305_crypto.erl",
        "src/jose_xchacha20_poly1305_unsupported.erl",
        "src/json/jose_json.erl",
        "src/json/jose_json_jason.erl",
        "src/json/jose_json_jiffy.erl",
        "src/json/jose_json_jsone.erl",
        "src/json/jose_json_jsx.erl",
        "src/json/jose_json_ojson.erl",
        "src/json/jose_json_poison.erl",
        "src/json/jose_json_poison_compat_encoder.erl",
        "src/json/jose_json_poison_lexical_encoder.erl",
        "src/json/jose_json_thoas.erl",
        "src/json/jose_json_unsupported.erl",
        "src/jwa/jose_jwa.erl",
        "src/jwa/jose_jwa_aes.erl",
        "src/jwa/jose_jwa_aes_kw.erl",
        "src/jwa/jose_jwa_base64url.erl",
        "src/jwa/jose_jwa_bench.erl",
        "src/jwa/jose_jwa_chacha20.erl",
        "src/jwa/jose_jwa_chacha20_poly1305.erl",
        "src/jwa/jose_jwa_concat_kdf.erl",
        "src/jwa/jose_jwa_curve25519.erl",
        "src/jwa/jose_jwa_curve448.erl",
        "src/jwa/jose_jwa_ed25519.erl",
        "src/jwa/jose_jwa_ed448.erl",
        "src/jwa/jose_jwa_hchacha20.erl",
        "src/jwa/jose_jwa_math.erl",
        "src/jwa/jose_jwa_pkcs1.erl",
        "src/jwa/jose_jwa_pkcs5.erl",
        "src/jwa/jose_jwa_pkcs7.erl",
        "src/jwa/jose_jwa_poly1305.erl",
        "src/jwa/jose_jwa_sha3.erl",
        "src/jwa/jose_jwa_unsupported.erl",
        "src/jwa/jose_jwa_x25519.erl",
        "src/jwa/jose_jwa_x448.erl",
        "src/jwa/jose_jwa_xchacha20.erl",
        "src/jwa/jose_jwa_xchacha20_poly1305.erl",
        "src/jwe/jose_jwe.erl",
        "src/jwe/jose_jwe_alg.erl",
        "src/jwe/jose_jwe_alg_aes_kw.erl",
        "src/jwe/jose_jwe_alg_c20p_kw.erl",
        "src/jwe/jose_jwe_alg_dir.erl",
        "src/jwe/jose_jwe_alg_ecdh_1pu.erl",
        "src/jwe/jose_jwe_alg_ecdh_es.erl",
        "src/jwe/jose_jwe_alg_pbes2.erl",
        "src/jwe/jose_jwe_alg_rsa.erl",
        "src/jwe/jose_jwe_alg_xc20p_kw.erl",
        "src/jwe/jose_jwe_enc.erl",
        "src/jwe/jose_jwe_enc_aes.erl",
        "src/jwe/jose_jwe_enc_c20p.erl",
        "src/jwe/jose_jwe_enc_xc20p.erl",
        "src/jwe/jose_jwe_zip.erl",
        "src/jwk/jose_jwk.erl",
        "src/jwk/jose_jwk_der.erl",
        "src/jwk/jose_jwk_kty.erl",
        "src/jwk/jose_jwk_kty_ec.erl",
        "src/jwk/jose_jwk_kty_oct.erl",
        "src/jwk/jose_jwk_kty_okp_ed25519.erl",
        "src/jwk/jose_jwk_kty_okp_ed25519ph.erl",
        "src/jwk/jose_jwk_kty_okp_ed448.erl",
        "src/jwk/jose_jwk_kty_okp_ed448ph.erl",
        "src/jwk/jose_jwk_kty_okp_x25519.erl",
        "src/jwk/jose_jwk_kty_okp_x448.erl",
        "src/jwk/jose_jwk_kty_rsa.erl",
        "src/jwk/jose_jwk_oct.erl",
        "src/jwk/jose_jwk_openssh_key.erl",
        "src/jwk/jose_jwk_pem.erl",
        "src/jwk/jose_jwk_set.erl",
        "src/jwk/jose_jwk_use_enc.erl",
        "src/jwk/jose_jwk_use_sig.erl",
        "src/jws/jose_jws.erl",
        "src/jws/jose_jws_alg.erl",
        "src/jws/jose_jws_alg_ecdsa.erl",
        "src/jws/jose_jws_alg_eddsa.erl",
        "src/jws/jose_jws_alg_hmac.erl",
        "src/jws/jose_jws_alg_none.erl",
        "src/jws/jose_jws_alg_poly1305.erl",
        "src/jws/jose_jws_alg_rsa_pkcs1_v1_5.erl",
        "src/jws/jose_jws_alg_rsa_pss.erl",
        "src/jwt/jose_jwt.erl",
    ],
)

filegroup(
    name = "private_hdrs",
    srcs = [],
)

filegroup(
    name = "public_hdrs",
    srcs = [
        "include/jose.hrl",
        "include/jose_base.hrl",
        "include/jose_compat.hrl",
        "include/jose_jwe.hrl",
        "include/jose_jwk.hrl",
        "include/jose_jws.hrl",
        "include/jose_jwt.hrl",
        "include/jose_public_key.hrl",
    ],
)

filegroup(
    name = "priv",
    srcs = ["priv/Dockerfile"],
)

filegroup(
    name = "licenses",
    srcs = ["LICENSE.md"],
)

filegroup(
    name = "public_and_private_hdrs",
    srcs = [
        ":private_hdrs",
        ":public_hdrs",
    ],
)

filegroup(
    name = "all_srcs",
    srcs = [
        ":public_and_private_hdrs",
        ":srcs",
    ],
)

erlang_app(
    name = "erlang_app",
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_name = "jose",
    beam_files = [":beam_files"],
    extra_apps = [
        "asn1",
        "crypto",
        "public_key",
    ],
    deps = ["@thoas//:erlang_app"],
)

alias(
    name = "jose",
    actual = ":erlang_app",
    visibility = ["//visibility:public"],
)
