|
16 | 16 | "find_cc_toolchain", |
17 | 17 | "make_static_lib_symlink", |
18 | 18 | ) |
| 19 | +load("//rust/settings:incompatible.bzl", "IncompatibleFlagInfo") |
19 | 20 |
|
20 | 21 | rust_analyzer_toolchain = _rust_analyzer_toolchain |
21 | 22 | rustfmt_toolchain = _rustfmt_toolchain |
@@ -537,6 +538,12 @@ def _rust_toolchain_impl(ctx): |
537 | 538 | sysroot_path = sysroot.sysroot_anchor.dirname |
538 | 539 | sysroot_short_path, _, _ = sysroot.sysroot_anchor.short_path.rpartition("/") |
539 | 540 |
|
| 541 | + # Override "rustc --print sysroot" with sysroot generated by `_generate_sysroot` |
| 542 | + # in this rule implementation |
| 543 | + rustc_flags = ctx.attr.extra_rustc_flags |
| 544 | + if ctx.attr._experimental_toolchain_generated_sysroot[IncompatibleFlagInfo].enabled == True: |
| 545 | + rustc_flags = ["--sysroot=" + sysroot_path] + rustc_flags |
| 546 | + |
540 | 547 | # Variables for make variable expansion |
541 | 548 | make_variables = { |
542 | 549 | "RUSTC": sysroot.rustc.path, |
@@ -623,7 +630,7 @@ def _rust_toolchain_impl(ctx): |
623 | 630 | rustfmt = sysroot.rustfmt, |
624 | 631 | staticlib_ext = ctx.attr.staticlib_ext, |
625 | 632 | stdlib_linkflags = stdlib_linkflags_cc_info, |
626 | | - extra_rustc_flags = ctx.attr.extra_rustc_flags, |
| 633 | + extra_rustc_flags = rustc_flags, |
627 | 634 | extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags, |
628 | 635 | per_crate_rustc_flags = ctx.attr.per_crate_rustc_flags, |
629 | 636 | sysroot = sysroot_path, |
@@ -787,6 +794,13 @@ rust_toolchain = rule( |
787 | 794 | "_cc_toolchain": attr.label( |
788 | 795 | default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), |
789 | 796 | ), |
| 797 | + "_experimental_toolchain_generated_sysroot": attr.label( |
| 798 | + default = Label("//rust/settings:experimental_toolchain_generated_sysroot"), |
| 799 | + doc = ( |
| 800 | + "Label to a boolean build setting that lets the rule knows wheter to set --sysroot to rustc" + |
| 801 | + "This flag is only relevant when used together with --@rules_rust//rust/settings:experimental_toolchain_generated_sysroot." |
| 802 | + ), |
| 803 | + ), |
790 | 804 | "_experimental_use_coverage_metadata_files": attr.label( |
791 | 805 | default = Label("//rust/settings:experimental_use_coverage_metadata_files"), |
792 | 806 | ), |
|
0 commit comments