Skip to content

Header mapping for C target #8530

Open
Open
@cipolleschi

Description

@cipolleschi

Description

Hi there, I'm Riccardo, SWE @ Meta and core maintainer of React Native.

We are working on migrating React Native away from Cocoapods to Swift Package Manager.

React Native is 10 years old and it is a mixture of C++, Objective-C and Objective-C++.

One of the problem that we have is that our import/include statement and our folder structure is not standard. We have a folder named React, where all the Objecitve-C/C++ code is located. The React folder contains several subfolders which may contains source files or other subfolders.
To exaplain the problem, let's consider a file named RCTBridge.h. This file is located in the React/Base path, and the full path is React/Base/RCTBridge.h.

In theory, this file should be imprted using the full path: #import <React/Base/RCTBridge.h>.
However, in the whole codebase and in all the OSS projects that depends on React Native, this is imported with #import <React/RCTBridge.h>, effectively dropping the Base subfolder.

This works with Cocoapods because it allows to remap where the headers must be located. However, Swift PM does not have the same feature.

I also tried to use a custom module map, but the custom module map is never picked up by Swift Package Manager. When I explore the .swiftpm folder, I only find the automatically generated module.modulemap which content is different from what I specified.

Is there a way to achieve what we need? If not, would it be possible to implement a setting to achieve that?

Thank you in advance.

Expected behavior

We would like to enable source files to use the statement:

#import <React/RCTBridge.h>

to import an header file that is located in the React/Base/ subfolder.

Actual behavior

If we use #import <React/RCTBridge.h> the build step fails with a file not found error.

Steps to reproduce

  1. Clone https://github.com/cipolleschi/SPMRemapping/ this is a very small reproducer I prepared.
  2. swift build, this will fail because Root/MyObject.h can't be found.

Swift Package Manager version/commit hash

6.1

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0
Darwin mac 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041 arm64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions