1"""Analysis tests for exporting the Windows interface library.""" 2 3load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 4load("@rules_cc//cc:defs.bzl", "cc_binary") 5load("//rust:defs.bzl", "rust_binary", "rust_shared_library") 6 7def _win_interface_library_test_impl(ctx): 8 env = analysistest.begin(ctx) 9 target = analysistest.target_under_test(env) 10 11 files = target[DefaultInfo].files.to_list() 12 cc_library = target[CcInfo].linking_context.linker_inputs.to_list()[0].libraries[0] 13 14 # Make sure that we have both the `.dll` and the `.dll.lib` file in the default info's files 15 asserts.equals(env, len(files), 2) 16 asserts.true(env, files[0].basename.endswith(".dll")) 17 asserts.true(env, files[1].basename.endswith(".dll.lib")) 18 19 # Make sure that the cc_library has both a dynamic and interface library 20 asserts.true(env, cc_library.dynamic_library != None) 21 asserts.true(env, cc_library.interface_library != None) 22 23 return analysistest.end(env) 24 25win_interface_library_test = analysistest.make(_win_interface_library_test_impl) 26 27def win_interface_library_analysis_test_suite(name): 28 """Analysis tests for exporting the Windows interface library. 29 30 Args: 31 name: the test suite name 32 """ 33 rust_shared_library( 34 name = "mylib", 35 srcs = ["lib.rs"], 36 edition = "2018", 37 target_compatible_with = ["@platforms//os:windows"], 38 ) 39 40 cc_binary( 41 name = "mybin", 42 srcs = ["bin.cc"], 43 deps = [":mylib"], 44 target_compatible_with = ["@platforms//os:windows"], 45 ) 46 47 rust_binary( 48 name = "myrustbin", 49 srcs = ["main.rs"], 50 edition = "2018", 51 target_compatible_with = ["@platforms//os:windows"], 52 ) 53 54 win_interface_library_test( 55 name = "win_interface_library_test", 56 target_under_test = ":mylib", 57 target_compatible_with = ["@platforms//os:windows"], 58 ) 59 60 native.test_suite( 61 name = name, 62 tests = [":win_interface_library_test"], 63 ) 64