|
| 1 | +load("//examples/windows/dll:windows_dll_library.bzl", "windows_dll_library") |
| 2 | + |
1 | 3 | filegroup( |
2 | 4 | name = "srcs", |
3 | 5 | srcs = glob(["**"]), |
4 | 6 | visibility = ["//examples:__pkg__"], |
5 | 7 | ) |
6 | 8 |
|
7 | | -cc_library( |
8 | | - name = "hello-library-header", |
| 9 | +# Define the shared library |
| 10 | +windows_dll_library( |
| 11 | + name = "hellolib", |
| 12 | + srcs = ["hello-library.cpp"], |
9 | 13 | hdrs = ["hello-library.h"], |
10 | | -) |
11 | | - |
12 | | -cc_binary( |
13 | | - name = "hellolib.dll", |
14 | | - srcs = [ |
15 | | - "hello-library.cpp", |
16 | | - ], |
17 | 14 | # Define COMPILING_DLL to export symbols during compiling the DLL. |
18 | 15 | # See hello-library.h |
19 | 16 | copts = ["/DCOMPILING_DLL"], |
20 | | - linkshared = 1, |
21 | | - deps = [ |
22 | | - ":hello-library-header", |
23 | | - ], |
24 | 17 | ) |
25 | 18 |
|
26 | 19 | # **Explicitly link to hellolib.dll** |
27 | 20 |
|
28 | | -# Declare hellolib.dll as data dependency and load it explicitly in code. |
| 21 | +## Declare hellolib.dll as data dependency and load it explicitly in code. |
29 | 22 | cc_binary( |
30 | 23 | name = "hello_world-load-dll-at-runtime", |
31 | | - srcs = [ |
32 | | - "hello_world-load-dll-at-runtime.cpp", |
33 | | - ], |
| 24 | + srcs = ["hello_world-load-dll-at-runtime.cpp"], |
34 | 25 | data = [":hellolib.dll"], |
35 | 26 | ) |
36 | 27 |
|
37 | 28 | # **Implicitly link to hellolib.dll** |
38 | 29 |
|
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 | | - ], |
61 | | -) |
62 | | - |
| 30 | +## Link to hellolib.dll through its import library. |
63 | 31 | cc_binary( |
64 | 32 | name = "hello_world-link-to-dll-via-lib", |
65 | | - srcs = [ |
66 | | - "hello_world-link-to-dll-via-lib.cpp", |
67 | | - ], |
68 | | - deps = [":hellolib_dll"], |
| 33 | + srcs = ["hello_world-link-to-dll-via-lib.cpp"], |
| 34 | + deps = [":hellolib"], |
69 | 35 | ) |
0 commit comments