facebookincubator / reindeer

Reindeer is a tool to transform Rust Cargo dependencies into generated Buck build rules
MIT License
185 stars 30 forks source link

feature: allow user to specify the name for `include_top_level` #45

Open thoughtpolice opened 6 months ago

thoughtpolice commented 6 months ago

include_top_level is pretty nice since it lets you build everything as a smoke test. But the generated target name comes across as pretty awkward; for example, given this snippet of a Cargo.toml, to be buckified and located at package third-party//rust:

[workspace]

[package]
name = "rust-third-party"
version = "0.0.0"
publish = false
edition = "2021"

# Dummy target to keep Cargo happy
[[bin]]
name = "top"
path = "top.rs"

[dependencies]
...

You get a fully-qualified target name like third-party//rust:rust-third-party-0.0.0-top, which is pretty verbose and annoying to write without tab completion in Buck.

To work around this, my reindeer.toml contains the following hack:

[buck]
file_name = "BUCK"

rust_library = "cargo.rust_library"
rust_binary = "cargo.rust_binary"
buckfile_imports = """
load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run")
load("@prelude//rust:cargo_package.bzl", "cargo")

# XXX (aseipp): this is a hack to provide a convenient top-level alias.
# this allows us to just build `third-party//rust` without a target name
# to build everything we need.
# this should probably be part of reindeer itself?

alias(
    name = "rust",
    actual = ":rust-third-party-0.0.0-top",
    visibility = ["PUBLIC"],
)

# XXX: normal reindeer-generated code below
"""

By giving the target the name rust, it becomes the default target for the package third-party//rust, and so buck2 build third-party//rust is enough to check that all my Cargo packages build. This is much more convenient.

It would be nice if there was a way to just specify what the name of the top-level target name is inside reindeer.toml, instead of needing this hack.