BUCKannotatedBUCKsource70 lines · 2.2 KB · raw
1load("//build:defs.bzl", "PG_MAJORS", "RUST_EDITION", "VERSION", "first_party_binary", "first_party_test")
2
3first_party_binary(
4    name = "cargo-gen",
5    srcs = glob(["src/**/*.rs"]),
6    crate_root = "src/main.rs",
7    deps = [
8        "//third-party:serde",
9        "//third-party:serde_json",
10        "//third-party:toml",
11    ],
12)

Every first-party buck package and its targets. A package with a library or binary becomes a Cargo package; its unit test target adds dev-dependencies. Add a new crate here when you add its BUCK file.

17PACKAGES = {
18    "crates/postjevsql": ["postjevsql"],
19    "crates/postjevsql-core": ["postjevsql-core", "test"],
20    "crates/postjevsql-pg": ["postjevsql-pg"],
21    "crates/postjevsql-sidecar": ["postjevsql-sidecar", "cli", "test"],
22    "tests/support": ["support"],
23    "tools/cargo-gen": ["cargo-gen"],
24    "tools/pgrx-schema": ["pgrx-schema"],
25    "tools/record-gates": ["record-gates"],
26    "tools/third-party-notices": ["third-party-notices"],
27}
29META = ["//{}:{}-cargo".format(pkg, t) for pkg, targets in PACKAGES.items() for t in targets]

The manifests the BUCK files imply, as a tree rooted like the checkout.

32genrule(
33    name = "manifests",
34    srcs = ["//third-party:Cargo.toml"],
35    out = "manifests",
36    cmd = " ".join([
37        "$(exe :cargo-gen) generate $OUT",
38        VERSION,
39        RUST_EDITION,
40        ",".join(PG_MAJORS),
41        "$(location //third-party:Cargo.toml)",
42    ] + ["$(location {})".format(m) for m in META]),
43)

The manifests committed in the checkout, as the same tree.

46genrule(
47    name = "committed",
48    out = "committed",
49    cmd = " && ".join(["mkdir -p $OUT", "cp -r $(location //:cargo-manifest)/. $OUT/"] + [
50        "mkdir -p $OUT/{pkg} && cp -r $(location //{pkg}:{t}-manifest)/. $OUT/{pkg}/".format(pkg = pkg, t = targets[0])
51        for pkg, targets in PACKAGES.items()
52    ]),
53)
55first_party_test(
56    name = "drift",
57    srcs = ["drift.rs"],
58    crate_root = "drift.rs",
59    env = {
60        "COMMITTED": "$(location :committed)",
61        "GENERATED": "$(location :manifests)",
62    },
63)

buck2 run //tools/cargo-gen:update rewrites the committed manifests.

66command_alias(
67    name = "update",
68    exe = ":cargo-gen",
69    args = ["write", "$(location :manifests)"],
70)