File
Blob: build/kj_test.bzl
| 1 | load("@rules_cc//cc:cc_binary.bzl", "cc_binary") |
| 2 | load("@rules_shell//shell:sh_test.bzl", "sh_test") |
| 3 | |
| 4 | def kj_test( |
| 5 | src, |
| 6 | data = [], |
| 7 | deps = [], |
| 8 | tags = [], |
| 9 | size = "medium", |
| 10 | **kwargs): |
| 11 | test_name = src.removesuffix(".c++") |
| 12 | binary_name = test_name + "_binary" |
| 13 | cc_binary( |
| 14 | name = binary_name, |
| 15 | testonly = True, |
| 16 | srcs = [src], |
| 17 | deps = [ |
| 18 | "@capnp-cpp//src/kj:kj-test", |
| 19 | ] + deps, |
| 20 | linkstatic = select({ |
| 21 | "@platforms//os:linux": 0, |
| 22 | "//conditions:default": 1, |
| 23 | }), |
| 24 | # For test binaries, reduce thinLTO optimizations and inlining to speed up linking. This |
| 25 | # only has an effect if thinLTO is enabled. Also apply dead_strip on macOS to manage binary |
| 26 | # sizes. |
| 27 | linkopts = select({ |
| 28 | "@platforms//os:linux": ["-Wl,--lto-O1", "-Wl,-mllvm,-import-instr-limit=5"], |
| 29 | "@//:use_dead_strip": ["-Wl,-dead_strip", "-Wl,-no_exported_symbols"], |
| 30 | "//conditions:default": [""], |
| 31 | }), |
| 32 | data = data, |
| 33 | tags = tags, |
| 34 | target_compatible_with = select({ |
| 35 | "@//build/config:no_build": ["@platforms//:incompatible"], |
| 36 | "//conditions:default": [], |
| 37 | }), |
| 38 | **kwargs |
| 39 | ) |
| 40 | |
| 41 | pkg = native.package_name() |
| 42 | cross_alias = binary_name + "_cross" |
| 43 | native.alias( |
| 44 | name = cross_alias, |
| 45 | actual = select({ |
| 46 | "@//build/config:prebuilt_binaries_arm64": "@//:bin.arm64/tmp/workerd/{}/{}.aarch64-linux-gnu".format(pkg, binary_name), |
| 47 | "//conditions:default": binary_name, |
| 48 | }), |
| 49 | ) |
| 50 | |
| 51 | sh_test( |
| 52 | name = test_name + "@", |
| 53 | srcs = ["//build/fixtures:kj_test.sh"], |
| 54 | args = ["$(location {})".format(cross_alias)], |
| 55 | data = data + [cross_alias], |
| 56 | tags = tags, |
| 57 | size = size, |
| 58 | ) |
| 59 | |
| 60 | sh_test( |
| 61 | name = test_name + "@all-autogates", |
| 62 | srcs = ["//build/fixtures:kj_test.sh"], |
| 63 | args = ["$(location {})".format(cross_alias)], |
| 64 | data = data + [cross_alias], |
| 65 | env = {"WORKERD_ALL_AUTOGATES": "1"}, |
| 66 | # Tag with no-coverage to reduce coverage CI time |
| 67 | tags = tags + ["no-coverage"], |
| 68 | size = size, |
| 69 | ) |