bazel-ios / rules_ios

Bazel rules for building iOS applications and frameworks
Apache License 2.0
278 stars 85 forks source link

`java.lang.RuntimeException` when building for multiple archs an `ios_application` that depends on an `apple_framework` #902

Closed vakhidbetrakhmadov closed 2 months ago

vakhidbetrakhmadov commented 2 months ago

Hi,

When building an ios_application from rules_apple that depends on an apple_framework, following error occures:

$ bazelisk build --apple_platform_type=ios --ios_multi_cpus=x86_64,sim_arm64 --//:test_case=apple_framework HelloWorldSwift
Analyzing: target //:HelloWorldSwift (90 packages loaded, 1135 targets configured)
    currently loading: @@build_bazel_rules_ios//rules/test_host_app
[1 / 1] checking cached actions
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ConfiguredTargetKey{label=//:HelloWorldSwift, config=BuildConfigurationKey[38f23fb72e03f0a597d6c10cf5be599a95e3ea63a333be1217596f4f4081746c]}' (requested by nodes 'ConfiguredTargetKey{label=//:HelloWorldSwift, config=BuildConfigurationKey[2e520ce0ae79be1571c07d6987a022b56061727d1a2cc69b5284af9c1a3729b9]}')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:550)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: net.starlark.java.eval.Starlark$UncheckedEvalException: IllegalStateException thrown during Starlark evaluation (//:HelloWorldSwift)
        at <starlark>.link_multi_arch_binary(<builtin>:0)
        at <starlark>._register_binary_linking_action(/private/var/tmp/_bazel_vakhid.betrakhmadov/683f29226f77b774d9de4d50b9c730af/external/build_bazel_rules_apple/apple/internal/linking_support.bzl:243)
        at <starlark>._ios_application_impl(/private/var/tmp/_bazel_vakhid.betrakhmadov/683f29226f77b774d9de4d50b9c730af/external/build_bazel_rules_apple/apple/internal/ios_rules.bzl:241)
Caused by: java.lang.IllegalStateException: Split transition keys are different between 'deps' [[Optional.of(ios_x86_64)]] and '$child_configuration_dummy' [[Optional.of(ios_sim_arm64), Optional.of(ios_x86_64)]]
        at com.google.common.base.Preconditions.checkState(Preconditions.java:854)
        at com.google.devtools.build.lib.rules.objc.AppleBinary.linkMultiArchBinary(AppleBinary.java:82)
        at com.google.devtools.build.lib.rules.objc.AppleStarlarkCommon.linkMultiArchBinary(AppleStarlarkCommon.java:311)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at net.starlark.java.eval.MethodDescriptor.call(MethodDescriptor.java:178)
        at net.starlark.java.eval.BuiltinFunction.fastcall(BuiltinFunction.java:78)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
        at net.starlark.java.eval.Eval.evalCall(Eval.java:682)
        at net.starlark.java.eval.Eval.eval(Eval.java:497)
        at net.starlark.java.eval.Eval.execAssignment(Eval.java:109)
        at net.starlark.java.eval.Eval.exec(Eval.java:268)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
        at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
        at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:179)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
        at net.starlark.java.eval.Eval.evalCall(Eval.java:682)
        at net.starlark.java.eval.Eval.eval(Eval.java:497)
        at net.starlark.java.eval.Eval.execAssignment(Eval.java:109)
        at net.starlark.java.eval.Eval.exec(Eval.java:268)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
        at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
        at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:179)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
        at com.google.devtools.build.lib.analysis.starlark.StarlarkRuleConfiguredTargetUtil.evalRule(StarlarkRuleConfiguredTargetUtil.java:100)
        at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:376)
        at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:194)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:1308)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:385)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:312)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:461)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

I have created a minimal repro example that can be found here: https://github.com/vakhidbetrakhmadov/ios_multi_cpus_repro.

To reproduce the error above, please run bazelisk build --apple_platform_type=ios --ios_multi_cpus=x86_64,sim_arm64 --//:test_case=apple_framework HelloWorldSwift.

As a comparison, when apple_framework is replaced with swift_library, it compiles just fine.

To observe that, please run bazelisk build --apple_platform_type=ios --ios_multi_cpus=x86_64,sim_arm64 --//:test_case=swift_library HelloWorldSwift.

Same is true when compiling for a single arch.

To observe that, please run bazelisk build --apple_platform_type=ios --ios_multi_cpus=x86_64 --//:test_case=apple_framework HelloWorldSwift or bazelisk build --apple_platform_type=ios --ios_multi_cpus=sim_arm64 --//:test_case=apple_framework HelloWorldSwift.

jszumski commented 2 months ago

I'm going to close this in favor of https://github.com/bazelbuild/rules_apple/issues/2518, thanks for investigating the issue though!