blob: 588eef472f7f488e209d7ddd664f3196e8735115 [file] [log] [blame]
Damien Martin-Guillerezca407f02016-07-04 13:07:08 +00001filegroup(
2 name = "srcs",
3 srcs = glob(["**"]),
4 visibility = ["//examples:__pkg__"],
5)
6
Yun Penga65ce6d2019-02-12 01:41:08 -08007cc_library(
8 name = "hello-library-header",
9 hdrs = ["hello-library.h"],
10)
11
Yun Penga93e9de2016-06-30 14:27:38 +000012cc_binary(
13 name = "hellolib.dll",
14 srcs = [
15 "hello-library.cpp",
16 ],
Yun Penga65ce6d2019-02-12 01:41:08 -080017 # Define COMPILING_DLL to export symbols during compiling the DLL.
18 # See hello-library.h
19 copts = ["/DCOMPILING_DLL"],
Yun Penga93e9de2016-06-30 14:27:38 +000020 linkshared = 1,
Yun Penga65ce6d2019-02-12 01:41:08 -080021 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.
29cc_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
40filegroup(
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
48cc_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
55cc_library(
56 name = "hellolib_dll",
57 deps = [
58 ":hello-library-header",
59 ":hellolib_dll_import",
60 ],
Yun Penga93e9de2016-06-30 14:27:38 +000061)
62
63cc_binary(
Yun Penga65ce6d2019-02-12 01:41:08 -080064 name = "hello_world-link-to-dll-via-lib",
Yun Penga93e9de2016-06-30 14:27:38 +000065 srcs = [
Yun Penga65ce6d2019-02-12 01:41:08 -080066 "hello_world-link-to-dll-via-lib.cpp",
Yun Penga93e9de2016-06-30 14:27:38 +000067 ],
Yun Penga65ce6d2019-02-12 01:41:08 -080068 deps = [":hellolib_dll"],
Yun Penga93e9de2016-06-30 14:27:38 +000069)