rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Regression: rust_prost_toolchain generates incorrect aliases on Linux / X86

Open marvin-hansen opened this issue 1 year ago • 3 comments

Bazel: 7.3.0 rules_rust: 0.49.1 rust: 1.80.1

This issue hit me totally out of the blue today;

rust_prost_toolchain somehow generates different aliases on on Linux / X86 than used in the prost toolchain config and that are different from MacOS, which breaks cross platform builds.

In a nutshell, rust_prost_toolchain is supposed to generate the following aliase:

  • "@crates//:protoc-gen-prost__protoc-gen-prost",
  • "@crates//:protoc-gen-tonic__protoc-gen-tonic",

Which it does on MacOS.

However, on Linux / X86 (Ubuntu 20.04) it fails to do so since today. This did not happened yesterday and literally never before.

Instead, since today, on Linux / X86 the aliases are generated as:

  • "protoc-gen-prost-0.3.1__protoc-gen-prost",
  • "protoc-gen-prost-0.4.0__protoc-gen-prost",

I don't know the cause, but here is what I observed when comparing the generated BUILD files side by side:

Build file: sandbox/external/rules_rust~~crate~crates/BUILD.bazel

On Mac, the file contains, among many others, these correct aliases:

# Binaries
alias(
    name = "protoc-gen-prost__protoc-gen-prost",
    actual = "@crates__protoc-gen-prost-0.3.1//:protoc-gen-prost__bin",
    tags = ["manual"],
)

alias(
    name = "protoc-gen-tonic__protoc-gen-tonic",
    actual = "@crates__protoc-gen-tonic-0.4.0//:protoc-gen-tonic__bin",
    tags = ["manual"],
)

On Linux / X86, the same file, contains different aliases containing version numbers:

# Binaries
alias(
    name = "protoc-gen-prost-0.3.1__protoc-gen-prost",
    actual = "@crates__protoc-gen-prost-0.3.1//:protoc-gen-prost__bin",
    tags = ["manual"],
)

alias(
    name = "protoc-gen-prost-0.4.0__protoc-gen-prost",
    actual = "@crates__protoc-gen-prost-0.4.0//:protoc-gen-prost__bin",
    tags = ["manual"],
)

The problem is, if I were to add the new alias with the version number my build breaks on Mac; If I keep the alias without version number, the CI build keeps failing, so either way this breaks stuff.

Config:

load("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain")
load("@rules_rust//rust:defs.bzl", "rust_library_group")

rust_library_group(
    name = "prost_runtime",
    deps = [
        "@crates//:prost",
    ],
)

rust_library_group(
    name = "tonic_runtime",
    deps = [
        ":prost_runtime",
        "@crates//:tonic",
    ],
)

rust_prost_toolchain(
    name = "prost_toolchain_impl",
    prost_plugin = "@crates//:protoc-gen-prost__protoc-gen-prost",
    prost_runtime = ":prost_runtime",
    prost_types = "@crates//:prost-types",
    # proto_compiler = "@protobuf//:protoc",
    tonic_plugin = "@crates//:protoc-gen-tonic__protoc-gen-tonic",
    tonic_runtime = ":tonic_runtime",
)

toolchain(
    name = "prost_toolchain",
    toolchain = "prost_toolchain_impl",
    toolchain_type = "@rules_rust//proto/prost:toolchain_type",
)

marvin-hansen avatar Aug 23 '24 11:08 marvin-hansen

It seems that the aliases with version number are actually build on all supported platforms, meaning when you update the rust_prost_toolchain declaration with an alias that contains a version number, the build runs on Mac and Linux. See below.

Why wasn't this mentioned in any of the release notes?

rust_prost_toolchain(
    name = "prost_toolchain_impl",
    prost_plugin = "@crates//:protoc-gen-prost-0.4.0__protoc-gen-prost",
    prost_runtime = ":prost_runtime",
    prost_types = "@crates//:prost-types",
    tonic_plugin = "@crates//:protoc-gen-tonic__protoc-gen-tonic",
    tonic_runtime = ":tonic_runtime",
)

marvin-hansen avatar Aug 23 '24 12:08 marvin-hansen

i was getting this error too:

no such target '@@rules_rust~~crate~crate_specs//:protoc-gen-prost__protoc-gen-prost': target 'protoc-gen-prost__protoc-gen-prost' not declared in package '' defined by /home/pdeva/.cache/bazel/_bazel_pdeva/b1a4ac6988a94eb0ad1222a792d4139b/external/rules_rust~~crate~crate_specs/BUILD.bazel

i agree this should have been mentioned in the release notes.

pdeva avatar Aug 23 '24 18:08 pdeva

@pdeva I did some digging and the bug also occurs with several previous versions of rules_rust all the way back to 0.47, which indicates the issue is most likely unrelated to the rules.

Rather, the underlying protoc-gen-prost crate pushed out 4 new versions about the same time I observed my first CI failure...

Stuff just happens 😕

marvin-hansen avatar Aug 24 '24 07:08 marvin-hansen