1load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library", "cc_test") 2load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_static_library") 3 4rust_static_library( 5 name = "rust_lib", 6 srcs = ["lib.rs"], 7 edition = "2021", 8) 9 10cc_library( 11 name = "c_lib", 12 srcs = ["lib.c"], 13 hdrs = ["lib.h"], 14 deps = [":rust_lib"], 15) 16 17# Tests that cc_shared_library correctly traverses into 18# `rust_static_library` when linking. 19cc_shared_library( 20 name = "shared", 21 deps = [":c_lib"], 22) 23 24cc_test( 25 name = "test", 26 srcs = ["main.c"], 27 dynamic_deps = [":shared"], 28 linkstatic = True, 29 deps = [":c_lib"], 30) 31 32NOT_WINDOWS = select({ 33 "@platforms//os:linux": [], 34 "@platforms//os:macos": [], 35 "//conditions:default": ["@platforms//:incompatible"], 36}) 37 38cc_import( 39 name = "shared_import", 40 shared_library = ":shared", 41 target_compatible_with = NOT_WINDOWS, 42) 43 44rust_binary( 45 name = "linked_against_shared", 46 srcs = ["linked_against_shared.rs"], 47 edition = "2018", 48 target_compatible_with = NOT_WINDOWS, 49 deps = [":shared_import"], 50) 51 52sh_test( 53 name = "runfiles_contains_shared", 54 srcs = ["runfiles_contains_shared.sh"], 55 data = [":linked_against_shared"], 56 target_compatible_with = NOT_WINDOWS, 57) 58