load(
    "@rules_rust//crate_universe:defs.bzl",
    "crate",
    "crates_vendor",
    "render_config",
)
load("//tools/install:install.bzl", "install", "install_license")
load("//tools/lint:lint.bzl", "add_lint_tests")
load("//tools/workspace/crate_universe:lock/archives.bzl", "ARCHIVES")

exports_files(glob(["lock/**"]))

# This is a maintainer-only tool for Drake Developers to manage our Rust
# dependencies. See README.md for instructions on how to run `upgrade.sh`.
crates_vendor(
    name = "crate",
    annotations = {
        "clarabel": [crate.annotation(
            patches = [
                "@drake//tools/workspace/crate_universe:patches/clarabel_blas.patch",  # noqa
            ],
        )],
    },
    cargo_lockfile = ":lock/Cargo.toml.lock",
    manifests = [
        "@clarabel_cpp_internal//:rust_wrapper/Cargo.toml",
    ],
    mode = "remote",
    render_config = render_config(
        generate_rules_license_metadata = True,
    ),
    tags = ["manual"],
    vendor_path = "lock/details",
)

# Install the license files for all crates.
ARCHIVE_NAMES = [archive["name"] for archive in ARCHIVES]

[
    install_license(
        name = "install_{}".format(name),
        doc_dest = "share/doc/{}".format(name),
        licenses = [
            "@{}//:license".format(name),
        ],
    )
    for name in ARCHIVE_NAMES
]

install(
    name = "install",
    visibility = ["//visibility:public"],
    deps = [
        "install_{}".format(name)
        for name in ARCHIVE_NAMES
    ],
)

add_lint_tests()
