bazelbuild / bazelbuild/rules_swift

Swift library is getting invalidated and recompiled when private headers change in Objective-C dependency

Open
#1,301 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
353
Forks
172
Avg merge
23h 14m
Merged PRs (30d)
8

Description

Likely coming from https://github.com/bazelbuild/rules_swift/blob/69df97201ef4274e87b68481fddadc87d8cb50c0/swift/toolchains/config/compile_config.bzl#L1450 includes all private and public transitive headers.

Running `bazel aquery "deps(//examples/apple/objc_interop:Printer)"` confirms `Private.h` header that is in srcs (ie private) is part of inputs of `Compiling Swift module //examples/apple/objc_interop:Printer` action
```
action 'Compiling Swift module //examples/apple/objc_interop:Printer'
Mnemonic: SwiftCompile
Target: //examples/apple/objc_interop:Printer
Configuration: darwin_arm64-fastbuild
Execution platform: @platforms//host:host
ActionKey: f65865cb7a00d8996f036bcd31777ff98e6e2ac928c348fdd6fa8c89dd1dfb2e
Inputs: [bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/PrintStream_modulemap/_/module.modulemap, bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer.output_file_map.json, bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/tools/worker/worker, bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/internal/_middlemen/tools_Sworker_Sworker-runfiles, examples/apple/objc_interop/OIPrintStream.h, examples/apple/objc_interop/Printer.swift, examples/apple/objc_interop/Private.h, swift/toolchains/config/const_protocols_to_gather.json]
Outputs: [bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer.macro-expansions (TreeArtifact), bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer_objs/Printer.swift.o, bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer_objs/Printer.swift.swiftconstvalues, bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/examples_apple_objc_interop_Printer.swiftdoc, bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/examples_apple_objc_interop_Printer.swiftmodule, bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/examples_apple_objc_interop_Printer.swiftsourceinfo, bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/generated_header/Printer-Swift.h]
Environment: [APPLE_SDK_PLATFORM=MacOSX, APPLE_SDK_VERSION_OVERRIDE=14.0, PATH=/bin:/usr/bin:/usr/local/bin, XCODE_VERSION_OVERRIDE=15.0.0.15A240d]
Command Line: (exec bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/tools/worker/worker \
swiftc \
-target \
arm64-apple-macos13.0 \
-sdk \
__BAZEL_XCODE_SDKROOT__ \
-debug-prefix-map \
'__BAZEL_XCODE_DEVELOPER_DIR__=/PLACEHOLDER_DEVELOPER_DIR' \
-file-prefix-map \
'__BAZEL_XCODE_DEVELOPER_DIR__=/PLACEHOLDER_DEVELOPER_DIR' \
'-Xwrapped-swift=-bazel-target-label=@@//examples/apple/objc_interop:Printer' \
-emit-object \
-output-file-map \
bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer.output_file_map.json \
-Xfrontend \
-no-clang-module-breadcrumbs \
-emit-module-path \
bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/examples_apple_objc_interop_Printer.swiftmodule \
-emit-objc-header-path \
bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/generated_header/Printer-Swift.h \
-emit-const-values-path \
bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer_objs/Printer.swift.swiftconstvalues \
-Xfrontend \
-const-gather-protocols-file \
-Xfrontend \
swift/toolchains/config/const_protocols_to_gather.json \
-DDEBUG \
-Onone \
-Xfrontend \
-no-serialize-debugging-options \
-enable-testing \
-gline-tables-only \
'-Xwrapped-swift=-debug-prefix-pwd-is-dot' \
'-Xwrapped-swift=-file-prefix-pwd-is-dot' \
-module-cache-path \
bazel-out/darwin_arm64-fastbuild/bin/_swift_module_cache \
'-Xwrapped-swift=-macro-expansion-dir=bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/Printer.macro-expansions' \
-Xcc \
-iquote. \
-Xcc \
-iquotebazel-out/darwin_arm64-fastbuild/bin \
-Xcc \
'-fmodule-map-file=bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/PrintStream_modulemap/_/module.modulemap' \
-Xfrontend \
-color-diagnostics \
-enable-batch-mode \
-module-name \
examples_apple_objc_interop_Printer \
-enable-bare-slash-regex \
-parse-as-library \
-static \
-Xcc \
-O0 \
-Xcc \
'-DDEBUG=1' \
examples/apple/objc_interop/Printer.swift)
# Configuration: ed8e8684eb5cd4576c9547de6ce9b0f2ecde34f2a5ec7d6f3d71fa9ce8a87dbf
# Execution platform: @@platforms//host:host
ExecutionInfo: {requires-darwin: '', requires-worker-protocol: json, supports-workers: 1, supports-xcode-requirements-set: ''}
```

Repro: https://github.com/ivan-golub/rules_swift/pull/1

Contributor guide

Open the contributing guide

Research direction

Inspect swift/toolchains/config/compile_config.bzl around line 1450 and reproduce the action inputs with the reported bazel aquery command for //examples/apple/objc_interop:Printer. Compare the inputs for the SwiftCompile action with the public and private Objective-C headers in examples/apple/objc_interop; done means changing Private.h no longer invalidates and recompiles the Swift library.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, swift
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.