|
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") |
@@ -367,8 +366,6 @@ def _cargo_build_script_impl(ctx): |
367 | 366 |
|
368 | 367 | toolchain_tools = [toolchain.all_files] |
369 | 368 |
|
370 | | - cc_toolchain = find_cpp_toolchain(ctx) |
371 | | - |
372 | 369 | env = {} |
373 | 370 |
|
374 | 371 | if ctx.attr.use_default_shell_env == -1: |
@@ -417,18 +414,25 @@ def _cargo_build_script_impl(ctx): |
417 | 414 | # Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version). |
418 | 415 | # We hope that the linker env is sufficient for the whole cc_toolchain. |
419 | 416 | cc_toolchain, feature_configuration = find_cc_toolchain(ctx) |
420 | | - linker, link_args, linker_env = get_linker_and_args(ctx, "bin", cc_toolchain, feature_configuration, None) |
| 417 | + linker, _, link_args, linker_env = get_linker_and_args(ctx, "bin", toolchain, cc_toolchain, feature_configuration, None) |
421 | 418 | env.update(**linker_env) |
422 | 419 | env["LD"] = linker |
423 | 420 | env["LDFLAGS"] = " ".join(_pwd_flags(link_args)) |
424 | 421 |
|
425 | | - # MSVC requires INCLUDE to be set |
426 | | - cc_c_args, cc_cxx_args, cc_env = get_cc_compile_args_and_env(cc_toolchain, feature_configuration) |
427 | | - include = cc_env.get("INCLUDE") |
428 | | - if include: |
429 | | - env["INCLUDE"] = include |
| 422 | + # Defaults for cxx flags. |
| 423 | + env["CC"] = "${{pwd}}/{}".format(ctx.executable._fallback_cc.path) |
| 424 | + env["CXX"] = "${{pwd}}/{}".format(ctx.executable._fallback_cxx.path) |
| 425 | + env["AR"] = "${{pwd}}/{}".format(ctx.executable._fallback_ar.path) |
| 426 | + env["CFLAGS"] = "" |
| 427 | + env["CXXFLAGS"] = "" |
430 | 428 |
|
431 | 429 | if cc_toolchain: |
| 430 | + # MSVC requires INCLUDE to be set |
| 431 | + cc_c_args, cc_cxx_args, cc_env = get_cc_compile_args_and_env(cc_toolchain, feature_configuration) |
| 432 | + include = cc_env.get("INCLUDE") |
| 433 | + if include: |
| 434 | + env["INCLUDE"] = include |
| 435 | + |
432 | 436 | toolchain_tools.append(cc_toolchain.all_files) |
433 | 437 |
|
434 | 438 | env["CC"] = cc_common.get_tool_for_action( |
@@ -503,6 +507,9 @@ def _cargo_build_script_impl(ctx): |
503 | 507 | direct = [ |
504 | 508 | script, |
505 | 509 | ctx.executable._cargo_build_script_runner, |
| 510 | + ctx.executable._fallback_cc, |
| 511 | + ctx.executable._fallback_cxx, |
| 512 | + ctx.executable._fallback_ar, |
506 | 513 | ] + ([toolchain.target_json] if toolchain.target_json else []), |
507 | 514 | transitive = script_data + script_tools + toolchain_tools, |
508 | 515 | ) |
@@ -725,14 +732,29 @@ cargo_build_script = rule( |
725 | 732 | "_experimental_symlink_execroot": attr.label( |
726 | 733 | default = Label("//cargo/settings:experimental_symlink_execroot"), |
727 | 734 | ), |
| 735 | + "_fallback_ar": attr.label( |
| 736 | + cfg = "exec", |
| 737 | + executable = True, |
| 738 | + default = Label("//cargo/private:no_ar"), |
| 739 | + ), |
| 740 | + "_fallback_cc": attr.label( |
| 741 | + cfg = "exec", |
| 742 | + executable = True, |
| 743 | + default = Label("//cargo/private:no_cc"), |
| 744 | + ), |
| 745 | + "_fallback_cxx": attr.label( |
| 746 | + cfg = "exec", |
| 747 | + executable = True, |
| 748 | + default = Label("//cargo/private:no_cxx"), |
| 749 | + ), |
728 | 750 | "_incompatible_runfiles_cargo_manifest_dir": attr.label( |
729 | 751 | default = Label("//cargo/settings:incompatible_runfiles_cargo_manifest_dir"), |
730 | 752 | ), |
731 | 753 | }, |
732 | 754 | fragments = ["cpp"], |
733 | 755 | toolchains = [ |
734 | 756 | str(Label("//rust:toolchain_type")), |
735 | | - "@bazel_tools//tools/cpp:toolchain_type", |
| 757 | + config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False), |
736 | 758 | ], |
737 | 759 | ) |
738 | 760 |
|
|
0 commit comments