Skip to content

Commit 19beae8

Browse files
authored
Add --rust-target to bindgen invocation (#3955)
1 parent 22f7dbb commit 19beae8

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

extensions/bindgen/private/bindgen.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,18 @@ def _rust_bindgen_impl(ctx):
243243
args.add_all(ctx.attr.bindgen_flags)
244244

245245
rust_toolchain = ctx.toolchains[Label("@rules_rust//rust:toolchain_type")]
246-
if "--rust-edition" not in [f.split("=")[0] for f in ctx.attr.bindgen_flags]:
246+
user_flags = [f.split("=")[0] for f in ctx.attr.bindgen_flags]
247+
248+
# Ignore `nightly` or `beta` versions.
249+
if rust_toolchain.version and rust_toolchain.version[0].isdigit():
250+
# Pass `--rust-target` so bindgen knows the actual toolchain version.
251+
# Without this, bindgen defaults to it's built-in `LATEST_STABLE_RUST`
252+
# which may be older than the actual toolchain version and would
253+
# reject newer editions (e.g. edition 2024 requires `rust-target >= 1.85.0`).
254+
if "--rust-target" not in user_flags:
255+
args.add("--rust-target=%s" % rust_toolchain.version)
256+
257+
if "--rust-edition" not in user_flags:
247258
args.add("--rust-edition=%s" % rust_toolchain.default_edition)
248259

249260
args.add(header)

0 commit comments

Comments
 (0)