Skip to content

Commit

Permalink
Fix cargo_build_script executables. (#2675)
Browse files Browse the repository at this point in the history
This allows it to work with new-style toolchains that use action configs
(see bazelbuild/bazel#22561).

It also allows you to specify a seperate C compiler and C++ compiler.
  • Loading branch information
matts1 authored Jun 3, 2024
1 parent 0c5e67c commit a92de54
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "CPP_COMPILE_ACTION_NAME", "C_COMPILE_ACTION_NAME")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
load("//rust:defs.bzl", "rust_common")
load("//rust:rust_common.bzl", "BuildInfo", "DepInfo")

Expand Down Expand Up @@ -46,17 +46,17 @@ def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
)
cc_c_args = cc_common.get_memory_inefficient_command_line(
feature_configuration = feature_configuration,
action_name = C_COMPILE_ACTION_NAME,
action_name = ACTION_NAMES.c_compile,
variables = compile_variables,
)
cc_cxx_args = cc_common.get_memory_inefficient_command_line(
feature_configuration = feature_configuration,
action_name = CPP_COMPILE_ACTION_NAME,
action_name = ACTION_NAMES.cpp_compile,
variables = compile_variables,
)
cc_env = cc_common.get_environment_variables(
feature_configuration = feature_configuration,
action_name = C_COMPILE_ACTION_NAME,
action_name = ACTION_NAMES.c_compile,
variables = compile_variables,
)
return cc_c_args, cc_cxx_args, cc_env
Expand Down Expand Up @@ -205,13 +205,18 @@ def _cargo_build_script_impl(ctx):
if cc_toolchain:
toolchain_tools.append(cc_toolchain.all_files)

cc_executable = cc_toolchain.compiler_executable
if cc_executable:
env["CC"] = cc_executable
env["CXX"] = cc_executable
ar_executable = cc_toolchain.ar_executable
if ar_executable:
env["AR"] = ar_executable
env["CC"] = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.c_compile,
)
env["CXX"] = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.cpp_compile,
)
env["AR"] = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.cpp_link_static_library,
)

# Populate CFLAGS and CXXFLAGS that cc-rs relies on when building from source, in particular
# to determine the deployment target when building for apple platforms (`macosx-version-min`
Expand Down

0 comments on commit a92de54

Please sign in to comment.