mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
5c8136f48a
## Why We want to make it possible for an app-server orchestrator on one OS to control an exec-server on another host running a different OS. In practice this kinda already works if you get lucky and the two hosts have the same path format, but we mangle quite a lot of operations if either end is Windows. We should be able to test the cross-platform interactions for exec-server, but we want to do this fairly soon and need a lightweight option for testing. Using Wine to run the Windows side is far from perfect, but it should give us a decent measure of how well we're handling the basics of paths, process spawning, shell interaction, etc. Future changes will add actual exec-server tests and possibly extensions to the Wine testing environment. ## What To make the cross-target-triple build easy, these tests are added only to the Bazel build. This change adds an x86_64 Wine prebuilt managed by Bazel and some build rules that can set up the needed toolchain transition. The support library for running Wine in a test environment created by the Bazel rules comes with its own basic unit and integration tests. Their primary priority is to make sure we don't leak child processes on developer machines and that we can build and launch a basic hello world binary. ## Validation Confirmed these new tests are running on the [x86_64 bazel ubuntu jobs](https://github.com/openai/codex/actions/runs/27446432302/job/81132356855?pr=27937): ``` //bazel/rules/testing/wine:wine-smoke-test (cached) PASSED in 3.7s //bazel/rules/testing/wine:wine-test-support-unit-tests (cached) PASSED in 15.8s ```
77 lines
3.1 KiB
Python
77 lines
3.1 KiB
Python
"""Macros for cross-building Windows Rust binaries and testing them with Wine."""
|
|
|
|
load("@rules_rust//rust:defs.bzl", "rust_test")
|
|
load("//:defs.bzl", "WINDOWS_GNULLVM_RUSTC_LINK_FLAGS")
|
|
load(":foreign_platform_binary.bzl", "foreign_platform_binary")
|
|
|
|
_WINE_RUNTIME_BINARIES = {
|
|
"wine": "@wine_linux_x86_64//:wine",
|
|
"wine-runtime-marker": "@wine_linux_x86_64//:runtime_marker",
|
|
"wineserver": "@wine_linux_x86_64//:wineserver",
|
|
}
|
|
|
|
def wine_rust_test(
|
|
name,
|
|
windows_binaries,
|
|
data = [],
|
|
target_compatible_with = [],
|
|
**kwargs):
|
|
"""Defines an x86-64 Linux Rust test with a pinned Wine runtime.
|
|
|
|
Each `windows_binaries` executable is transitioned to GNU/LLVM Windows;
|
|
every Rust dependency receives the repository's Windows linker flags while
|
|
the test stays on x86-64 Linux. Its environment-variable contract is:
|
|
|
|
* Each entry contributes `CARGO_BIN_EXE_<binary_name>` for its executable.
|
|
* `CARGO_BIN_EXE_wine` and `CARGO_BIN_EXE_wineserver` identify Wine tools.
|
|
* `CARGO_BIN_EXE_wine-runtime-marker` identifies a file whose parent is the
|
|
Wine DLL directory to use as `WINEDLLPATH`.
|
|
|
|
These are Bazel runfile locations. Resolve binaries with
|
|
`codex_utils_cargo_bin::cargo_bin`; `:wine_test_support` resolves the fixed
|
|
runtime names and starts each process in an isolated prefix.
|
|
|
|
Args:
|
|
name: Name of the generated Linux `rust_test`.
|
|
windows_binaries: Map from `CARGO_BIN_EXE_*` suffixes to Windows targets.
|
|
data: Additional runtime data for the Linux test.
|
|
target_compatible_with: Additional compatibility constraints.
|
|
**kwargs: Remaining attributes forwarded to `rust_test`.
|
|
"""
|
|
binaries = dict(_WINE_RUNTIME_BINARIES)
|
|
for index, binary_name in enumerate(sorted(windows_binaries.keys())):
|
|
if binary_name in binaries:
|
|
fail("Windows test binary name collides with Wine runtime: {}".format(binary_name))
|
|
transitioned_binary = name + "-windows-binary-" + str(index)
|
|
foreign_platform_binary(
|
|
name = transitioned_binary,
|
|
binary = windows_binaries[binary_name],
|
|
extra_rustc_flags = WINDOWS_GNULLVM_RUSTC_LINK_FLAGS,
|
|
platform = "//:windows_x86_64_gnullvm",
|
|
tags = ["manual"],
|
|
target_compatible_with = [
|
|
"@platforms//cpu:x86_64",
|
|
"@platforms//os:linux",
|
|
],
|
|
testonly = True,
|
|
visibility = ["//visibility:private"],
|
|
)
|
|
binaries[binary_name] = ":" + transitioned_binary
|
|
|
|
rust_test(
|
|
name = name,
|
|
data = data + [
|
|
"@wine_linux_x86_64//:runtime",
|
|
] + [binary for binary in binaries.values()],
|
|
env = {
|
|
"CARGO_BIN_EXE_{}".format(binary_name): "$(rlocationpath {})".format(binary)
|
|
for binary_name, binary in binaries.items()
|
|
},
|
|
target_compatible_with = target_compatible_with + [
|
|
"@llvm//constraints/libc:gnu.2.28",
|
|
"@platforms//cpu:x86_64",
|
|
"@platforms//os:linux",
|
|
],
|
|
**kwargs
|
|
)
|