Skip to content

Commit

Permalink
[Bazel 6.x.x] sdk_dylib at _end_ of the linker invocation (#766)
Browse files Browse the repository at this point in the history
Apple's > Xcode 4.x linkers have problems when SDK dylibs are first -
Bazel 6.0 broke this due to refactoring. see changes in (
https://github.com/bazelbuild/bazel/blob/283ed362e6ccceb047553c2517a0331afd02db90/tools/osx/crosstool/cc_toolchain_config.bzl#L261 )

So this PR, is adding sdk_dylib to _end_ of the linker invocation to
make this work as it did
  • Loading branch information
jerrymarino authored Sep 14, 2023
1 parent 35c7197 commit d701fdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit d701fdc

Please sign in to comment.