Skip to content

Support "artifact dependencies" (bin, cdylib, staticlib) #1739

Closed
@dtolnay

Description

@dtolnay

Historically Cargo has not supported depending on binary packages, only on libraries.

In the past, crate_universe used to expose extra_workspace_members for declaring binary dependencies to augment the library dependencies established by your Cargo.toml.

crates_repository(
    name = "crate_index_extra_members",
    extra_workspace_members = {
        "texture-synthesis-cli": crate.workspace_member(
            sha256 = "a7dbdf13f5e6f214750fce1073279b71ce3076157a8d337c9b0f0e14334e2aec",
            version = "0.8.2",
        ),
    },
    ...
)

This was deleted in #1406 in favor of "external manifests":

http_archive(
    name = "names",
    urls = ["https://github.com/fnichol/names/archive/refs/tags/v0.13.0.zip"],
    ...
)

crates_repository(
    name = "crate_index_cargo_remote",
    manifests = ["@names//:Cargo.toml"],
    ...
)

Recently though, Cargo has begun implementing support for binary dependencies natively in Cargo.toml.

Supporting this feature in crate_universe would make it substantially more convenient to manage binary dependencies. In particular, --repin would be able to pull in updates, which is not possible with the current "external manifests" way.

Binary dependencies would be declared in Cargo.toml as follows, and would work with both crates_repository and crates_vendor.

[dependencies]
# Export rust_binary for all bins in the package. If the
# package also contains a library, then a rust_library still
# needs to be generated in BUILD.example-1.0.0.bazel because
# the binary depends on it, but it will be private.
example = { version = "1", artifact = "bin" }

# Export rust_binary for those specific bins, do not export rust_library.
example = { version = "1", artifact = ["bin:faketty", "bin:cmake"] }

# Export rust_library as well as rust_binary.
example = { version = "1", artifact = "bin", lib = true }

# Export rust_library, do not generate any rust_binary targets.
example = { version = "1" }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions