Damien Martin-Guillerez | ca407f0 | 2016-07-04 13:07:08 +0000 | [diff] [blame] | 1 | filegroup( |
| 2 | name = "srcs", |
| 3 | srcs = glob(["**"]), |
| 4 | visibility = ["//examples:__pkg__"], |
| 5 | ) |
| 6 | |
Yun Peng | a65ce6d | 2019-02-12 01:41:08 -0800 | [diff] [blame] | 7 | cc_library( |
| 8 | name = "hello-library-header", |
| 9 | hdrs = ["hello-library.h"], |
| 10 | ) |
| 11 | |
Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 12 | cc_binary( |
| 13 | name = "hellolib.dll", |
| 14 | srcs = [ |
| 15 | "hello-library.cpp", |
| 16 | ], |
Yun Peng | a65ce6d | 2019-02-12 01:41:08 -0800 | [diff] [blame] | 17 | # Define COMPILING_DLL to export symbols during compiling the DLL. |
| 18 | # See hello-library.h |
| 19 | copts = ["/DCOMPILING_DLL"], |
Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 20 | linkshared = 1, |
Yun Peng | a65ce6d | 2019-02-12 01:41:08 -0800 | [diff] [blame] | 21 | deps = [ |
| 22 | ":hello-library-header", |
| 23 | ], |
| 24 | ) |
| 25 | |
| 26 | # **Explicitly link to hellolib.dll** |
| 27 | |
| 28 | # Declare hellolib.dll as data dependency and load it explicitly in code. |
| 29 | cc_binary( |
| 30 | name = "hello_world-load-dll-at-runtime", |
| 31 | srcs = [ |
| 32 | "hello_world-load-dll-at-runtime.cpp", |
| 33 | ], |
| 34 | data = [":hellolib.dll"], |
| 35 | ) |
| 36 | |
| 37 | # **Implicitly link to hellolib.dll** |
| 38 | |
| 39 | # Get the import library for hellolib.dll |
| 40 | filegroup( |
| 41 | name = "hello_lib_import_lib", |
| 42 | srcs = [":hellolib.dll"], |
| 43 | output_group = "interface_library", |
| 44 | ) |
| 45 | |
| 46 | # Because we cannot directly depend on cc_binary from other cc rules in deps attribute, |
| 47 | # we use cc_import as a bridge to depend on hellolib.dll |
| 48 | cc_import( |
| 49 | name = "hellolib_dll_import", |
| 50 | interface_library = ":hello_lib_import_lib", |
| 51 | shared_library = ":hellolib.dll", |
| 52 | ) |
| 53 | |
| 54 | # Create a new cc_library to also include the headers needed for hellolib.dll |
| 55 | cc_library( |
| 56 | name = "hellolib_dll", |
| 57 | deps = [ |
| 58 | ":hello-library-header", |
| 59 | ":hellolib_dll_import", |
| 60 | ], |
Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 61 | ) |
| 62 | |
| 63 | cc_binary( |
Yun Peng | a65ce6d | 2019-02-12 01:41:08 -0800 | [diff] [blame] | 64 | name = "hello_world-link-to-dll-via-lib", |
Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 65 | srcs = [ |
Yun Peng | a65ce6d | 2019-02-12 01:41:08 -0800 | [diff] [blame] | 66 | "hello_world-link-to-dll-via-lib.cpp", |
Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 67 | ], |
Yun Peng | a65ce6d | 2019-02-12 01:41:08 -0800 | [diff] [blame] | 68 | deps = [":hellolib_dll"], |
Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 69 | ) |