Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dtolnay opened this issue Jan 1, 2023 · 2 comments · Fixed by #2226
Closed

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

dtolnay opened this issue Jan 1, 2023 · 2 comments · Fixed by #2226

Comments

@dtolnay
Copy link
Contributor

dtolnay commented Jan 1, 2023

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" }
@dtolnay
Copy link
Contributor Author

dtolnay commented Jan 1, 2023

I believe this is blocked right now on rust-lang/cargo#10607.

@weihanglo
Copy link

I just filed a pull request rust-lang/cargo#11550 for cargo metata supporting artifact dependencies. I will appreciate you trying it to see if that meets the needs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants