Skip to content

Commit

Permalink
Add ability to disable passing the -import-underlying-module copt to …
Browse files Browse the repository at this point in the history
…swift_library targets (#745)

* Add ability to disable passing the -import-underlying-module copt to swift_library targets
* Intentionally disable list-append lint
  • Loading branch information
thiagohmcruz authored Jul 21, 2023
1 parent cf7d493 commit 4a890d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ config_setting(
},
)

config_setting(
name = "swift_disable_import_underlying_module",
values = {
"features": feature_names.swift_disable_import_underlying_module,
},
)

selects.config_setting_group(
name = "arm64_simulator_use_device_deps",
match_any = [
Expand Down
3 changes: 3 additions & 0 deletions rules/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ feature_names = struct(

# Use the ARM deps for the simulator - see rules/import_middleman.bzl
arm64_simulator_use_device_deps = "apple.arm64_simulator_use_device_deps",

# When set disable passing the `-import-underlying-module` copt to `swift_library` targets
swift_disable_import_underlying_module = "swift.swift_disable_import_underlying_module",
)
40 changes: 28 additions & 12 deletions rules/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,15 @@ _DEFAULT_LIBRARY_TOOLS = {
"fetch_default_xcconfig": _error_on_default_xcconfig,
}

# buildifier: disable=list-append
def _append_headermap_copts(hmap, flag, objc_copts, swift_copts, cc_copts):
copt = flag + "$(execpath :{hmap})".format(hmap = hmap)

objc_copts.append(copt)
cc_copts.append(copt)
swift_copts.extend(("-Xcc", copt))
objc_copts += [copt]
cc_copts += [copt]
swift_copts += ["-Xcc", copt]

return objc_copts, swift_copts, cc_copts

def _uppercase_string(s):
return s.upper()
Expand Down Expand Up @@ -448,7 +451,17 @@ def _find_imported_xcframework_name(outputs):
return fw_name
return None

def apple_library(name, library_tools = {}, export_private_headers = True, namespace_is_module_name = True, default_xcconfig_name = None, xcconfig = {}, xcconfig_by_build_setting = {}, objc_defines = [], swift_defines = [], **kwargs):
def apple_library(
name,
library_tools = {},
export_private_headers = True,
namespace_is_module_name = True,
default_xcconfig_name = None,
xcconfig = {},
xcconfig_by_build_setting = {},
objc_defines = [],
swift_defines = [],
**kwargs):
"""Create libraries for native source code on Apple platforms.
Automatically handles mixed-source libraries and comes with
Expand Down Expand Up @@ -854,7 +867,7 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
tags = _MANUAL,
)
private_dep_names.append(public_hmap_name)
_append_headermap_copts(public_hmap_name, "-I", additional_objc_copts, additional_swift_copts, additional_cc_copts)
additional_objc_copts, additional_swift_copts, additional_cc_copts = _append_headermap_copts(public_hmap_name, "-I", additional_objc_copts, additional_swift_copts, additional_cc_copts)

if len(objc_non_exported_hdrs + objc_private_hdrs) > 0:
private_hmap_name = name + "_private_hmap"
Expand All @@ -865,7 +878,7 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
tags = _MANUAL,
)
private_dep_names.append(private_hmap_name)
_append_headermap_copts(private_hmap_name, "-I", additional_objc_copts, additional_swift_copts, additional_cc_copts)
additional_objc_copts, additional_swift_copts, additional_cc_copts = _append_headermap_copts(private_hmap_name, "-I", additional_objc_copts, additional_swift_copts, additional_cc_copts)

## END HMAP

Expand All @@ -888,14 +901,17 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
module_data = library_tools["wrap_resources_in_filegroup"](name = name + "_wrapped_resources_filegroup", srcs = data, testonly = testonly)

if swift_sources:
additional_swift_copts.extend(("-Xcc", "-I."))
additional_swift_copts += ["-Xcc", "-I."]
if module_map:
# Frameworks find the modulemap file via the framework vfs overlay
if not namespace_is_module_name:
additional_swift_copts += ["-Xcc", "-fmodule-map-file=" + "$(execpath " + module_map + ")"]
additional_swift_copts.append(
"-import-underlying-module",
)

additional_swift_copts += select({
"@build_bazel_rules_ios//:swift_disable_import_underlying_module": [],
"//conditions:default": ["-import-underlying-module"],
})

swiftc_inputs = other_inputs + objc_hdrs + objc_private_hdrs
if module_map:
swiftc_inputs.append(module_map)
Expand Down Expand Up @@ -975,7 +991,7 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
testonly = testonly,
)
private_dep_names.append(swift_doublequote_hmap_name)
_append_headermap_copts(swift_doublequote_hmap_name, "-iquote", additional_objc_copts, additional_swift_copts, additional_cc_copts)
additional_objc_copts, additional_swift_copts, additional_cc_copts = _append_headermap_copts(swift_doublequote_hmap_name, "-iquote", additional_objc_copts, additional_swift_copts, additional_cc_copts)

# Add generated swift header to header maps for angle bracket imports
swift_angle_bracket_hmap_name = name + "_swift_angle_bracket_hmap"
Expand All @@ -988,7 +1004,7 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
testonly = testonly,
)
private_dep_names.append(swift_angle_bracket_hmap_name)
_append_headermap_copts(swift_angle_bracket_hmap_name, "-I", additional_objc_copts, additional_swift_copts, additional_cc_copts)
additional_objc_copts, additional_swift_copts, additional_cc_copts = _append_headermap_copts(swift_angle_bracket_hmap_name, "-I", additional_objc_copts, additional_swift_copts, additional_cc_copts)

if cpp_sources:
additional_cc_copts.append("-I.")
Expand Down

0 comments on commit 4a890d3

Please sign in to comment.