Enabling building Apple Frameworks

97 views
Skip to first unread message

Yi

unread,
Feb 12, 2023, 10:26:23 PM2/12/23
to re2-dev
I made the following change: https://github.com/google/re2/pull/410 to the CMakeLists.txt to build the Apple Frameworks for macOS, iOS, tvOS, and watchOS. So, Apple developers can pull the framework file into their Xcode projects and use RE2 from there. Please let me know if I should create a Gerrit change.

Paul Wankadia

unread,
Feb 13, 2023, 2:35:29 AM2/13/23
to Yi, re2-dev
On Mon, Feb 13, 2023 at 2:26 PM Yi <yi.wan...@gmail.com> wrote:

I made the following change: https://github.com/google/re2/pull/410 to the CMakeLists.txt to build the Apple Frameworks for macOS, iOS, tvOS, and watchOS. So, Apple developers can pull the framework file into their Xcode projects and use RE2 from there. Please let me know if I should create a Gerrit change.

I'm not fundamentally opposed to supporting a framework build on Apple platforms, but could you please explain why it's needed? Also, it would need to be conditioned appropriately so that it wouldn't break existing users on Apple platforms that don't expect/want RE2 built as a framework. (Is there a framework equivalent to the BUILD_SHARED_LIBS option?) I'm very much opposed to exposing every .h file via PUBLIC_HEADER, however, and I see no strong reason to do so.

王益

unread,
Feb 13, 2023, 12:19:28 PM2/13/23
to Paul Wankadia, re2-dev
Why

Xcode is the official method for making apps for iOS, tvOS, and watchOS. You can use RE2 in an Xcode project in two ways. The first one doesn't change the current CMakeLists.txt file, but the user needs to do the following: (1) Make multiple libre2.a files, each for a different OS-arch combination, like libre2-ios-arm64, libre2-ios-simulator-arm64, libre2-ios-simulator-x86 64, libre2-tvos-arm64, and libre2-watchos-arm64. (2) Drag and drop all of these libre2-os-arch.a files into the Xcode project, and then set the project targets to the appropriate library. (3) Drag-and-drop the RE2 header files into the Xcode project and set the include path. Because of how complicated (3) was, Apple came up with the idea of Framework, which is a directory called a bundle that contains the header files and a certain version of libre2.a. My Pull Request makes it possible for these kinds of frameworks to be built for Apple platforms. It also lets us run a command called "xcodebuild -create-framework" after the process is done to combine all of these frameworks that depend on the platform into a higher-level bundle called "re2.xcframework." So Xcode users just drag and drop a single bundle into the project. This takes care of the difficulties in (1) and (2).

Conditional

This makes sense. CMake To get it, I think we can add a RE2_BUILD_FRAMEWORK option to my prototype Pull Request. CMake doesn't have a flag for "add_library" like BUILD_SHARED LIBS that lets you build frameworks. This is because the framework and shared/static libraries are not on the same logical layer. If BUILD SHARED LIBS is set, a framework does have a shared library. It has a static library if it is not set. However, we can condition the call to set_target_properties by using RE2_BUILD_FRAMEWORK AND APPLE.

Expose header files

Framework and XCFramework are used to release header files and libraries at the same time. "add library" needs to know which header files to add to the framework. But if you can split RE2 header files into a public group and an internal group, and make sure that public header files don't include internal ones, we can definitely avoid including all of them.

Paul Wankadia

unread,
Feb 13, 2023, 1:47:54 PM2/13/23
to 王益, re2-dev
On Tue, Feb 14, 2023 at 4:19 AM 王益 <yi.wan...@gmail.com> wrote:

Why

Xcode is the official method for making apps for iOS, tvOS, and watchOS. You can use RE2 in an Xcode project in two ways. The first one doesn't change the current CMakeLists.txt file, but the user needs to do the following: (1) Make multiple libre2.a files, each for a different OS-arch combination, like libre2-ios-arm64, libre2-ios-simulator-arm64, libre2-ios-simulator-x86 64, libre2-tvos-arm64, and libre2-watchos-arm64. (2) Drag and drop all of these libre2-os-arch.a files into the Xcode project, and then set the project targets to the appropriate library. (3) Drag-and-drop the RE2 header files into the Xcode project and set the include path. Because of how complicated (3) was, Apple came up with the idea of Framework, which is a directory called a bundle that contains the header files and a certain version of libre2.a. My Pull Request makes it possible for these kinds of frameworks to be built for Apple platforms. It also lets us run a command called "xcodebuild -create-framework" after the process is done to combine all of these frameworks that depend on the platform into a higher-level bundle called "re2.xcframework." So Xcode users just drag and drop a single bundle into the project. This takes care of the difficulties in (1) and (2).

TIL. Thank you very much for explaining that. :D

Conditional

This makes sense. CMake To get it, I think we can add a RE2_BUILD_FRAMEWORK option to my prototype Pull Request. CMake doesn't have a flag for "add_library" like BUILD_SHARED LIBS that lets you build frameworks. This is because the framework and shared/static libraries are not on the same logical layer. If BUILD SHARED LIBS is set, a framework does have a shared library. It has a static library if it is not set. However, we can condition the call to set_target_properties by using RE2_BUILD_FRAMEWORK AND APPLE.

Done in commit 9049cd2.

Expose header files

Framework and XCFramework are used to release header files and libraries at the same time. "add library" needs to know which header files to add to the framework. But if you can split RE2 header files into a public group and an internal group, and make sure that public header files don't include internal ones, we can definitely avoid including all of them.

Done in commit d074884 as a preparatory refactor.

Please feel free to test these changes (i.e. what's at HEAD) and let me know if further changes are necessary. They will be released in a couple of weeks when I tag 2023-03-01.

Reply all
Reply to author
Forward
0 new messages