Skip to content

Commit e42d4a8

Browse files
committed
fix: add curl dependency and fix linker issues with c++ libraries like boringssl
1 parent f21487d commit e42d4a8

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module(
99
bazel_dep(name = "bazel_lib", version = "3.0.0")
1010
bazel_dep(name = "bazel_features", version = "1.32.0")
1111
bazel_dep(name = "bazel_skylib", version = "1.8.1")
12+
bazel_dep(name = "curl", version = "8.8.0.bcr.3")
1213
bazel_dep(name = "package_metadata", version = "0.0.5")
1314
bazel_dep(name = "platforms", version = "0.0.11")
1415
bazel_dep(name = "rules_cc", version = "0.2.0")

d/private/rules/cc_toolchain.bzl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@ _UNSUPPORTED_FEATURES = [
2121
]
2222

2323
_LINKER_OPTIONS_DENYLIST = {
24-
# Don't link C++ libraries
25-
"-lstdc++": None,
26-
"-lc++": None,
27-
"-lc++abi": None,
28-
# libm and libobjc are added by the D compiler already, so suppress them here, to avoid warnings
29-
"-lm": None,
30-
"-lobjc": None,
31-
"-fobjc-link-runtime": None,
24+
# d-runtime uses __start/__stop_minfo
25+
"-Wl,--gc-sections": None,
3226
# --target is passed by the D compiler
3327
"--target=": None,
3428
# --target passed by the D compiler conflicts with -mmacosx-version-min set by cc_toolchain

d/private/rules/common.bzl

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,38 @@ def compilation_action(ctx, target_type = TARGET_TYPE.LIBRARY):
112112
The provider containing the compilation information.
113113
"""
114114
toolchain = ctx.toolchains["//d:toolchain_type"].d_toolchain_info
115-
c_deps = [d[CcInfo] for d in ctx.attr.deps if CcInfo in d]
116-
c_linker_inputs = [
115+
cc_deps = [d[CcInfo] for d in ctx.attr.deps if CcInfo in d]
116+
cc_linker_inputs = [
117117
linker_input
118-
for dep in c_deps
118+
for dep in cc_deps
119119
for linker_input in dep.linking_context.linker_inputs.to_list()
120120
]
121-
c_libraries = depset([
121+
cc_libraries = depset([
122122
lib.pic_static_library if lib.pic_static_library else lib.static_library
123-
for li in c_linker_inputs
123+
for li in cc_linker_inputs
124124
for lib in li.libraries
125+
], order = "topological")
126+
fix_linker_flags = {
127+
"-pthread": "-lpthread",
128+
}
129+
cc_linker_flags = depset([
130+
fix_linker_flags.get(flag, flag)
131+
for li in cc_linker_inputs
132+
for flag in li.user_link_flags
125133
])
126134
d_deps = [d[DInfo] for d in ctx.attr.deps if DInfo in d]
127-
compiler_flags = depset(ctx.attr.dopts, transitive = [d.compiler_flags for d in d_deps])
135+
compiler_flags = depset(
136+
ctx.attr.dopts,
137+
transitive = [d.compiler_flags for d in d_deps],
138+
)
128139
imports = depset(
129140
[paths.join(ctx.label.workspace_root, ctx.label.package, imp) for imp in ctx.attr.imports],
130141
transitive = [d.imports for d in d_deps],
131142
)
132-
linker_flags = depset(ctx.attr.linkopts, transitive = [d.linker_flags for d in d_deps])
143+
linker_flags = depset(
144+
ctx.attr.linkopts,
145+
transitive = [d.linker_flags for d in d_deps] + [cc_linker_flags],
146+
)
133147
string_imports = depset(
134148
([paths.join(ctx.label.workspace_root, ctx.label.package)] if ctx.files.string_srcs else []) +
135149
[paths.join(ctx.label.workspace_root, ctx.label.package, imp) for imp in ctx.attr.string_imports],
@@ -144,15 +158,15 @@ def compilation_action(ctx, target_type = TARGET_TYPE.LIBRARY):
144158
args.add_all(toolchain.compiler_flags)
145159
args.add_all(compiler_flags.to_list())
146160
args.add_all(versions.to_list(), format_each = "-version=%s")
147-
args.add_all(toolchain.linker_flags)
148-
args.add_all(linker_flags.to_list(), format_each = "-L=%s")
149161
output = None
150162
cc_toolchain = None
151163
env = ctx.var
152164
if target_type in [TARGET_TYPE.BINARY, TARGET_TYPE.TEST]:
165+
args.add_all(toolchain.linker_flags)
166+
args.add_all(linker_flags.to_list(), format_each = "-L=%s")
153167
for dep in d_deps:
154168
args.add_all(dep.libraries)
155-
args.add_all(c_libraries)
169+
args.add_all(cc_libraries)
156170
if target_type == TARGET_TYPE.TEST:
157171
args.add_all(["-main", "-unittest"])
158172
output = ctx.actions.declare_file(_binary_name(ctx, ctx.label.name))
@@ -183,7 +197,7 @@ def compilation_action(ctx, target_type = TARGET_TYPE.LIBRARY):
183197

184198
transitive_library_inputs = []
185199
if target_type != TARGET_TYPE.LIBRARY:
186-
transitive_library_inputs += [d.libraries for d in d_deps] + [c_libraries]
200+
transitive_library_inputs += [d.libraries for d in d_deps] + [cc_libraries]
187201
inputs = depset(
188202
direct = ctx.files.srcs + ctx.files.string_srcs,
189203
transitive = [toolchain.d_compiler[DefaultInfo].default_runfiles.files] +
@@ -219,8 +233,7 @@ def compilation_action(ctx, target_type = TARGET_TYPE.LIBRARY):
219233
libraries = depset(
220234
[] if ctx.attr.source_only else [output],
221235
order = "topological",
222-
transitive = [d.libraries for d in d_deps] +
223-
[c_libraries],
236+
transitive = [d.libraries for d in d_deps] + [cc_libraries],
224237
),
225238
linker_flags = linker_flags,
226239
string_imports = depset(

d/private/sdk/BUILD.dmd.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ d_toolchain(
9191
"-L--export-dynamic",
9292
],
9393
"@platforms//os:macos": ["-L-L{D_COMPILER_ROOT}/osx/lib"],
94-
"@platforms//os:windows": ["-L/LIBPATH:{D_COMPILER_ROOT}/windows/lib64"],
94+
"@platforms//os:windows": [
95+
"-L/LIBPATH:{D_COMPILER_ROOT}/windows/lib64",
96+
"-L/DEFAULTLIB:msvcrt.lib",
97+
"-L/NODEFAULTLIB:libcmt",
98+
"-L/INCREMENTAL:NO",
99+
],
95100
}),
96101
rdmd_tool = ":rdmd",
97102
)

tools/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ d_library(
2626
"curl_downloader.d",
2727
"integrity_hash.d",
2828
],
29-
linkopts = ["-lcurl"],
3029
visibility = ["//dub:__subpackages__"],
30+
deps = ["@curl"],
3131
)
3232

3333
d_binary(
3434
name = "generate_compiler_versions_bzl",
3535
srcs = [
3636
"generate_compiler_versions_bzl.d",
3737
],
38-
tags = ["manual"], # Not built by default; 'curl' dependency may not be available on all platforms.
3938
deps = [":d_utils"],
4039
)

0 commit comments

Comments
 (0)