Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,22 @@ def _cargo_build_script_impl(ctx):
env["LDFLAGS"] = " ".join(_pwd_flags(link_args))

# Defaults for cxx flags.
env["CC"] = "${{pwd}}/{}".format(ctx.executable._fallback_cc.path)
env["CXX"] = "${{pwd}}/{}".format(ctx.executable._fallback_cxx.path)
env["AR"] = "${{pwd}}/{}".format(ctx.executable._fallback_ar.path)
env["ARFLAGS"] = ""
env["CFLAGS"] = ""
env["CXXFLAGS"] = ""
fallback_tools = []
if not cc_toolchain:
fallbacks = {
"AR": "_fallback_ar",
"CC": "_fallback_cc",
"CXX": "_fallback_cxx",
}
for key, attr in fallbacks.items():
tool = getattr(ctx.executable, attr)
if not tool:
fail("cargo_build_script without a cc toolchain requires %s" % attr)
fallback_tools.append(tool)
env[key] = "${{pwd}}/{}".format(tool.path)

if cc_toolchain:
# MSVC requires INCLUDE to be set
Expand Down Expand Up @@ -516,10 +526,7 @@ def _cargo_build_script_impl(ctx):
direct = [
script,
ctx.executable._cargo_build_script_runner,
ctx.executable._fallback_cc,
ctx.executable._fallback_cxx,
ctx.executable._fallback_ar,
] + ([toolchain.target_json] if toolchain.target_json else []),
] + fallback_tools + ([toolchain.target_json] if toolchain.target_json else []),
transitive = script_data + script_tools + toolchain_tools,
)

Expand Down Expand Up @@ -744,16 +751,19 @@ cargo_build_script = rule(
"_fallback_ar": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = Label("//cargo/private:no_ar"),
),
"_fallback_cc": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = Label("//cargo/private:no_cc"),
),
"_fallback_cxx": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = Label("//cargo/private:no_cxx"),
),
"_incompatible_runfiles_cargo_manifest_dir": attr.label(
Expand Down