mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Swift: fix cmake generation
The bazel -> cmake generator is currently not capable of handling separate included generated cmake files making use of common C/C++ dependencies. To work around this limitation, a single generated cmake is now in place. Long-term, we should either: * make the cmake generator handle common dependencies gracefully, or * make the cmake generation aspect travel up `pkg_` rules `srcs` attributes so to avoid having to list the targets to be generated in the top-level `BUILD` file. Other things fixed: * removed some warning spam about redefined `BAZEL_CURRENT_REPOSITORY` * fixed the final link step, that was failing because `libswiftCore.so` was not being linked.
This commit is contained in:
@@ -11,8 +11,7 @@ CmakeInfo = provider(
|
||||
"includes": "",
|
||||
"quote_includes": "",
|
||||
"stripped_includes": "",
|
||||
"imported_static_libs": "",
|
||||
"imported_dynamic_libs": "",
|
||||
"imported_libs": "",
|
||||
"copts": "",
|
||||
"linkopts": "",
|
||||
"force_cxx_compilation": "",
|
||||
@@ -41,10 +40,8 @@ def _file_kind(file):
|
||||
return "src"
|
||||
if ext in ("h", "hh", "hpp", "def", "inc"):
|
||||
return "hdr"
|
||||
if ext == "a":
|
||||
return "static_lib"
|
||||
if ext in ("so", "dylib"):
|
||||
return "dynamic_lib"
|
||||
if ext in ("a", "so", "dylib"):
|
||||
return "lib"
|
||||
return None
|
||||
|
||||
def _get_includes(includes):
|
||||
@@ -70,8 +67,7 @@ def _cmake_aspect_impl(target, ctx):
|
||||
by_kind.setdefault(_file_kind(f), []).append(_cmake_file(f))
|
||||
hdrs = by_kind.get("hdr", [])
|
||||
srcs = by_kind.get("src", [])
|
||||
static_libs = by_kind.get("static_lib", [])
|
||||
dynamic_libs = by_kind.get("dynamic_lib", [])
|
||||
libs = by_kind.get("lib", [])
|
||||
if not srcs and is_binary:
|
||||
empty = ctx.actions.declare_file(name + "_empty.cpp")
|
||||
ctx.actions.write(empty, "")
|
||||
@@ -134,12 +130,15 @@ def _cmake_aspect_impl(target, ctx):
|
||||
system_includes = system_includes,
|
||||
quote_includes = quote_includes,
|
||||
stripped_includes = stripped_includes,
|
||||
imported_static_libs = static_libs,
|
||||
imported_dynamic_libs = dynamic_libs,
|
||||
imported_libs = libs,
|
||||
copts = copts,
|
||||
linkopts = linkopts,
|
||||
defines = compilation_ctx.defines.to_list(),
|
||||
local_defines = compilation_ctx.local_defines.to_list(),
|
||||
local_defines = [
|
||||
d
|
||||
for d in compilation_ctx.local_defines.to_list()
|
||||
if not d.startswith("BAZEL_CURRENT_REPOSITORY")
|
||||
],
|
||||
force_cxx_compilation = force_cxx_compilation,
|
||||
transitive_deps = depset(deps, transitive = [dep.transitive_deps for dep in deps]),
|
||||
),
|
||||
@@ -156,20 +155,10 @@ def _map_cmake_info(info, is_windows):
|
||||
commands = [
|
||||
"add_%s(%s)" % (info.kind, args),
|
||||
]
|
||||
if info.imported_static_libs and info.imported_dynamic_libs:
|
||||
commands += [
|
||||
"if(BUILD_SHARED_LIBS)",
|
||||
" target_link_libraries(%s %s %s)" %
|
||||
(info.name, info.modifier or "PUBLIC", " ".join(info.imported_dynamic_libs)),
|
||||
"else()",
|
||||
" target_link_libraries(%s %s %s)" %
|
||||
(info.name, info.modifier or "PUBLIC", " ".join(info.imported_static_libs)),
|
||||
"endif()",
|
||||
]
|
||||
elif info.imported_static_libs or info.imported_dynamic_libs:
|
||||
if info.imported_libs:
|
||||
commands += [
|
||||
"target_link_libraries(%s %s %s)" %
|
||||
(info.name, info.modifier or "PUBLIC", " ".join(info.imported_dynamic_lib + info.imported_static_libs)),
|
||||
(info.name, info.modifier or "PUBLIC", " ".join(info.imported_libs)),
|
||||
]
|
||||
if info.deps:
|
||||
libs = {}
|
||||
|
||||
Reference in New Issue
Block a user