Skip to content

Conversation

@codeman9
Copy link

@codeman9 codeman9 commented Nov 3, 2025

Author's note: This was most all generated by AI. I verified the functionality works as I intend and apologize if the coding conventions aren't of the highest quality.

Summary

This PR adds support for building Swift packages with complex C dependencies, specifically enabling aws-crt-swift and aws-sdk-swift to build successfully.

Changes

Umbrella Directory Modulemaps

  • Added umbrella directory support to modulemap generation (matching SPM behavior)
  • Prevents atomics redefinition errors by only processing headers when explicitly included
  • Modified generate_modulemap.bzl and module_maps.bzl

Framework Auto-Detection

  • Scan C source files for #include <Framework/Header.h> patterns
  • Automatically add -framework linker flags for detected Apple frameworks
  • Handles cases where frameworks aren't explicitly declared in Package.swift

Default Public Headers Path

  • Default to include/ directory when publicHeadersPath is not specified
  • Remove include/ from exclude patterns (SPM doesn't exclude public headers)

Excluded Directory Headers

  • Collect headers from excluded directories (SPM excludes only affect compilation)
  • Makes headers available for inclusion even when in excluded directories

Examples

Added two examples demonstrating the fixes:

  • aws_crt_example: Directly tests aws-crt-swift
  • aws_sdk_example: Tests full AWS SDK for Swift (transitively depends on aws-crt-swift)

Both examples build and run successfully.

Testing

cd examples/aws_crt_example && bazel test //...
cd examples/aws_sdk_example && bazel run //:AwsSdkExample

- Add umbrella directory modulemap generation to match SPM behavior
- Add framework detection: scan C source files for framework imports and auto-link
- Add default include/ path handling when publicHeadersPath is not specified
- Add header collection from excluded directories (SPM excludes only affect compilation)
- Add aws_crt_example demonstrating aws-crt-swift building successfully

Fixes enable building Swift packages with complex C dependencies that have:
- Inline implementation files (.inl) that should be conditionally included
- Default public header paths (include/)
- Excluded directories containing needed headers
- System framework dependencies not declared in Package.swift

The umbrella directory approach prevents atomics redefinition errors by only
processing headers when explicitly included, rather than importing all headers
upfront when listed individually in the modulemap.
This example builds and runs successfully, demonstrating that all the fixes
for complex C dependencies work with aws-sdk-swift, which transitively
depends on aws-crt-swift and its complex C library dependencies.
@cgrindel cgrindel changed the title Add support for aws-crt-swift and complex C dependencies feat: add support for aws-crt-swift and complex C dependencies Nov 4, 2025
Copy link
Owner

@cgrindel cgrindel left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! I will dive into the review later today. However, I noticed that this PR does not update the example_infos. After doing that, you will need to run bazel run //:tidy which will update the generated CI file.

- Added aws_crt_example and aws_sdk_example to example_infos.bzl
- Ran bazel run //:tidy to update CI workflow and deleted_packages
- CI will now test both new examples on macOS
Copy link
Owner

@cgrindel cgrindel left a comment

Choose a reason for hiding this comment

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

Overall, looks good. Most of my comments are formatting issues. Thanks, again, for the contribution!

- Update .bazelrc files to use shared config imports
- Update do_test script to use BIT_BAZEL_BINARY
- Wrap long lines in MODULE.bazel to stay under 80 chars
- Refactor framework detection with helper function and constants
- Move header extensions to constants
- Improve line wrapping and formatting throughout
Both examples now include cgrindel_bazel_starlib dependency which is required
by the shared.bazelrc configuration.
@codeman9 codeman9 requested a review from cgrindel November 5, 2025 20:29
Copy link
Owner

@cgrindel cgrindel left a comment

Choose a reason for hiding this comment

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

It looks like we are missing a do_test file for the aws_sdk_example. Once that is added, we should be good to go.

- Add .bazelignore files to exclude .build directories from Bazel
- Add Gazelle targets for automated BUILD file generation
- Add tidy targets to run Gazelle updates
- Add swift_package_tool targets for package updates
- Update MODULE.bazel files with Gazelle dependencies and swift_deps_info
- Add do_test script for aws_sdk_example
- Update do_test script for aws_crt_example to run tidy
- Exclude Tests directory from Gazelle in aws_crt_example
- Fix repository name references to use build_bazel_rules_swift
- Standardize bash options and formatting in do_test scripts
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