1*d4726bddSHONG Yifanload("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2*d4726bddSHONG Yifanload("@cui//:defs.bzl", "aliases", "all_crate_deps") 3*d4726bddSHONG Yifanload("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test", "rust_library", "rust_test") 4*d4726bddSHONG Yifanload("//crate_universe:version.bzl", "VERSION") 5*d4726bddSHONG Yifan 6*d4726bddSHONG Yifanexports_files( 7*d4726bddSHONG Yifan glob([ 8*d4726bddSHONG Yifan "src/**/*.bzl", 9*d4726bddSHONG Yifan "src/**/*.j2", 10*d4726bddSHONG Yifan "src/**/*.rs", 11*d4726bddSHONG Yifan ]) + [ 12*d4726bddSHONG Yifan "Cargo.toml", 13*d4726bddSHONG Yifan "Cargo.lock", 14*d4726bddSHONG Yifan "defs.bzl", 15*d4726bddSHONG Yifan "docs_bzlmod.bzl", 16*d4726bddSHONG Yifan "docs_workspace.bzl", 17*d4726bddSHONG Yifan ], 18*d4726bddSHONG Yifan visibility = ["//visibility:public"], 19*d4726bddSHONG Yifan) 20*d4726bddSHONG Yifan 21*d4726bddSHONG Yifanfilegroup( 22*d4726bddSHONG Yifan name = "bzl_srcs", 23*d4726bddSHONG Yifan srcs = glob(["*.bzl"]) + [ 24*d4726bddSHONG Yifan "//crate_universe/3rdparty:bzl_srcs", 25*d4726bddSHONG Yifan "//crate_universe/private:bzl_srcs", 26*d4726bddSHONG Yifan "//crate_universe/tools:bzl_srcs", 27*d4726bddSHONG Yifan ], 28*d4726bddSHONG Yifan visibility = ["//visibility:public"], 29*d4726bddSHONG Yifan) 30*d4726bddSHONG Yifan 31*d4726bddSHONG Yifanbzl_library( 32*d4726bddSHONG Yifan name = "bzl_lib", 33*d4726bddSHONG Yifan srcs = [":bzl_srcs"], 34*d4726bddSHONG Yifan visibility = ["//visibility:public"], 35*d4726bddSHONG Yifan deps = ["//rust:bzl_lib"], 36*d4726bddSHONG Yifan) 37*d4726bddSHONG Yifan 38*d4726bddSHONG Yifanfilegroup( 39*d4726bddSHONG Yifan name = "rust_srcs", 40*d4726bddSHONG Yifan srcs = glob([ 41*d4726bddSHONG Yifan "src/**/*.bzl", 42*d4726bddSHONG Yifan "src/**/*.j2", 43*d4726bddSHONG Yifan "src/**/*.rs", 44*d4726bddSHONG Yifan ]), 45*d4726bddSHONG Yifan visibility = ["//:__subpackages__"], 46*d4726bddSHONG Yifan) 47*d4726bddSHONG Yifan 48*d4726bddSHONG Yifanrust_library( 49*d4726bddSHONG Yifan name = "cargo_bazel", 50*d4726bddSHONG Yifan srcs = glob( 51*d4726bddSHONG Yifan include = ["src/**/*.rs"], 52*d4726bddSHONG Yifan exclude = ["src/main.rs"], 53*d4726bddSHONG Yifan ), 54*d4726bddSHONG Yifan aliases = aliases(), 55*d4726bddSHONG Yifan compile_data = glob( 56*d4726bddSHONG Yifan include = ["src/**"], 57*d4726bddSHONG Yifan exclude = ["src/**/*.rs"], 58*d4726bddSHONG Yifan ), 59*d4726bddSHONG Yifan edition = "2021", 60*d4726bddSHONG Yifan proc_macro_deps = all_crate_deps(proc_macro = True), 61*d4726bddSHONG Yifan # This target embeds additional, stamping related information (see 62*d4726bddSHONG Yifan # https://docs.bazel.build/versions/main/user-manual.html#workspace_status 63*d4726bddSHONG Yifan # for more information). Set stamp = -1 to indicate that it should respect 64*d4726bddSHONG Yifan # the value of the --stamp comandline flag. 65*d4726bddSHONG Yifan stamp = -1, 66*d4726bddSHONG Yifan version = VERSION, 67*d4726bddSHONG Yifan visibility = ["//visibility:public"], 68*d4726bddSHONG Yifan deps = all_crate_deps(normal = True), 69*d4726bddSHONG Yifan) 70*d4726bddSHONG Yifan 71*d4726bddSHONG Yifanrust_binary( 72*d4726bddSHONG Yifan name = "cargo_bazel_bin", 73*d4726bddSHONG Yifan srcs = ["src/main.rs"], 74*d4726bddSHONG Yifan edition = "2021", 75*d4726bddSHONG Yifan version = VERSION, 76*d4726bddSHONG Yifan visibility = ["//visibility:public"], 77*d4726bddSHONG Yifan deps = [":cargo_bazel"], 78*d4726bddSHONG Yifan) 79*d4726bddSHONG Yifan 80*d4726bddSHONG Yifanalias( 81*d4726bddSHONG Yifan name = "bin", 82*d4726bddSHONG Yifan actual = ":cargo_bazel_bin", 83*d4726bddSHONG Yifan visibility = ["//visibility:public"], 84*d4726bddSHONG Yifan) 85*d4726bddSHONG Yifan 86*d4726bddSHONG Yifanrust_test( 87*d4726bddSHONG Yifan name = "unit_test", 88*d4726bddSHONG Yifan aliases = aliases(), 89*d4726bddSHONG Yifan crate = ":cargo_bazel", 90*d4726bddSHONG Yifan data = glob(["test_data/**"]) + [ 91*d4726bddSHONG Yifan "//crate_universe/test_data/serialized_configs", 92*d4726bddSHONG Yifan "@rules_rust//rust/toolchain:current_cargo_files", 93*d4726bddSHONG Yifan "@rules_rust//rust/toolchain:current_rustc_files", 94*d4726bddSHONG Yifan ], 95*d4726bddSHONG Yifan proc_macro_deps = all_crate_deps( 96*d4726bddSHONG Yifan proc_macro_dev = True, 97*d4726bddSHONG Yifan ), 98*d4726bddSHONG Yifan rustc_env = { 99*d4726bddSHONG Yifan "CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)", 100*d4726bddSHONG Yifan "RUSTC": "$(rootpath @rules_rust//rust/toolchain:current_rustc_files)", 101*d4726bddSHONG Yifan }, 102*d4726bddSHONG Yifan deps = [ 103*d4726bddSHONG Yifan "@rules_rust//tools/runfiles", 104*d4726bddSHONG Yifan ] + all_crate_deps( 105*d4726bddSHONG Yifan normal_dev = True, 106*d4726bddSHONG Yifan ), 107*d4726bddSHONG Yifan) 108*d4726bddSHONG Yifan 109*d4726bddSHONG Yifan# Integration tests which invoke cargo and/or rustc as subprocesses. 110*d4726bddSHONG Yifanrust_test( 111*d4726bddSHONG Yifan name = "cargo_integration_test", 112*d4726bddSHONG Yifan timeout = "long", 113*d4726bddSHONG Yifan srcs = ["tests/cargo_integration_test.rs"], 114*d4726bddSHONG Yifan aliases = aliases(), 115*d4726bddSHONG Yifan data = glob(["test_data/**"]) + [ 116*d4726bddSHONG Yifan "//crate_universe/test_data/serialized_configs", 117*d4726bddSHONG Yifan "@rules_rust//rust/toolchain:current_cargo_files", 118*d4726bddSHONG Yifan "@rules_rust//rust/toolchain:current_rustc_files", 119*d4726bddSHONG Yifan ], 120*d4726bddSHONG Yifan edition = "2021", 121*d4726bddSHONG Yifan env = { 122*d4726bddSHONG Yifan "CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)", 123*d4726bddSHONG Yifan "RUSTC": "$(rootpath @rules_rust//rust/toolchain:current_rustc_files)", 124*d4726bddSHONG Yifan }, 125*d4726bddSHONG Yifan proc_macro_deps = all_crate_deps( 126*d4726bddSHONG Yifan proc_macro_dev = True, 127*d4726bddSHONG Yifan ), 128*d4726bddSHONG Yifan rustc_env = { 129*d4726bddSHONG Yifan "CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)", 130*d4726bddSHONG Yifan "RUSTC": "$(rootpath @rules_rust//rust/toolchain:current_rustc_files)", 131*d4726bddSHONG Yifan }, 132*d4726bddSHONG Yifan tags = ["requires-network"], 133*d4726bddSHONG Yifan deps = [ 134*d4726bddSHONG Yifan ":cargo_bazel", 135*d4726bddSHONG Yifan "@rules_rust//tools/runfiles", 136*d4726bddSHONG Yifan ] + all_crate_deps( 137*d4726bddSHONG Yifan normal = True, 138*d4726bddSHONG Yifan ), 139*d4726bddSHONG Yifan) 140*d4726bddSHONG Yifan 141*d4726bddSHONG Yifanrust_test( 142*d4726bddSHONG Yifan name = "versions_test", 143*d4726bddSHONG Yifan srcs = ["tests/version_test.rs"], 144*d4726bddSHONG Yifan data = [ 145*d4726bddSHONG Yifan "Cargo.toml", 146*d4726bddSHONG Yifan "version.bzl", 147*d4726bddSHONG Yifan ], 148*d4726bddSHONG Yifan edition = "2021", 149*d4726bddSHONG Yifan rustc_env = { 150*d4726bddSHONG Yifan "CARGO_TOML": "$(rootpath :Cargo.toml)", 151*d4726bddSHONG Yifan "VERSION_BZL": "$(rootpath :version.bzl)", 152*d4726bddSHONG Yifan }, 153*d4726bddSHONG Yifan) 154*d4726bddSHONG Yifan 155*d4726bddSHONG Yifanrust_doc( 156*d4726bddSHONG Yifan name = "rustdoc", 157*d4726bddSHONG Yifan crate = ":cargo_bazel", 158*d4726bddSHONG Yifan rustdoc_flags = [ 159*d4726bddSHONG Yifan "--cap-lints=warn", 160*d4726bddSHONG Yifan "--document-private-items", 161*d4726bddSHONG Yifan "--allow=rustdoc::private_intra_doc_links", 162*d4726bddSHONG Yifan ], 163*d4726bddSHONG Yifan visibility = ["//visibility:public"], 164*d4726bddSHONG Yifan) 165*d4726bddSHONG Yifan 166*d4726bddSHONG Yifanrust_doc_test( 167*d4726bddSHONG Yifan name = "rustdoc_test", 168*d4726bddSHONG Yifan crate = ":cargo_bazel", 169*d4726bddSHONG Yifan) 170