Skip to content

Commit 5681c74

Browse files
authored
fix: honor --force_pic for shared library (#1440)
cc_common.create_compile_variables() does not enable pic when --force_pic is used unless the 'use_pic' attr is set to True. This causes issues when linking shared libraries what expected the compiled object to be pic.
1 parent 85cbfe1 commit 5681c74

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

foreign_cc/private/cc_toolchain_util.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def get_flags_info(ctx, link_output_file = None):
242242
cxxopts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts + getattr(ctx.attr, "copts", [])) or []
243243
linkopts = (ctx.fragments.cpp.linkopts + getattr(ctx.attr, "linkopts", [])) or []
244244
defines = _defines_from_deps(ctx)
245+
use_pic = cc_toolchain_.needs_pic_for_dynamic_libraries(feature_configuration = feature_configuration)
245246

246247
flags = CxxFlagsInfo(
247248
cc = cc_common.get_memory_inefficient_command_line(
@@ -251,6 +252,7 @@ def get_flags_info(ctx, link_output_file = None):
251252
feature_configuration = feature_configuration,
252253
cc_toolchain = cc_toolchain_,
253254
preprocessor_defines = defines,
255+
use_pic = use_pic,
254256
),
255257
),
256258
cxx = cc_common.get_memory_inefficient_command_line(
@@ -261,6 +263,7 @@ def get_flags_info(ctx, link_output_file = None):
261263
cc_toolchain = cc_toolchain_,
262264
preprocessor_defines = defines,
263265
add_legacy_cxx_options = True,
266+
use_pic = use_pic,
264267
),
265268
),
266269
cxx_linker_shared = cc_common.get_memory_inefficient_command_line(

0 commit comments

Comments
 (0)