1load("@rules_rust//rust:defs.bzl", "rust_binary") 2 3package(default_visibility = ["//visibility:public"]) 4 5filegroup( 6 name = "all", 7 srcs = [ 8 ":hello_world_aarch64", 9 ":hello_world_host", 10 ":hello_world_x86_64", 11 ], 12) 13 14rust_binary( 15 name = "hello_world_host", 16 srcs = ["src/main.rs"], 17 deps = [], 18) 19 20rust_binary( 21 name = "hello_world_x86_64", 22 srcs = ["src/main.rs"], 23 platform = "//build/platforms:linux-x86_64", 24 deps = [], 25) 26 27rust_binary( 28 name = "hello_world_aarch64", 29 srcs = ["src/main.rs"], 30 platform = "//build/platforms:linux-aarch64", 31 deps = [], 32) 33 34# Test if the host binary works. 35# Note, we cannot test for platform since Bazel determines the host platform automatically 36sh_test( 37 name = "test_hello_world_host", 38 srcs = ["test_hello_world.sh"], 39 args = [ 40 "$(rlocationpath :hello_world_host)", 41 ], 42 data = [ 43 ":hello_world_host", 44 ], 45 deps = [ 46 "@bazel_tools//tools/bash/runfiles", 47 ], 48) 49 50# Test the for x86_64 architecture 51sh_test( 52 name = "test_linux_x86_64", 53 srcs = ["test_platform.sh"], 54 args = [ 55 "$(rootpath :hello_world_x86_64)", 56 "x86_64", 57 ], 58 data = [ 59 ":hello_world_x86_64", 60 ], 61 deps = [ 62 "@bazel_tools//tools/bash/runfiles", 63 ], 64) 65 66# Test for ARM architecture 67sh_test( 68 name = "test_linux_arm64", 69 srcs = ["test_platform.sh"], 70 args = [ 71 "$(rootpath :hello_world_aarch64)", 72 "aarch64", 73 ], 74 data = [ 75 ":hello_world_aarch64", 76 ], 77 deps = [ 78 "@bazel_tools//tools/bash/runfiles", 79 ], 80) 81