|
3 | 3 | load("@bazel_skylib//lib:paths.bzl", "paths") |
4 | 4 | load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") |
5 | 5 | load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") |
6 | | -load("@rules_cc//cc:find_cc_toolchain.bzl", find_cpp_toolchain = "find_cc_toolchain") |
7 | 6 | load("@rules_cc//cc/common:cc_common.bzl", "cc_common") |
8 | 7 | load("//rust:defs.bzl", "rust_common") |
9 | 8 | load("//rust:rust_common.bzl", "BuildInfo", "CrateGroupInfo", "DepInfo") |
@@ -373,8 +372,6 @@ def _cargo_build_script_impl(ctx): |
373 | 372 |
|
374 | 373 | toolchain_tools = [toolchain.all_files] |
375 | 374 |
|
376 | | - cc_toolchain = find_cpp_toolchain(ctx) |
377 | | - |
378 | 375 | env = {} |
379 | 376 |
|
380 | 377 | if ctx.attr.use_default_shell_env == -1: |
@@ -423,18 +420,25 @@ def _cargo_build_script_impl(ctx): |
423 | 420 | # Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version). |
424 | 421 | # We hope that the linker env is sufficient for the whole cc_toolchain. |
425 | 422 | cc_toolchain, feature_configuration = find_cc_toolchain(ctx) |
426 | | - linker, link_args, linker_env = get_linker_and_args(ctx, "bin", cc_toolchain, feature_configuration, None) |
| 423 | + linker, _, link_args, linker_env = get_linker_and_args(ctx, "bin", toolchain, cc_toolchain, feature_configuration, None) |
427 | 424 | env.update(**linker_env) |
428 | 425 | env["LD"] = linker |
429 | 426 | env["LDFLAGS"] = " ".join(_pwd_flags(link_args)) |
430 | 427 |
|
431 | | - # MSVC requires INCLUDE to be set |
432 | | - cc_c_args, cc_cxx_args, cc_ar_args, cc_env = get_cc_compile_args_and_env(cc_toolchain, feature_configuration) |
433 | | - include = cc_env.get("INCLUDE") |
434 | | - if include: |
435 | | - env["INCLUDE"] = include |
| 428 | + # Defaults for cxx flags. |
| 429 | + env["CC"] = "${{pwd}}/{}".format(ctx.executable._fallback_cc.path) |
| 430 | + env["CXX"] = "${{pwd}}/{}".format(ctx.executable._fallback_cxx.path) |
| 431 | + env["AR"] = "${{pwd}}/{}".format(ctx.executable._fallback_ar.path) |
| 432 | + env["CFLAGS"] = "" |
| 433 | + env["CXXFLAGS"] = "" |
436 | 434 |
|
437 | 435 | if cc_toolchain: |
| 436 | + # MSVC requires INCLUDE to be set |
| 437 | + cc_c_args, cc_cxx_args, cc_ar_args, cc_env = get_cc_compile_args_and_env(cc_toolchain, feature_configuration) |
| 438 | + include = cc_env.get("INCLUDE") |
| 439 | + if include: |
| 440 | + env["INCLUDE"] = include |
| 441 | + |
438 | 442 | toolchain_tools.append(cc_toolchain.all_files) |
439 | 443 |
|
440 | 444 | env["CC"] = cc_common.get_tool_for_action( |
@@ -515,6 +519,9 @@ def _cargo_build_script_impl(ctx): |
515 | 519 | direct = [ |
516 | 520 | script, |
517 | 521 | ctx.executable._cargo_build_script_runner, |
| 522 | + ctx.executable._fallback_cc, |
| 523 | + ctx.executable._fallback_cxx, |
| 524 | + ctx.executable._fallback_ar, |
518 | 525 | ] + ([toolchain.target_json] if toolchain.target_json else []), |
519 | 526 | transitive = script_data + script_tools + toolchain_tools, |
520 | 527 | ) |
@@ -737,14 +744,29 @@ cargo_build_script = rule( |
737 | 744 | "_experimental_symlink_execroot": attr.label( |
738 | 745 | default = Label("//cargo/settings:experimental_symlink_execroot"), |
739 | 746 | ), |
| 747 | + "_fallback_ar": attr.label( |
| 748 | + cfg = "exec", |
| 749 | + executable = True, |
| 750 | + default = Label("//cargo/private:no_ar"), |
| 751 | + ), |
| 752 | + "_fallback_cc": attr.label( |
| 753 | + cfg = "exec", |
| 754 | + executable = True, |
| 755 | + default = Label("//cargo/private:no_cc"), |
| 756 | + ), |
| 757 | + "_fallback_cxx": attr.label( |
| 758 | + cfg = "exec", |
| 759 | + executable = True, |
| 760 | + default = Label("//cargo/private:no_cxx"), |
| 761 | + ), |
740 | 762 | "_incompatible_runfiles_cargo_manifest_dir": attr.label( |
741 | 763 | default = Label("//cargo/settings:incompatible_runfiles_cargo_manifest_dir"), |
742 | 764 | ), |
743 | 765 | }, |
744 | 766 | fragments = ["cpp"], |
745 | 767 | toolchains = [ |
746 | 768 | str(Label("//rust:toolchain_type")), |
747 | | - "@bazel_tools//tools/cpp:toolchain_type", |
| 769 | + config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False), |
748 | 770 | ], |
749 | 771 | ) |
750 | 772 |
|
|
0 commit comments