pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/bazelbuild/bazel/commit/c07188a30d8cdd71d79bba408ddb0b3234a8718f

e157469407.css" /> Refactor building DLL example on Windows with windows_dll_library · bazelbuild/bazel@c07188a · GitHub
Skip to content

Commit c07188a

Browse files
meteorcloudycopybara-github
authored andcommitted
Refactor building DLL example on Windows with windows_dll_library
Closes #7930. PiperOrigin-RevId: 243611901
1 parent b941e0b commit c07188a

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed

examples/windows/dll/BUILD

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,35 @@
1+
load("//examples/windows/dll:windows_dll_library.bzl", "windows_dll_library")
2+
13
filegroup(
24
name = "srcs",
35
srcs = glob(["**"]),
46
visibility = ["//examples:__pkg__"],
57
)
68

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"],
913
hdrs = ["hello-library.h"],
10-
)
11-
12-
cc_binary(
13-
name = "hellolib.dll",
14-
srcs = [
15-
"hello-library.cpp",
16-
],
1714
# Define COMPILING_DLL to export symbols during compiling the DLL.
1815
# See hello-library.h
1916
copts = ["/DCOMPILING_DLL"],
20-
linkshared = 1,
21-
deps = [
22-
":hello-library-header",
23-
],
2417
)
2518

2619
# **Explicitly link to hellolib.dll**
2720

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.
2922
cc_binary(
3023
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"],
3425
data = [":hellolib.dll"],
3526
)
3627

3728
# **Implicitly link to hellolib.dll**
3829

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.
6331
cc_binary(
6432
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"],
6935
)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This is a simple windows_dll_library rule for builing a DLL Windows
2+
# that can be depended on by other cc rules.
3+
#
4+
# Example useage:
5+
# windows_dll_library(
6+
# name = "hellolib",
7+
# srcs = [
8+
# "hello-library.cpp",
9+
# ],
10+
# hdrs = ["hello-library.h"],
11+
# # Define COMPILING_DLL to export symbols during compiling the DLL.
12+
# copts = ["/DCOMPILING_DLL"],
13+
# )
14+
#
15+
16+
def windows_dll_library(
17+
name,
18+
srcs = [],
19+
hdrs = [],
20+
visibility = None,
21+
**kwargs):
22+
"""A simple windows_dll_library rule for builing a DLL Windows."""
23+
dll_name = name + ".dll"
24+
import_lib_name = name + "_import_lib"
25+
import_target_name = name + "_dll_import"
26+
27+
# Build the shared library
28+
native.cc_binary(
29+
name = dll_name,
30+
srcs = srcs + hdrs,
31+
linkshared = 1,
32+
**kwargs
33+
)
34+
35+
# Get the import library for the dll
36+
native.filegroup(
37+
name = import_lib_name,
38+
srcs = [":" + dll_name],
39+
output_group = "interface_library",
40+
)
41+
42+
# Because we cannot directly depend on cc_binary from other cc rules in deps attribute,
43+
# we use cc_import as a bridge to depend on the dll.
44+
native.cc_import(
45+
name = import_target_name,
46+
interface_library = ":" + import_lib_name,
47+
shared_library = ":" + dll_name,
48+
)
49+
50+
# Create a new cc_library to also include the headers needed for the shared library
51+
native.cc_library(
52+
name = name,
53+
hdrs = hdrs,
54+
visibility = visibility,
55+
deps = [
56+
":" + import_target_name,
57+
],
58+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy