@@ -71,7 +71,6 @@ 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 = {}
7574
7675 # CFLAGS and CXXFLAGS are also set in foreign_cc/private/cmake_script.bzl, so that meson
7776 # can use the intended tools.
@@ -91,7 +90,8 @@ def _create_meson_script(configureParameters):
9190 script .append ("##export_var## CXXFLAGS \" {} ${{CXXFLAGS:-}}\" " .format (_join_flags_list (ctx .workspace_name , cxxopts ).replace ("\" " , "'" )))
9291
9392 if flags .cxx_linker_executable :
94- script .append ("##export_var## LDFLAGS \" {} ${{LDFLAGS:-}}\" " .format (_join_flags_list (ctx .workspace_name , flags .cxx_linker_executable ).replace ("\" " , "'" )))
93+ ldflags = _filter_flags (flags .cxx_linker_executable , ctx .attr .linkopts_exclude )
94+ script .append ("##export_var## LDFLAGS \" {} ${{LDFLAGS:-}}\" " .format (_join_flags_list (ctx .workspace_name , ldflags ).replace ("\" " , "'" )))
9595
9696 script .append ("##export_var## CMAKE {}" .format (attrs .cmake_path ))
9797 script .append ("##export_var## NINJA {}" .format (attrs .ninja_path ))
@@ -142,21 +142,13 @@ def _create_meson_script(configureParameters):
142142
143143 target_args [target_name ] = args
144144
145- # Append custom build options
146- build_options .update (ctx .attr .options )
147- if flags .cxx_linker_shared and ctx .attr .shared_ldflags_option :
148- if ctx .attr .shared_ldflags_option in build_options :
149- fail ("cannot override existing build option: {}" .format (ctx .attr .shared_ldflags_option ))
150-
151- build_options [ctx .attr .shared_ldflags_option ] = _flags_to_str_repr (ctx .workspace_name , flags .cxx_linker_shared )
152-
153145 script .append ("{meson} setup --prefix={install_dir} {setup_args} {options} {source_dir}" .format (
154146 meson = meson_path ,
155147 install_dir = "$$INSTALLDIR$$" ,
156148 setup_args = " " .join (target_args .get ("setup" , [])),
157149 options = " " .join ([
158- "\" -D{}={}\" " .format (key , build_options [key ])
159- for key in build_options
150+ "-D{}=\" {}\" " .format (key , ctx . attr . options [key ])
151+ for key in ctx . attr . options
160152 ]),
161153 source_dir = "$$EXT_BUILD_ROOT$$/" + root ,
162154 ))
@@ -225,6 +217,10 @@ def _attrs():
225217 doc = "__deprecated__: please use `target_args` with `'install'` target key." ,
226218 mandatory = False ,
227219 ),
220+ "linkopts_exclude" : attr .string_list (
221+ doc = "Optional link options to be excluded from the common set of flags passed from the Bazel toolchain to Meson." ,
222+ mandatory = False ,
223+ ),
228224 "options" : attr .string_dict (
229225 doc = "Meson `setup` options (converted to `-Dkey=value`)" ,
230226 mandatory = False ,
@@ -234,10 +230,6 @@ def _attrs():
234230 doc = "__deprecated__: please use `target_args` with `'setup'` target key." ,
235231 mandatory = False ,
236232 ),
237- "shared_ldflags_option" : attr .string (
238- doc = "Name of additional setup option that will contain shared ldflags." ,
239- mandatory = False ,
240- ),
241233 "target_args" : attr .string_list_dict (
242234 doc = "Dict of arguments for each of the Meson targets. The " +
243235 "target name is the key and the list of args is the value." ,
@@ -314,9 +306,7 @@ def _absolutize(workspace_name, text, force = False):
314306def _join_flags_list (workspace_name , flags ):
315307 return " " .join ([_absolutize (workspace_name , flag ) for flag in flags ])
316308
317- def _flags_to_str_repr (workspace_name , flags ):
318- # see https://mesonbuild.com/Build-options.html#using-build-options
319- # meson array build options with elements that contain commas need to be in the format
320- # "-Doption=['a,b', 'c,d']"
321- quoted = ["'" + _absolutize (workspace_name , flag ) + "'" for flag in flags ]
322- return "[" + ", " .join (quoted ) + "]"
309+ def _filter_flags (flags , exclude_list ):
310+ if len (exclude_list ):
311+ return [flag for flag in flags if flag not in exclude_list ]
312+ return flags
0 commit comments