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

[Bazel 6.x.x] sdk_dylib at _end_ of the linker invocation #766

Merged
merged 1 commit into from
Sep 14, 2023
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
22 changes: 22 additions & 0 deletions rules/internal/framework_middleman.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ def _dedupe_key(key, avoid_libraries, objc_provider_fields, check_name = False):
updated_library.append(f)
objc_provider_fields[key] = depset(updated_library)

def _get_lib_name(name):
"""return a lib name for a name dropping prefix/suffix"""
if name.startswith("lib"):
name = name[3:]
if name.endswith(".dylib"):
name = name[:-6]
elif name.endswith(".so"):
name = name[:-3]
return name

def _dep_middleman(ctx):
objc_providers = []
cc_providers = []
Expand Down Expand Up @@ -225,6 +235,18 @@ def _dep_middleman(ctx):
_dedupe_key("imported_library", avoid_libraries, objc_provider_fields, check_name = True)
_dedupe_key("static_framework_file", avoid_libraries, objc_provider_fields, check_name = True)

if "sdk_dylib" in objc_provider_fields:
# Put sdk_dylib at _end_ of the linker invocation. Apple's linkers have
# problems when SDK dylibs are first in the list, starting with Bazel
# 6.0 this is backwards by default
objc_provider_fields["linkopt"] = depset(
[],
transitive = [
objc_provider_fields.get("linkopt", depset([])),
depset(["-l" + _get_lib_name(lib) for lib in objc_provider_fields.pop("sdk_dylib").to_list()]),
],
)

objc_provider = apple_common.new_objc_provider(**objc_provider_fields)
cc_info_provider = cc_common.merge_cc_infos(direct_cc_infos = [], cc_infos = cc_providers)
providers = [
Expand Down
2 changes: 1 addition & 1 deletion tests/ios/unit-test/test-imports-app/BUILD.GoogleMobileAds
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apple_static_framework_import(
allow_empty = False,
),
sdk_dylibs = [
"libsqlite3",
"libsqlite3.dylib",
"libz",
],
sdk_frameworks = [
Expand Down