Skip to content

Commit 9b3ba29

Browse files
authored
Fix import_middleman broken with Bazel 7 + sandbox mode (#910)
What changed and why: 1. added test case that broke with main, under sandbox mode and bazel 7 and `arm64_simulator_use_device_deps` feature turned on : To repro locally, run `bazel build //tests/ios/unit-test/test-imports-app:TestImports-App --config=ios --features apple.arm64_simulator_use_device_deps` and it fails. But success if change `.bazelversion` to 6.4.0 The error is "unable to find header `basic.h`" which is the same issue with what our own repo has. Also this only break Objc side not swift side (probably because CcInfo is more used by objc_library?) 2. To fix above: use the compilation_context generated originally. The original fix #873 is missing fields inside `compilation_context` such as `headers`. So might as well use the original CcInfo collected, and only recreate the linking context. BTW i believe the original PR aims to fix this kind of error in bazel 7: ``` ld: building for 'iOS-simulator', but linking in object file (/path/to/someframework.framework[arm64][2] built for 'iOS' ``` Which is the error we got if trying to just use the original CcInfo. 3. Update the test matrix to have sandbox mode for the tests for `arm64_simulator_use_device_deps` feature Tests done: Without the change from #903 some checks should still fail but the ones using `arm64_simulator_use_device_deps` should be green
1 parent a6e6e77 commit 9b3ba29

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ jobs:
8080
path: bazel-testlogs
8181

8282
build_arm64_simulator:
83-
name: arm64 Simulator (Bazel ${{ matrix.bazel_version }} / Xcode ${{ matrix.xcode_version }})
83+
name: arm64 Simulator (Bazel ${{ matrix.bazel_version }} / Xcode ${{ matrix.xcode_version }} / Sandbox ${{ matrix.sandbox }})
8484
runs-on: macos-14
8585
strategy:
8686
fail-fast: false
8787
matrix:
8888
bazel_version: [6.5.0, 7.1.0]
89+
sandbox: [true, false]
8990
xcode_version: [15.2]
9091
env:
9192
XCODE_VERSION: ${{ matrix.xcode_version }}
@@ -94,6 +95,10 @@ jobs:
9495
- uses: actions/checkout@v4
9596
- name: Preflight Env
9697
run: .github/workflows/preflight_env.sh
98+
- if: matrix.sandbox
99+
name: Enable sandbox mode
100+
run: |
101+
echo "build --config=sandboxed" >> user.bazelrcc
97102
- name: Build and Test
98103
run: |
99104
bazelisk build \

rules/import_middleman.bzl

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,13 @@ def _file_collector_rule_impl(ctx):
265265
**objc_provider_fields
266266
)
267267

268-
# Create the CcInfo provider, linking information from this is used in Bazel 7+.
269-
cc_info = None
268+
dep_cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep]
269+
cc_info = cc_common.merge_cc_infos(cc_infos = dep_cc_infos)
270270
if is_bazel_7:
271+
# Need to recreate linking_context for Bazel 7 or later
272+
# because of https://github.com/bazelbuild/bazel/issues/16939
271273
cc_info = CcInfo(
272-
compilation_context = cc_common.create_compilation_context(
273-
framework_includes = depset(
274-
transitive = [
275-
dep[CcInfo].compilation_context.framework_includes
276-
for dep in ctx.attr.deps
277-
if CcInfo in dep
278-
],
279-
),
280-
),
274+
compilation_context = cc_info.compilation_context,
281275
linking_context = cc_common.create_linking_context(
282276
linker_inputs = depset([
283277
cc_common.create_linker_input(
@@ -297,10 +291,6 @@ def _file_collector_rule_impl(ctx):
297291
]),
298292
),
299293
)
300-
else:
301-
dep_cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep]
302-
cc_info = cc_common.merge_cc_infos(cc_infos = dep_cc_infos)
303-
304294
return [
305295
DefaultInfo(files = depset(dynamic_framework_dirs + replaced_frameworks)),
306296
objc,

tests/ios/unit-test/test-imports-app/empty.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Foundation
22
import SomeFramework
3+
import Basic
34

45
@objc public class EmptyClass: NSObject {
56

67
@objc public static func emptyDescription() -> String {
8+
print(BasicString)
9+
print(EmptyClass.emptyDescription)
710
return ""
811
}
912

tests/ios/unit-test/test-imports-app/main.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import "Header.h"
22
#import <TestImports-App/Header.h>
33
#import <TestImports-App/TestImports_App-Swift.h>
4+
#import <Basic/Basic.h>
45

56
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
67
@import UIKit;
@@ -18,6 +19,7 @@ - (BOOL)application:(UIApplication *)__unused application didFinishLaunchingWith
1819
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
1920
self.window.rootViewController = [UIViewController new];
2021
self.window.rootViewController.view.backgroundColor = UIColor.whiteColor;
22+
NSLog([NSString stringWithFormat:@"%@ %ld", BasicString, BasicVal_DownloadTheApp]);
2123
NSAssert([EmptyClass emptyDescription] != nil, @"Empty class description exists");
2224
NSAssert([[EmptyClass new] emptyDescription] != nil, @"Empty instance description exists");
2325
[self.window makeKeyAndVisible];

0 commit comments

Comments
 (0)