Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sewerynplazuk authored Mar 11, 2024
2 parents a6adebb + 3a46721 commit e8d412e
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 171 deletions.
6 changes: 5 additions & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
matrix:
bazel: ["7.x", "rolling"]

tasks:
verify_targets:
name: Verify build targets
platform: macos
platform: macos_arm64
bazel: ${{ bazel }}
test_targets:
- '@rules_apple//examples/macos/CommandLine:ExamplesBuildTest'
test_flags:
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module(
repo_name = "build_bazel_rules_apple",
)

bazel_dep(name = "apple_support", version = "1.12.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "apple_support", version = "1.14.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_swift", version = "1.16.0", repo_name = "build_bazel_rules_swift")
Expand Down
3 changes: 2 additions & 1 deletion apple/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load(":cc_toolchain_forwarder.bzl", "cc_toolchain_forwarder")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":cc_toolchain_forwarder.bzl", "cc_toolchain_forwarder")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -27,6 +27,7 @@ licenses(["notice"])
"watchos_arm64_32",
"watchos_x86_64",
"watchos_device_arm64",
"watchos_device_arm64e",
]
]

Expand Down
6 changes: 5 additions & 1 deletion apple/internal/apple_framework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ def _apple_dynamic_framework_import_impl(ctx):
deps = deps,
disabled_features = disabled_features,
features = features,
framework_includes = _framework_search_paths(framework.header_imports),
framework_includes = _framework_search_paths(
framework.header_imports +
framework.swift_interface_imports +
framework.swift_module_imports,
),
header_imports = framework.header_imports,
kind = "dynamic",
label = label,
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/bundling_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def _validate_bundle_id(bundle_id):
# handled by the split(), so just have to check for '-'.
for i in range(len(part)):
ch = part[i]
if ch != "-" and not ch.isalnum():
if ch not in ["-", "_"] and not ch.isalnum():
fail("Invalid character(s) in bundle_id: \"%s\"" % bundle_id)

# Define the loadable module that lists the exported symbols in this file.
Expand Down
4 changes: 3 additions & 1 deletion apple/internal/experimental_mixed_language_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ target only contains Objective-C files.""")
swift_copts += header_map_ctx.swift_copts

# Generate module map for the underlying Obj-C module
# This is the modulemap used exclusively by the swift_library
# as such we export all the headers including the private ones so they can be found in the Swift module.
objc_module_map_name = name + ".internal.objc"
textual_hdrs = kwargs.get("textual_hdrs", [])
_module_map(
name = objc_module_map_name,
hdrs = hdrs,
hdrs = hdrs + private_hdrs,
module_name = module_name,
textual_hdrs = textual_hdrs,
testonly = testonly,
Expand Down
16 changes: 13 additions & 3 deletions apple/internal/partials/app_intents_metadata_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def _app_intents_metadata_bundle_partial_impl(
# This binary should only contain symbols for structs implementing the AppIntents protocol.
# Instead of containing all the application/extension/framework binary symbols, allowing
# the action to run faster and avoid depending on the application binary linking step.
#
# TODO(b/295227222): Avoid this linker step for Xcode 15.0+ when rules_swift supports the new
# swiftconstvalues-based manner of handling App Intents metadata.
link_result = linking_support.link_multi_arch_binary(
actions = actions,
cc_toolchains = cc_toolchains,
Expand All @@ -54,9 +57,16 @@ def _app_intents_metadata_bundle_partial_impl(
disabled_features = disabled_features,
features = features,
label = label,
# Allow `_main` to be undefined since none of the AppIntents implementing dependencies
# should include this entry point, and we only care about linking all AppIntents symbols.
user_link_flags = ["-Wl,-U,_main"],
user_link_flags = [
# Force _NSExtensionMain, which exists on all Apple platforms, to
# be the main symbol for the binary, just so any main symbol will
# exist. Since this binary is discarded afterwards the main symbol
# doesn't actually matter. This can be removed when the TODO above
# is resolved.
"-Wl,-e,_NSExtensionMain",
# Force the binary to link Foundation to make the hack above work.
"-Wl,-framework,Foundation",
],
)

fat_stub_binary = intermediates.file(
Expand Down
16 changes: 12 additions & 4 deletions apple/internal/partials/debug_symbols.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _collect_linkmaps(

return outputs

def _copy_dsyms_into_declared_bundle(
def _generate_dsym_binaries(
*,
actions,
debug_output_filename,
Expand Down Expand Up @@ -303,13 +303,21 @@ def _bundle_dsym_files(
found_binaries_by_arch.update(dsym_binaries)

if found_binaries_by_arch:
output_files = _copy_dsyms_into_declared_bundle(
generated_dsym_binaries = _generate_dsym_binaries(
actions = actions,
debug_output_filename = dsym_output_filename,
dsym_bundle_name = dsym_bundle_name,
found_binaries_by_arch = found_binaries_by_arch,
platform_prerequisites = platform_prerequisites,
)
output_files.extend(generated_dsym_binaries)
dsyms_command = (" && ".join([
"cp \"{dsym_path}\" \"${{OUTPUT_DIR}}/Contents/Resources/DWARF/{dsym_bundle_name}\"".format(
dsym_path = dsym_binary.path,
dsym_bundle_name = dsym_output_filename,
)
for dsym_binary in generated_dsym_binaries
]))

# If we found any binaries, create the Info.plist for the bundle as well.
dsym_plist = _generate_dsym_info_plist(
Expand All @@ -334,9 +342,9 @@ def _bundle_dsym_files(
apple_support.run_shell(
actions = actions,
apple_fragment = platform_prerequisites.apple_fragment,
inputs = [dsym_plist] + found_binaries_by_arch.values(),
inputs = generated_dsym_binaries + [dsym_plist] + found_binaries_by_arch.values(),
outputs = [dsym_bundle_dir],
command = ("mkdir -p \"${OUTPUT_DIR}/Contents/Resources/DWARF\" && " + plist_command),
command = ("mkdir -p \"${OUTPUT_DIR}/Contents/Resources/DWARF\" && " + dsyms_command + " && " + plist_command),
env = {
"OUTPUT_DIR": dsym_bundle_dir.path,
},
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _create_apple_rule(
cfg = cfg,
doc = doc,
executable = is_executable,
fragments = ["apple", "cpp", "objc"],
fragments = ["apple", "cpp", "objc", "j2objc"],
toolchains = toolchains,
**extra_args
)
Expand Down
4 changes: 2 additions & 2 deletions apple/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def apple_rules_dependencies(ignore_version_differences = False, include_bzlmod_
_maybe(
http_archive,
name = "build_bazel_apple_support",
sha256 = "100d12617a84ebc7ee7a10ecf3b3e2fdadaebc167ad93a21f820a6cb60158ead",
url = "https://github.com/bazelbuild/apple_support/releases/download/1.12.0/apple_support.1.12.0.tar.gz",
sha256 = "a8ba6fd09d0ffeba9b5f398f3a46262470fe0addddb4ef5afa7eab18d001a7b0",
url = "https://github.com/bazelbuild/apple_support/releases/download/1.14.0/apple_support.1.14.0.tar.gz",
ignore_version_differences = ignore_version_differences,
)

Expand Down
50 changes: 0 additions & 50 deletions doc/frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,53 +245,3 @@ apple_dynamic_framework_import(
```

![Framework imports](frameworks4.png)

## Migration

`apple_dynamic_framework_import` and `apple_static_framework_import` are
Starlark replacement rules for the native `objc_framework` rule, which is
deprecated and slated to be removed in Q1-19. The following is an example of how
migration will happen for `objc_framework` targets for Dynamic Frameworks:

```build
objc_framework(
name = "MyPrebuiltDynamicFramework",
framework_imports = glob(["MyPrebuiltDynamicFramework.framework/**"]),
is_dynamic = 1,
sdk_dylibs = [...],
sdk_frameworks = [...],
weak_sdk_frameworks = [...],
)
apple_dynamic_framework_import(
name = "MyPrebuildDynamicFramework",
framework_imports = glob(["MyPrebuiltDynamicFramework.framework/**"]),
)
```

Notice that the `sdk_frameworks`, `weak_sdk_frameworks` and `sdk_dylibs` were
removed. This is because Dynamic Frameworks are already linked, and this
information should already be encoded in the binary. If your build starts
failing after this change, it means that the import was masking another library
that required an extra SDK framework/dylib. That library should be fixed
instead.

For Static Frameworks, migration would look like this:

```build
objc_framework(
name = "MyPrebuiltStaticFramework",
framework_imports = glob(["MyPrebuiltStaticFramework.framework/**"]),
sdk_dylibs = [...],
sdk_frameworks = [...]
weak_sdk_frameworks = [...],
)
apple_static_framework_import(
name = "MyPrebuildStaticFramework",
framework_imports = glob(["MyPrebuiltStaticFramework.framework/**"]),
sdk_dylibs = [...],
sdk_frameworks = [...]
weak_sdk_frameworks = [...],
)
```
5 changes: 2 additions & 3 deletions examples/ios/HelloWorldSwift/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ licenses(["notice"])
swift_library(
name = "Sources",
srcs = [
"Sources/AppDelegate.swift",
"Sources/BazelApp.swift",
],
data = [
"Resources/HelloWorldSwift.docc",
"Resources/Main.storyboard",
],
module_name = "Sources",
tags = ["manual"],
Expand Down Expand Up @@ -49,7 +48,7 @@ ios_unit_test(

genrule(
name = "CreateTestCoverageManifest",
srcs = ["Sources/AppDelegate.swift"],
srcs = ["Sources/BazelApp.swift"],
outs = [
"CoverageManifest.instrumented_files",
],
Expand Down
58 changes: 28 additions & 30 deletions examples/ios/HelloWorldSwift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
42 changes: 0 additions & 42 deletions examples/ios/HelloWorldSwift/Resources/Main.storyboard

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import UIKit
import SwiftUI

// Shim to compile with older Xcodes.
#if !swift(>=4.2)
extension UIApplication {
typealias LaunchOptionsKey = UIApplicationLaunchOptionsKey
}
#endif

/// The ``AppDelegate`` for the application.
/// This class is the entry point for the application and is responsible for the lifecycle of it.
@UIApplicationMain
public class AppDelegate: NSObject, UIApplicationDelegate {

/// The window of the application.
public var window: UIWindow?

/// The start of the application.
public func application(
_ application: UIApplication,
didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?
) -> Bool {
return true
@main
struct BazelApp: App {
var body: some Scene {
WindowGroup {
Text("Hello World")
.accessibility(identifier: "HELLO_WORLD")
}
}

/// A foo API to test DooC documentation generation.
Expand Down
2 changes: 1 addition & 1 deletion examples/ios/HelloWorldSwift/Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import XCTest

final class HelloWorldSwiftTests: XCTestCase {
func testInit() {
XCTAssertNotNil(AppDelegate())
XCTAssertNotNil(BazelApp())
}
}
Loading

0 comments on commit e8d412e

Please sign in to comment.