Skip to content

Commit d8b415b

Browse files
committed
meson: use common ldflags
1 parent 66b9b32 commit d8b415b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

foreign_cc/meson.bzl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _create_meson_script(configureParameters):
7171
tools = get_tools_info(ctx)
7272
flags = get_flags_info(ctx)
7373
script = pkgconfig_script(inputs.ext_build_dirs)
74+
build_options = _get_options(ctx)
7475

7576
# CFLAGS and CXXFLAGS are also set in foreign_cc/private/cmake_script.bzl, so that meson
7677
# can use the intended tools.
@@ -141,13 +142,20 @@ def _create_meson_script(configureParameters):
141142

142143
target_args[target_name] = args
143144

145+
# Append shared flags to build options
146+
if flags.cxx_linker_shared and ctx.attr.shared_ldflags_option:
147+
if ctx.attr.shared_ldflags_option in build_options:
148+
fail("cannot override existing build option: {}".format(ctx.attr.shared_ldflags_option))
149+
150+
build_options[ctx.attr.shared_ldflags_option] = _list_to_str_repr(flags.cxx_linker_shared)
151+
144152
script.append("{meson} setup --prefix={install_dir} {setup_args} {options} {source_dir}".format(
145153
meson = meson_path,
146154
install_dir = "$$INSTALLDIR$$",
147155
setup_args = " ".join(target_args.get("setup", [])),
148156
options = " ".join([
149-
"-D{}=\"{}\"".format(key, ctx.attr.options[key])
150-
for key in ctx.attr.options
157+
"\"-D{}={}\"".format(key, build_options[key])
158+
for key in build_options
151159
]),
152160
source_dir = "$$EXT_BUILD_ROOT$$/" + root,
153161
))
@@ -225,6 +233,10 @@ def _attrs():
225233
doc = "__deprecated__: please use `target_args` with `'setup'` target key.",
226234
mandatory = False,
227235
),
236+
"shared_ldflags_option": attr.string(
237+
doc = "Name of additional setup option that will contain shared ldflags.",
238+
mandatory = False,
239+
),
228240
"target_args": attr.string_list_dict(
229241
doc = "Dict of arguments for each of the Meson targets. The " +
230242
"target name is the key and the list of args is the value.",
@@ -300,3 +312,18 @@ def _absolutize(workspace_name, text, force = False):
300312

301313
def _join_flags_list(workspace_name, flags):
302314
return " ".join([_absolutize(workspace_name, flag) for flag in flags])
315+
316+
def _get_options(ctx):
317+
# create an unfrozen dict with build options
318+
opts = {}
319+
opts.update(ctx.attr.options)
320+
return opts
321+
322+
def _list_to_str_repr(lst):
323+
# see https://mesonbuild.com/Build-options.html#using-build-options
324+
# meson array build options with elements that contain commas need to be in the format
325+
# "-Doption=['a,b', 'c,d']"
326+
quoted = []
327+
for item in lst:
328+
quoted.append("'" + item + "'")
329+
return "[" + ", ".join(quoted) + "]"

0 commit comments

Comments
 (0)