MobileNativeFoundation/rules_xcodeproj

Bug: Missing clangs arg count

luispadron opened this issue · 14 comments

Description

A user reported an issue where they were on one commit using Xcode 15.1 where things were working correctly. They switched to a commit which uses Xcode 15.0.1 and run into generation errors during project generation:

Generating ".cashcli/Projects/CashApp.xcodeproj"
Starting local Bazel server and connecting to it...
INFO: Invocation ID: fda96df3-b7f4-47d2-96c0-3eeca4eae007
INFO: Analyzed target @rules_xcodeproj~1.15.0~internal~rules_xcodeproj_generated//generator/.cashcli/Projects/CashApp:CashApp (799 packages loaded, 53174 targets configured).
INFO: Found 1 target...
ERROR: Code/SystemResources/AppDependencies/BUILD.bazel:12:15: Generating bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.build_settings failed: (Exit 1): universal_target_build_settings failed: error executing command (from target //Code/SystemResources/AppDependencies:AppDependencies) 
  (cd /private/var/tmp/_bazel_<bradfol>/907fcb5025b8b52c1255ae7b70e7bf3a/rules_xcodeproj.noindex/build_output_base/execroot/_main && \
  exec env - \
  bazel-out/darwin_arm64-opt-exec-2B5CBBC6-ST-477482371507/bin/external/rules_xcodeproj~1.15.0/tools/generators/target_build_settings/universal_target_build_settings 1 bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.build_settings bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.debug_settings 0 1 bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies_swift.rules_xcodeproj.debug_settings '' 0 0 '' '' 0 '' '' '' 0 '' '' bazel-out/darwin_arm64-opt-exec-2B5CBBC6-ST-477482371507/bin/external/rules_swift~1.13.0/tools/worker/worker swiftc @bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.build_settings-0.params --- ---)
# Configuration: ba4f66d6c1caab0757ed204ea2949fcf8a4e0a53735846a4b89f2b6948d9fb93
# Execution platform: @local_config_platform//:host
ERROR: Internal precondition failure:
tools/generators/lib/PBXProj/src/TargetSwiftDebugSettings.swift:34: "/private/var/tmp/_bazel_<user>/907fcb5025b8b52c1255ae7b70e7bf3a/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies_swift.rules_xcodeproj.debug_settings": Missing clang args count
Please file a bug report at https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
ERROR: Code/SystemResources/AppDependencies/BUILD.bazel:12:15: Generating bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-7229f8b34da9/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.build_settings failed: (Exit 1): universal_target_build_settings failed: error executing command (from target //Code/SystemResources/AppDependencies:AppDependencies) 
  (cd /private/var/tmp/_bazel_<user>/907fcb5025b8b52c1255ae7b70e7bf3a/rules_xcodeproj.noindex/build_output_base/execroot/_main && \
  exec env - \
  bazel-out/darwin_arm64-opt-exec-2B5CBBC6-ST-477482371507/bin/external/rules_xcodeproj~1.15.0/tools/generators/target_build_settings/universal_target_build_settings 1 bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-7229f8b34da9/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.build_settings bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-7229f8b34da9/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.debug_settings 0 1 bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-7229f8b34da9/bin/Code/SystemResources/AppDependencies/AppDependencies_swift.rules_xcodeproj.debug_settings '' 0 0 '' '' 0 '' '' '' 0 '' '' bazel-out/darwin_arm64-opt-exec-2B5CBBC6-ST-477482371507/bin/external/rules_swift~1.13.0/tools/worker/worker swiftc @bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-7229f8b34da9/bin/Code/SystemResources/AppDependencies/AppDependencies.rules_xcodeproj.build_settings-0.params --- ---)
# Configuration: 79e7d91f01934ef122458860281ec7fd9d20f8f620a5175739a049a2c36d03cb
# Execution platform: @local_config_platform//:host
ERROR: Internal precondition failure:
tools/generators/lib/PBXProj/src/TargetSwiftDebugSettings.swift:34: "/private/var/tmp/_bazel_<user>/907fcb5025b8b52c1255ae7b70e7bf3a/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-7229f8b34da9/bin/Code/SystemResources/AppDependencies/AppDependencies_swift.rules_xcodeproj.debug_settings": Missing clang args count
Please file a bug report at https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
INFO: Elapsed time: 38.273s, Critical Path: 0.15s
INFO: 121 processes: 47 disk cache hit, 73 internal, 1 local.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target

Reproduction steps

From what what was reported to me:

  • Switch from Xcode 15.1 to Xcode 15.0.1 different commits after having generated with 15.1

Expected behavior

The project generates correctly

rules_xcodeproj version

1.15.0

Xcode version

15.1 -> 15.0.1

Bazel version

6.4.0

rules_apple version

3.1.1

rules_swift version

1.13.0

Additional information

No response

Workaround was to delete all caches, including our Bazel disk cache

I wonder, are you following the suggestion here to get Bazel to pick up correctly the change in Xcode versions? https://github.com/bazelbuild/rules_apple/blob/master/doc/common_info.md#xcode-version-selection-and-invalidation

@BalestraPatrick Yeah we have that all setup (correctly i hope). The command line builds are fine its just when generating the project that we see the failure.

Was /private/var/tmp/_bazel_<user>/907fcb5025b8b52c1255ae7b70e7bf3a/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/ios-arm64-min14.0-applebin_ios-ios_arm64-dbg-ST-1085b1e95571/bin/Code/SystemResources/AppDependencies/AppDependencies_swift.rules_xcodeproj.debug_settings empty? Did anything else change besides the Xcode version? Like deps?

That file should never be empty (

var data = Data()
data.appendArgs(clangArgs)
data.appendArgs(frameworkIncludes)
data.appendArgs(swiftIncludes)
try data.write(to: url)
), so this sounds like some odd disk cache poisoning issue...

The one thing we did which i think caused other build failures (and forced us to use our action_env cache buster) was we moved our Tools/Rules directory which contained all our rules to Bazel/. Users reported issues at the command line after this change and deleting disk cache was the only solution, so potentially related to that and not a bug in rules_xcodeproj?

Probably. I would need a repro to dig into this more. Looking at the code, it doesn't seem like this condition should be possible outside of cache poisoning.

We had another engineer report the same error (different target).

They reported deleting a target and then trying to generate a project. I don't believe an Xcode change was involved in this case but need to check with them.

Going to try to get a repro, so far haven't been able to myself.

Consistently hitting this just now in an internal project, tried to clean everything an no luck. Trying to wipe my disk cache now to see if that unblocks me. If I manage to find a repro will share it here as well.

EDIT: confirmed that after deleting my disk cache directory the issue is gone

An engineer just reported this again, should we reopen? It's not immediately obvious what's causing this but clearing out caches seems to fix this

For this recent case I don't believe there was any Xcode switching involved

Until we have a repro, I don't know what we can do. I'm not sure it's not a remote cache things, or a Bazel bug, or if it's something in rules_xcodeproj.

I also asked some questions about the content of files. I'm not even sure what the symptom is, let alone the root cause. Do you have more information on any of that?

Yeah I don't really know either, personally never run into it.

From the errors we've seen it's the debug_settings file but I haven't been able to look deeper at the contents, etc

I got a similar (but slightly different) report on internal CI, so going to reopen this (still without repro steps though):

(13:49:47) ERROR: /Users/vagrant/git/Modules/EventKit/BUILD.bazel:561:28: Generating bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min15.0-applebin_ios-ST-bd2bf54e2820/bin/Modules/EventKit/DebugLoggerInterface_swift.rules_xcodeproj.build_settings failed: (Killed): universal_target_build_settings failed: error executing WriteTargetBuildSettings command (from target //Modules/EventKit:DebugLoggerInterface_swift) 
  (cd /private/var/tmp/_bazel_vagrant/44b08d771321dac1bc850a6d84c72843/rules_xcodeproj.noindex/build_output_base/execroot/_main && \
  exec env - \
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_xcodeproj~/tools/generators/target_build_settings/universal_target_build_settings 1 bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min15.0-applebin_ios-ST-bd2bf54e2820/bin/Modules/EventKit/DebugLoggerInterface_swift.rules_xcodeproj.build_settings bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min15.0-applebin_ios-ST-bd2bf54e2820/bin/Modules/EventKit/DebugLoggerInterface_swift.rules_xcodeproj.debug_settings 1 '' '' 0 0 '' '' '' '' '' 0 '' '' bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_swift~/tools/worker/worker swiftc @bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min15.0-applebin_ios-ST-bd2bf54e2820/bin/Modules/EventKit/DebugLoggerInterface_swift.rules_xcodeproj.build_settings-0.params --- ---)