Fix #1161: set the `CMAKE` environment variables for prebuilt toolchains. (#1163)

This commit is contained in:
thomas 2024-03-13 15:29:36 +01:00 committed by GitHub
parent 5547abc63b
commit cecdab091e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 397 additions and 373 deletions

View File

@ -19,7 +19,7 @@ ToolInfo = provider(
},
)
def _resolve_tool_path(ctx, path, target):
def _resolve_tool_path(ctx, path, target, tools):
"""
Resolve the path to a tool.
@ -32,7 +32,7 @@ def _resolve_tool_path(ctx, path, target):
_, resolved_bash_command, _ = ctx.resolve_command(
command = path,
expand_locations = True,
tools = [target],
tools = tools + [target],
)
return resolved_bash_command[-1]
@ -43,10 +43,10 @@ def _native_tool_toolchain_impl(ctx):
path = None
env = {}
if ctx.attr.target:
path = _resolve_tool_path(ctx, ctx.attr.path, ctx.attr.target)
path = _resolve_tool_path(ctx, ctx.attr.path, ctx.attr.target, ctx.attr.tools)
for k, v in ctx.attr.env.items():
env[k] = _resolve_tool_path(ctx, v, ctx.attr.target)
env[k] = _resolve_tool_path(ctx, v, ctx.attr.target, ctx.attr.tools)
else:
path = ctx.expand_location(ctx.attr.path)
@ -88,6 +88,16 @@ native_tool_toolchain = rule(
),
allow_files = True,
),
"tools": attr.label_list(
mandatory = False,
cfg = "exec",
doc = (
"Additional tools." +
"If `target` expands to several files, `tools` can be used to " +
"isolate a specific file that can be used in `env`."
),
allow_files = True,
),
},
incompatible_use_toolchain_transition = True,
)

File diff suppressed because it is too large Load Diff

View File

@ -211,6 +211,11 @@ load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "n
package(default_visibility = ["//visibility:public"])
filegroup(
name = "cmake_bin",
srcs = ["bin/{{bin}}"],
)
filegroup(
name = "cmake_data",
srcs = glob(
@ -230,6 +235,8 @@ native_tool_toolchain(
name = "cmake_tool",
path = "bin/{{bin}}",
target = ":cmake_data",
env = {{env}},
tools = [":cmake_bin"],
)
\"\"\"
@ -338,7 +345,7 @@ def get_cmake_definitions() -> str:
build="cmake",
template="_CMAKE_BUILD_FILE",
bin=bin,
env="{}",
env='{\\"CMAKE\\": \\"$(execpath :cmake_bin)\\"}',
)
)
version_toolchains.update({plat_target: name})