Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion conan/tools/google/bazeldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ def _get_linkopts(self, cpp_info):
link_opt = '/DEFAULTLIB:{}' if os_build == "Windows" else '-l{}'
system_libs = [link_opt.format(lib) for lib in cpp_info.system_libs]
shared_flags = cpp_info.sharedlinkflags + cpp_info.exelinkflags
return [f'"{flag}"' for flag in (system_libs + shared_flags)]
frameworkdirs_flags = []
framework_flags = []
for frw in cpp_info.frameworks:
framework_flags.extend(["-framework", frw])
for frw_dir in cpp_info.frameworkdirs:
frameworkdirs_flags.extend(["-F", frw_dir.replace("\\", "/")])
return [f'"{flag}"' for flag in (system_libs + shared_flags + framework_flags + frameworkdirs_flags)]

def _get_copts(self, cpp_info):
# FIXME: long discussions between copts (-Iflag) vs includes in Bazel. Not sure yet
Expand Down
4 changes: 4 additions & 0 deletions test/functional/toolchains/google/test_bazel.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ def test_transitive_libs_consuming_7x(shared, bazel_output_root_dir):
self.cpp_info.system_libs.append("m")
else:
self.cpp_info.system_libs.append("ws2_32")
# Issue: https://github.com/conan-io/conan/issues/18748
from conan.tools.apple.apple import is_apple_os
if is_apple_os(self):
self.cpp_info.frameworks = ["CoreFoundation"]
"""
client.save({"conanfile.py": conanfile})
client.run(f"create . -o '*:shared={shared}' -tf ''") # skipping tests
Expand Down
48 changes: 48 additions & 0 deletions test/integration/toolchains/google/test_bazeldeps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import pathlib
import platform
import textwrap

import pytest

from conan.test.assets.genconanfile import GenConanfile
from conan.test.utils.tools import TestClient
from conan.tools.files import load
Expand Down Expand Up @@ -1257,3 +1260,48 @@ def package_info(self):
)
""")
assert myfirstcomp_expected in build_content


@pytest.mark.skipif(platform.system() == "Windows", reason="Unix paths only")
def test_apple_frameworks_and_frameworkdirs():
"""
Testing that Apple frameworks are included as linkopts
Issue: https://github.com/conan-io/conan/issues/18748
"""
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class PkgConfigConan(ConanFile):
def package_info(self):
self.cpp_info.frameworks = ["CoreFoundation", "Cocoa"]
self.cpp_info.frameworkdirs = ["/my/path/to/frw1"]

""")
client.save({"conanfile.py": conanfile}, clean_first=True)
client.run("create . --name=mylib --version=0.1")
client.save({"conanfile.py": GenConanfile("pkg", "0.1").with_require("mylib/0.1")},
clean_first=True)
client.run("install . -g BazelDeps")
build_content = load(None, os.path.join(client.current_folder, "mylib", "BUILD.bazel"))
build_file_expected = textwrap.dedent("""\
cc_library(
name = "mylib",
hdrs = glob([
"include/**",
]),
includes = [
"include",
],
linkopts = [
"-framework",
"CoreFoundation",
"-framework",
"Cocoa",
"-F",
"/my/path/to/frw1",
],
visibility = ["//visibility:public"],
)
""")
assert build_file_expected in build_content
Loading