Skip to content

Conversation

adincebic
Copy link
Contributor

Previously when building swift_import targets that depend on other swift_import targets with .swiftinterface files failed when using Bazel sandbox with error:

  cannot open file 'swift-syntax/arm64/SwiftSyntax.private.swiftinterface' (No such file or directory)

The SWIFT_ACTION_COMPILE_MODULE_INTERFACE action was missing transitive dependency files as inputs so I made sure that they are explicitly listed.

@adincebic adincebic force-pushed the adin/fix-module-interface-dependency-compilation branch from dd23624 to efa3f31 Compare September 27, 2025 14:04
@adincebic adincebic force-pushed the adin/fix-module-interface-dependency-compilation branch from 9ea7b48 to 89c0878 Compare October 8, 2025 13:10
@adincebic
Copy link
Contributor Author

@brentleyjones can I have your opinion on this one?


return ConfigResultInfo(
inputs = prerequisites.transitive_swiftmodules,
inputs = transitive_inputs,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it so prerequisites.transitive_swiftmodules has the right things (and probably rename it to transitive_included_modules... though maybe we don't do that for now to keep cherry-picks easier). Also, we should only add one or the other. We should add swift_module.swiftmodule if it exists, otherwise swift_module.private_swiftinterface, otherwise swift_module.swiftinterface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running into issues if I pick only one of those files since -swiftmodule is getting generated even though it is not explicitly passed. I am assuming that .swiftmodule is produced as a result of building swift_import target with .swiftinterface.
Basically we need to keep logic as is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming that .swiftmodule is produced as a result of building swift_import target with .swiftinterface

Ideally we wouldn't compile .swiftinterface and just pass it along as an importable module. You should only need to compile a (private) interface into a module if you needed access to package/protected types, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really familiar with how swift_import rule is implemented. But essentially I am building https://github.com/wesprint-io/swift-syntax-prebuilt/releases and it only exposes swift_import targets with no .swiftmodule files yet they are produced at some point and if I pick either .swiftmodule or .swiftinterface the build fails because it won't pick up the .swiftinterface since .swiftmodule appears and it gets selected. Only way that I was able to make it work is by including both of them like in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brentleyjones given the following swift_import target

swift_import(
    name = "SwiftBasicFormat",
    archives = select({":darwin_arm64": ["arm64/libSwiftBasicFormat.a"]}),
    module_name = "SwiftBasicFormat",
    swiftdoc = select({":darwin_arm64": "arm64/SwiftBasicFormat.swiftdoc"}),
    swiftinterface = select({":darwin_arm64": "arm64/SwiftBasicFormat.swiftinterface"}),
    visibility = ["//visibility:public"],
    deps = [":SwiftSyntax"],
)

after executing build bazel build :SwiftBasicFormat I see the following files produced

SwiftSyntax601.swiftmodule-0.params
SwiftBasicFormat.swiftmodule
SwiftBasicFormat.swiftmodule-0.params
SwiftSyntax.swiftmodule
SwiftSyntax.swiftmodule-0.params
SwiftSyntax509.swiftmodule
SwiftSyntax509.swiftmodule-0.params
SwiftSyntax510.swiftmodule
SwiftSyntax510.swiftmodule-0.params
SwiftSyntax600.swiftmodule
SwiftSyntax600.swiftmodule-0.params
SwiftSyntax601.swiftmodule

I also added print staments to track this while build is in progress

DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax509.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax509.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax510.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax510.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax600.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax600.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax601.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax601.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax509.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax509.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax510.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax510.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax600.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax600.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax601.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax601.swiftinterface>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2015:22: Adding swiftmodule: <generated file SwiftSyntax.swiftmodule>
DEBUG: /private/var/tmp/_bazel_adincebic/636060455adfb7fc752026ce1a8908d3/external/rules_swift+/swift/toolchains/config/compile_config.bzl:2018:22: Adding swiftinterface: <source file arm64/SwiftSyntax.private.swiftinterface>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants