mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
This change marks all ABI-related structs with `structs.HostLayout`, which was introduced in Go 1.23: https://pkg.go.dev/[email protected]#HostLayout This is intended to force the Go compiler to preserve the layout of the struct, removing it from the liberty of reordering fields as it sees fit. Adds a check automatically generated by our `go_library` rule wrapper which verifies this recursively for all exported structs in a package. Fixes issue #10693. PiperOrigin-RevId: 860238103
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Defines go_host_layout_struct_test to generate host layout struct tests."""
|
|
|
|
def go_host_layout_struct_test(go_test_rule_func, name, srcs, library, **kwargs):
|
|
"""Checks that all structs in the given source file have _ structs.HostLayout as their first field.
|
|
|
|
Args:
|
|
go_test_rule_func: the go_test rule function to use.
|
|
name: the name of the test.
|
|
srcs: the source files to check.
|
|
library: the library that the source files belong to.
|
|
**kwargs: standard arguments.
|
|
"""
|
|
gen_file = name + "_generated.go"
|
|
|
|
native.genrule(
|
|
name = name + "_gen",
|
|
srcs = srcs + [library],
|
|
outs = [gen_file],
|
|
tools = ["//tools/go_hostlayout:hostlayoutgen"],
|
|
cmd = "$(location //tools/go_hostlayout:hostlayoutgen) -package " + library.replace(":", "/") + " -out $@ " + " ".join(["$(location %s)" % src for src in srcs]) + " -- $(locations " + library + ")",
|
|
)
|
|
|
|
go_test_rule_func(
|
|
name = name,
|
|
srcs = [gen_file],
|
|
deps = [
|
|
library,
|
|
"//tools/go_hostlayout/hostlayoutcheck",
|
|
],
|
|
**kwargs
|
|
)
|