Skip to content

Commit

Permalink
Set version from Cargo.toml (#40)
Browse files Browse the repository at this point in the history
This uses a genrule to read the Cargo.toml and set `CARGO_PKG_VERSION`.
This is picked up by clap to set the version when asked via `--version`.

Fixes #39
  • Loading branch information
cameron-martin authored Jun 24, 2024
1 parent 22fb925 commit c069c2d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
12 changes: 12 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rust_binary(
"//src/builtin:builtin.pb",
"//src/builtin:default_build_language.pb",
],
rustc_env_files = [":generate_rustc_env_file"],
deps = [
"//src/builtin:build_proto_rust",
"//src/builtin:builtin_proto_rust",
Expand All @@ -23,6 +24,17 @@ rust_binary(
],
)

genrule(
name = "generate_rustc_env_file",
srcs = [
"Cargo.toml",
"src/main.rs",
],
outs = ["rustc_env_file"],
cmd = "echo \"CARGO_PKG_VERSION=$$($(location @rust_host_tools//:cargo) read-manifest | jq -r .version)\" > $@",
tools = ["@rust_host_tools//:cargo"],
)

rust_test(
name = "unit_tests",
crate = ":bazel-lsp",
Expand Down
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ rust.toolchain(
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")

rust_host_tools = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools")

use_repo(rust_host_tools, "rust_host_tools")

crate = use_extension(
"@rules_rust//crate_universe:extension.bzl",
"crate",
Expand Down
27 changes: 22 additions & 5 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c069c2d

Please sign in to comment.