Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions foreign_cc/meson.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _create_meson_script(configureParameters):
tools = get_tools_info(ctx)
flags = get_flags_info(ctx)
script = pkgconfig_script(inputs.ext_build_dirs)
build_options = ctx.attr.options

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

target_args[target_name] = args

# Append shared flags to build options
if flags.cxx_linker_shared and ctx.attr.shared_ldflags_option:
if ctx.attr.shared_ldflags_option in build_options:
fail("cannot override existing build option: {}".format(ctx.attr.shared_ldflags_option))

build_options = build_options | {ctx.attr.shared_ldflags_option: _list_to_str_repr(flags.cxx_linker_shared)}

# Expand options
build_options = expand_locations_and_make_variables(ctx, build_options, "options", data)

script.append("{meson} setup --prefix={install_dir} {setup_args} {options} {source_dir}".format(
meson = meson_path,
install_dir = "$$INSTALLDIR$$",
setup_args = " ".join(target_args.get("setup", [])),
options = " ".join([
"-D{}=\"{}\"".format(key, ctx.attr.options[key])
for key in ctx.attr.options
"\"-D{}={}\"".format(key, build_options[key])
for key in build_options
]),
source_dir = "$$EXT_BUILD_ROOT$$/" + root,
))
Expand Down Expand Up @@ -225,6 +236,10 @@ def _attrs():
doc = "__deprecated__: please use `target_args` with `'setup'` target key.",
mandatory = False,
),
"shared_ldflags_option": attr.string(
doc = "Name of additional setup option that will contain shared ldflags.",
mandatory = False,
),
"target_args": attr.string_list_dict(
doc = "Dict of arguments for each of the Meson targets. The " +
"target name is the key and the list of args is the value.",
Expand Down Expand Up @@ -300,3 +315,12 @@ def _absolutize(workspace_name, text, force = False):

def _join_flags_list(workspace_name, flags):
return " ".join([_absolutize(workspace_name, flag) for flag in flags])

def _list_to_str_repr(lst):
# see https://mesonbuild.com/Build-options.html#using-build-options
# meson array build options with elements that contain commas need to be in the format
# "-Doption=['a,b', 'c,d']"
quoted = []
for item in lst:
quoted.append("'" + item + "'")
return "[" + ", ".join(quoted) + "]"