Files
codex/third_party/voice/runtime.bzl
Benjamin Carlsson 1c40ffe427 Add Windows MSVC Bazel targets for native voice libraries (#43144)
## What changed

- Add explicit x64 and ARM64 targets for native builds, runtime preparation, and linking using the existing voice recipes. Each target requires native Windows execution of the matching architecture.
- Declare compiler, SDK, Python, and CMake inputs; require an explicitly supplied Cygwin/pkgconf tool tree and a fixed `SystemRoot`. Validate installed tool selections against the manifest and declared files.
- Pair Windows DLLs with SDK import libraries, preserve plugin and receipt runfiles, and omit Unix runtime-search flags. Use Python for portable payload copying.
- Correct the MSVC ARM64 tool directory casing to `HostArm64` and document provisioning and build commands.

The generic Rust-consumer aliases remain separate; native Windows Bazel execution and consumer validation are still needed to establish complete Windows voice support.

## Testing

Add eight unit tests covering tool selection, path anchoring, invalid inputs, and DLL/import-library copying, plus x64 and ARM64 link smoke targets that reference `gst_version`.

GitOrigin-RevId: fb2b4998e9ffb5b64ca830ebf4bb4633fc959eb9
2026-09-06 02:14:05 +00:00

81 lines
3.5 KiB
Python

"""Prepare build-produced native libraries with the existing platform policy."""
load("@rules_python//python:py_runtime_info.bzl", "PyRuntimeInfo")
load(":windows_native.bzl", "WindowsBuildToolsInfo")
def _native_runtime_impl(ctx):
python = ctx.attr._python[PyRuntimeInfo]
prefix = ctx.attr.prefix[DefaultInfo].files.to_list()[0]
receipt = ctx.attr.prefix[OutputGroupInfo].receipt.to_list()[0]
output = ctx.actions.declare_directory(ctx.label.name)
sdk = ctx.actions.declare_directory(ctx.label.name + "_sdk")
if ctx.attr.windows_tools:
tools = ctx.attr.windows_tools[WindowsBuildToolsInfo]
if tools.inputs["target"] != ctx.attr.target:
fail("Windows runtime target must match its declared native tools")
config = ctx.actions.declare_file(ctx.label.name + ".json")
ctx.actions.write(config, json.encode({
"inputs": tools.inputs,
"manifest": tools.manifest.path,
"installed_files": [file.path for file in tools.installed_files],
"prefix": prefix.path,
"receipt": receipt.path,
"status": ctx.info_file.path,
"output": output.path,
"sdk": sdk.path,
}))
ctx.actions.run(
executable = tools.python.interpreter,
arguments = [ctx.file._windows_driver.path, "prepare", config.path],
inputs = depset([config, prefix, receipt, ctx.info_file, ctx.file._driver, ctx.file._windows_driver] + ctx.files._preparers, transitive = [tools.files]),
outputs = [output, sdk],
env = tools.environment,
execution_requirements = {"no-remote-exec": "1"},
mnemonic = "VoiceWindowsRuntime",
)
return [DefaultInfo(files = depset([output])), OutputGroupInfo(sdk = depset([sdk]))]
ctx.actions.run(
executable = python.interpreter,
arguments = [
ctx.file._driver.path,
"--prefix",
prefix.path,
"--build-receipt",
receipt.path,
"--status",
ctx.info_file.path,
"--target",
ctx.attr.target,
"--output",
output.path,
"--sdk-output",
sdk.path,
],
inputs = depset(
[prefix, receipt, ctx.info_file, ctx.file._driver, python.interpreter] + ctx.files._preparers,
transitive = [python.files],
),
outputs = [output, sdk],
env = {"PATH": "/usr/bin:/bin", "LC_ALL": "C"},
execution_requirements = {"no-remote-exec": "1", "no-remote-cache": "1"} if ctx.attr.target.endswith("apple-darwin") else {},
mnemonic = "VoiceNativeRuntime",
progress_message = "Preparing private voice runtime for " + ctx.attr.target,
)
return [
DefaultInfo(files = depset([output])),
OutputGroupInfo(sdk = depset([sdk])),
]
native_runtime = rule(
implementation = _native_runtime_impl,
attrs = {
"prefix": attr.label(mandatory = True, allow_single_file = True),
"target": attr.string(mandatory = True),
"windows_tools": attr.label(cfg = "exec", providers = [WindowsBuildToolsInfo]),
"_windows_driver": attr.label(default = "//third_party/voice:bazel_windows.py", allow_single_file = True),
"_driver": attr.label(default = "//third_party/voice:prepare_built_runtime.py", allow_single_file = True),
"_preparers": attr.label(default = "//third_party/voice:build_inputs"),
"_python": attr.label(default = "@python_3_12//:py3_runtime", cfg = "exec"),
},
)