set CC and CXX and their flags in meson (#1098)
This commit is contained in:
parent
83aeab38da
commit
51152aac9d
|
@ -39,6 +39,12 @@ meson_with_requirements(
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
lib_source = ":all_srcs",
|
lib_source = ":all_srcs",
|
||||||
|
linkopts = select({
|
||||||
|
"@openssl//:msvc_compiler": [
|
||||||
|
"ws2_32.lib",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
options = select({
|
options = select({
|
||||||
"@platforms//os:linux": {
|
"@platforms//os:linux": {
|
||||||
# Disable LLVM support, as building LLVM in rules_foreign_cc CI would drastically increase the build time
|
# Disable LLVM support, as building LLVM in rules_foreign_cc CI would drastically increase the build time
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
load("//foreign_cc:utils.bzl", "full_label")
|
load("//foreign_cc:utils.bzl", "full_label")
|
||||||
load("//foreign_cc/built_tools:meson_build.bzl", "meson_tool")
|
load("//foreign_cc/built_tools:meson_build.bzl", "meson_tool")
|
||||||
|
load(
|
||||||
|
"//foreign_cc/private:cc_toolchain_util.bzl",
|
||||||
|
"absolutize_path_in_str",
|
||||||
|
"get_flags_info",
|
||||||
|
"get_tools_info",
|
||||||
|
)
|
||||||
load(
|
load(
|
||||||
"//foreign_cc/private:detect_root.bzl",
|
"//foreign_cc/private:detect_root.bzl",
|
||||||
"detect_root",
|
"detect_root",
|
||||||
|
@ -61,8 +67,34 @@ def _create_meson_script(configureParameters):
|
||||||
attrs = configureParameters.attrs
|
attrs = configureParameters.attrs
|
||||||
inputs = configureParameters.inputs
|
inputs = configureParameters.inputs
|
||||||
|
|
||||||
|
tools = get_tools_info(ctx)
|
||||||
script = pkgconfig_script(inputs.ext_build_dirs)
|
script = pkgconfig_script(inputs.ext_build_dirs)
|
||||||
|
|
||||||
|
# CFLAGS and CXXFLAGS are also set in foreign_cc/private/cmake_script.bzl, so that meson
|
||||||
|
# can use the intended tools.
|
||||||
|
# However, they are split by meson on whitespace. For Windows it's common to have spaces in path
|
||||||
|
# https://github.com/mesonbuild/meson/issues/3565
|
||||||
|
# Skip setting them in this case.
|
||||||
|
if " " not in tools.cc:
|
||||||
|
script.append("##export_var## CC {}".format(_absolutize(ctx.workspace_name, tools.cc)))
|
||||||
|
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 []
|
||||||
|
|
||||||
|
if copts:
|
||||||
|
script.append("##export_var## CFLAGS \"{}\"".format(" ".join(copts).replace("\"", "'")))
|
||||||
|
if cxxopts:
|
||||||
|
script.append("##export_var## CXXFLAGS \"{}\"".format(" ".join(cxxopts).replace("\"", "'")))
|
||||||
|
|
||||||
|
flags = get_flags_info(ctx)
|
||||||
|
if flags.cxx_linker_executable:
|
||||||
|
script.append("##export_var## LDFLAGS \"{}\"".format(" ".join(flags.cxx_linker_executable).replace("\"", "'")))
|
||||||
|
|
||||||
script.append("##export_var## CMAKE {}".format(attrs.cmake_path))
|
script.append("##export_var## CMAKE {}".format(attrs.cmake_path))
|
||||||
script.append("##export_var## NINJA {}".format(attrs.ninja_path))
|
script.append("##export_var## NINJA {}".format(attrs.ninja_path))
|
||||||
script.append("##export_var## PKG_CONFIG {}".format(attrs.pkg_config_path))
|
script.append("##export_var## PKG_CONFIG {}".format(attrs.pkg_config_path))
|
||||||
|
@ -201,3 +233,9 @@ def meson_with_requirements(name, requirements, **kwargs):
|
||||||
toolchain = full_label("built_meson_toolchain_for_{}".format(name)),
|
toolchain = full_label("built_meson_toolchain_for_{}".format(name)),
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _absolutize(workspace_name, text, force = False):
|
||||||
|
if text.strip(" ").startswith("C:") or text.strip(" ").startswith("c:"):
|
||||||
|
return "\"{}\"".format(text)
|
||||||
|
|
||||||
|
return absolutize_path_in_str(workspace_name, "$EXT_BUILD_ROOT/", text, force)
|
||||||
|
|
|
@ -191,6 +191,7 @@ def do_function_call(text, shell_context):
|
||||||
return replace_exports(after, shell_context)
|
return replace_exports(after, shell_context)
|
||||||
|
|
||||||
arguments = split_arguments(after.strip(" ")) if after else []
|
arguments = split_arguments(after.strip(" ")) if after else []
|
||||||
|
|
||||||
return call_shell(shell_context, funname, *arguments)
|
return call_shell(shell_context, funname, *arguments)
|
||||||
|
|
||||||
# buildifier: disable=function-docstring
|
# buildifier: disable=function-docstring
|
||||||
|
@ -199,22 +200,28 @@ def split_arguments(text):
|
||||||
current = text.strip(" ")
|
current = text.strip(" ")
|
||||||
|
|
||||||
for _ in range(1, 2147483647):
|
for _ in range(1, 2147483647):
|
||||||
|
current = current.strip(" ")
|
||||||
if not current:
|
if not current:
|
||||||
break
|
break
|
||||||
|
|
||||||
# we are ignoring escaped quotes
|
# we are ignoring escaped quotes
|
||||||
(before, separator, after) = current.partition("\"")
|
s_quote = current.find("\"")
|
||||||
if not separator:
|
if s_quote < 0:
|
||||||
parts += current.split(" ")
|
for e in current.split(" "):
|
||||||
|
if len(e) > 0:
|
||||||
|
parts.append(e)
|
||||||
break
|
break
|
||||||
(quoted, separator2, after2) = after.partition("\"")
|
|
||||||
if not separator2:
|
e_quote = current.find("\"", s_quote + 1)
|
||||||
|
if e_quote < 0:
|
||||||
fail("Incorrect quoting in fragment: {}".format(current))
|
fail("Incorrect quoting in fragment: {}".format(current))
|
||||||
|
|
||||||
before = before.strip(" ")
|
# backtrack to first space, from here to e_quote is a token
|
||||||
if before:
|
e_before = current.rfind(" ", 0, s_quote)
|
||||||
|
if e_before >= 0:
|
||||||
|
before = current[0:e_before].strip(" ")
|
||||||
parts += before.split(" ")
|
parts += before.split(" ")
|
||||||
parts.append("\"" + quoted + "\"")
|
parts.append(current[e_before + 1:e_quote + 1])
|
||||||
current = after2
|
current = current[e_quote + 1:]
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
|
|
|
@ -84,6 +84,7 @@ def _split_arguments_test(ctx):
|
||||||
" 1 2 3": ["1", "2", "3"],
|
" 1 2 3": ["1", "2", "3"],
|
||||||
" usual \"quoted argument\"": ["usual", "\"quoted argument\""],
|
" usual \"quoted argument\"": ["usual", "\"quoted argument\""],
|
||||||
"1 2": ["1", "2"],
|
"1 2": ["1", "2"],
|
||||||
|
"var -flag1=\"redacted\" -flag2=\"redacted\"": ["var", "-flag1=\"redacted\"", "-flag2=\"redacted\""],
|
||||||
}
|
}
|
||||||
for case in cases:
|
for case in cases:
|
||||||
result = split_arguments(case)
|
result = split_arguments(case)
|
||||||
|
|
Loading…
Reference in New Issue