Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flags handling for meson #1303

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
19 changes: 9 additions & 10 deletions foreign_cc/meson.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _create_meson_script(configureParameters):
inputs = configureParameters.inputs

tools = get_tools_info(ctx)
flags = get_flags_info(ctx)
script = pkgconfig_script(inputs.ext_build_dirs)

# CFLAGS and CXXFLAGS are also set in foreign_cc/private/cmake_script.bzl, so that meson
Expand All @@ -80,20 +81,15 @@ def _create_meson_script(configureParameters):
if " " not in tools.cxx:
script.append("##export_var## CXX {}".format(_absolutize(ctx.workspace_name, tools.cxx)))

# set flags same as foreign_cc/private/cc_toolchain_util.bzl
# cannot use get_flags_info() because bazel adds additional flags that
# aren't compatible with compiler or linker above
copts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.conlyopts + getattr(ctx.attr, "copts", [])) or []
cxxopts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts + getattr(ctx.attr, "copts", [])) or []

copts = flags.cc
cxxopts = flags.cxx
if copts:
script.append("##export_var## CFLAGS \"{} ${{CFLAGS:-}}\"".format(" ".join(copts).replace("\"", "'")))
script.append("##export_var## CFLAGS \"{} ${{CFLAGS:-}}\"".format(_join_flags_list(ctx.workspace_name, copts).replace("\"", "'")))
if cxxopts:
script.append("##export_var## CXXFLAGS \"{} ${{CXXFLAGS:-}}\"".format(" ".join(cxxopts).replace("\"", "'")))
script.append("##export_var## CXXFLAGS \"{} ${{CXXFLAGS:-}}\"".format(_join_flags_list(ctx.workspace_name, cxxopts).replace("\"", "'")))

flags = get_flags_info(ctx)
if flags.cxx_linker_executable:
script.append("##export_var## LDFLAGS \"{} ${{LDFLAGS:-}}\"".format(" ".join(flags.cxx_linker_executable).replace("\"", "'")))
script.append("##export_var## LDFLAGS \"{} ${{LDFLAGS:-}}\"".format(_join_flags_list(ctx.workspace_name, flags.cxx_linker_executable).replace("\"", "'")))

script.append("##export_var## CMAKE {}".format(attrs.cmake_path))
script.append("##export_var## NINJA {}".format(attrs.ninja_path))
Expand Down Expand Up @@ -243,3 +239,6 @@ def _absolutize(workspace_name, text, force = False):
return "\"{}\"".format(text)

return absolutize_path_in_str(workspace_name, "$EXT_BUILD_ROOT/", text, force)

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