1*d4726bddSHONG Yifanload("@rules_rust//cargo:defs.bzl", "cargo_build_script") 2*d4726bddSHONG Yifanload("@rules_rust//rust:defs.bzl", "rust_test") 3*d4726bddSHONG Yifan 4*d4726bddSHONG Yifan# generate a file 5*d4726bddSHONG Yifangenrule( 6*d4726bddSHONG Yifan name = "data_generator", 7*d4726bddSHONG Yifan outs = ["generated.data"], 8*d4726bddSHONG Yifan cmd = "echo hello > $@", 9*d4726bddSHONG Yifan) 10*d4726bddSHONG Yifan 11*d4726bddSHONG Yifan_data = [ 12*d4726bddSHONG Yifan # we should be able to read non-generated source/data files 13*d4726bddSHONG Yifan "source.file", 14*d4726bddSHONG Yifan # and generated files as well 15*d4726bddSHONG Yifan "generated.data", 16*d4726bddSHONG Yifan # we should also be able to access external binaries 17*d4726bddSHONG Yifan # such as protoc. 18*d4726bddSHONG Yifan "@com_google_protobuf//:protoc", 19*d4726bddSHONG Yifan] 20*d4726bddSHONG Yifan 21*d4726bddSHONG Yifancargo_build_script( 22*d4726bddSHONG Yifan name = "build", 23*d4726bddSHONG Yifan srcs = ["build.rs"], 24*d4726bddSHONG Yifan build_script_env = { 25*d4726bddSHONG Yifan "GENERATED_DATA": "$(location generated.data)", 26*d4726bddSHONG Yifan "SOME_TOOL": "$(execpath @com_google_protobuf//:protoc)", 27*d4726bddSHONG Yifan # both execpath and location should work 28*d4726bddSHONG Yifan "SOURCE_FILE": "$(execpath source.file)", 29*d4726bddSHONG Yifan }, 30*d4726bddSHONG Yifan data = _data, 31*d4726bddSHONG Yifan) 32*d4726bddSHONG Yifan 33*d4726bddSHONG Yifanrust_test( 34*d4726bddSHONG Yifan name = "test", 35*d4726bddSHONG Yifan srcs = [ 36*d4726bddSHONG Yifan "main.rs", 37*d4726bddSHONG Yifan ], 38*d4726bddSHONG Yifan data = _data, 39*d4726bddSHONG Yifan edition = "2018", 40*d4726bddSHONG Yifan rustc_env = { 41*d4726bddSHONG Yifan "GENERATED_DATA_ABS": "$(execpath generated.data)", 42*d4726bddSHONG Yifan "GENERATED_DATA_ROOT": "$(rootpath generated.data)", 43*d4726bddSHONG Yifan "SOME_TOOL": "$(rootpath @com_google_protobuf//:protoc)", 44*d4726bddSHONG Yifan "SOURCE_FILE": "$(rootpath source.file)", 45*d4726bddSHONG Yifan }, 46*d4726bddSHONG Yifan deps = [ 47*d4726bddSHONG Yifan ":build", 48*d4726bddSHONG Yifan ], 49*d4726bddSHONG Yifan) 50