[iOS] Custom framework add to chromium

422 views
Skip to first unread message

Radu Rad

unread,
Mar 7, 2023, 7:09:43 PM3/7/23
to Chromium-dev
Hello,

I've seen a couple of post regarding adding an external/custom framework to chromium.
Followed the suggestions there (adding frameworks, framework_dirs, bundle_data) but it does not seam to make a change.

Due to not including the custom framework properly, have following issues:
- not able to use the framework headers inside the chromium (e.g. #import <CustomFramework/CustomFramework.h>
- library not included within the app bundle when launching on a device(e.g Library not found: @rpath/CustomFramework

Any help regarding how to correctly include a custom framework and be able to use it inside chromium code base?

Thank you.

Sylvain Defresne

unread,
Mar 8, 2023, 4:47:58 AM3/8/23
to radu...@gmail.com, Chromium-dev
If you want to link with a pre-built framework (i.e. built by a separate tool before running ninja), then you have to
  1. define a config, say `custom_framework_config` to declare frameworks and framework_dir variables,
  2. add this config to all target the tries to use the framework, i.e. include `configs += [ ":custom_framework_config" ]
  3. add a bundle_data rule target listing the files from the framework to package in the app (if possible list all of them)
  4. add a dependency to the bundle_data target in your final ios_app_bundle target (could be indirectly).
So, say that you put the pre-build framework in $absolute_path_to_framework (note, you cannot use environment variables in gn, so you have to substitute the real path in the fragment I put below), then you would do the following:

config("custom_framework_config") {
  frameworks = [ "CustomFramework.framework" ]
  framework_dirs = [ "$absolute_path_to_framework" ]
}

bundle_data("custom_framework_bundle_data") {
  sources = [
      "$absolute_path_to_framework/CustomFramework.framework/CustomFramework",
      "$absolute_path_to_framework/CustomFramework.framework/Info.plist",
      # List all the other files, if the framework contains directories, you'll
      # needs to use multiple bundle_data targets, one per sub-directory.
  ]
  outputs = [ "{{bundle_resources_dir}}/Frameworks/CustomFramework.framework/{{source_file_part}}" ]
}

source_set("some_code_that_uses_the_framework") {
  sources = [ ... ]
  configs += [ ":custom_framework_config" ]
  deps = [ ":custom_framework_bundle_data" ]
}

ios_app_bundle("my_app") {
  deps = [ ":some_code_that_uses_the_framework" ]
  ...
}
  
If you want to build the framework as part of building Chromium, then you would have to define rules to build the framework. You can look at how this is done for lottie for example in //ios/third_party/lottie/BUILD.gn.

Hope this helps,
-- Sylvain

Radu Rad

unread,
Mar 8, 2023, 1:59:18 PM3/8/23
to Chromium-dev, Sylvain Defresne, Chromium-dev, radu...@gmail.com
Hi Sylvian,

This helps a lot, thank you.

I was able to successfully embed the framework (pre-built one, signed with same team as the app, otherwise it fails) within the app bundle and to use the framework inside chromium code as well with a similar gn file.

However, after doing some clean up of the gn file, I'm not able anymore to successfully pass the linking stage, as my framework symbols are not recognized anymore. Tried with your gn configuration as well and same results. Not sure what is causing this.
Do you know if during the linking stage the framework_dirs variable is enough for linking the new framework symbols. For reference, I see that the linker_driver.py is including the framework path, judging by this argument  "-F../../path_to_framework"

Thank you again,
Radu

Radu Rad

unread,
Mar 8, 2023, 2:00:48 PM3/8/23
to Chromium-dev, Sylvain Defresne, Chromium-dev, radu...@gmail.com
Hi Sylvain,

A follow up to my previous reply regarding linker undefined symbols. It seams the issue was on my side, during clean up I've rebuild my custom framework and left out the exported part. After correctly re-building it the linker issues are gone as it successfully finds the missing exported symbols inside the custom framework.

Thank you a lot for all the help,
Radu.

On Wednesday, March 8, 2023 at 11:47:58 AM UTC+2 Sylvain Defresne wrote:

Sylvain Defresne

unread,
Jul 3, 2024, 4:54:54 AM (24 hours ago) Jul 3
to Priyonto M Rahman, Chromium-dev
Hello,
I have no idea whether a Swift framework will work or not. I presume that if the framework exposes an Objective-C API then that part should be usable, however, if the framework exposes a pure Swift API, then it may not work. The reason is that we may have to pass extra flags to the swift compiler but I have no idea which ones.

TL;DR: using swift framework is unsupported, and you are probably on your own here.
-- Sylvain

On Wed, Jul 3, 2024 at 10:06 AM Priyonto M Rahman <priy...@gmail.com> wrote:

Hello Sylvian, 
I am running through a similar issue, but in my case I am trying to integrate a Swift framework. This approach works for me for ObjC framework, but somehow not with Swift framework.
I do not get any compile error, and contents inside the framework seems to be in place too, but whenever I try to import the framework from the swift file using import SomeSDK (framework added as deps on the code used to call that framework) I get no such module error. 
Is custom Swift framework expected to work or I am missing anything? Any help/suggestions would be great :) Thanks
- Priyonto

Priyonto M Rahman

unread,
Jul 3, 2024, 2:36:58 PM (14 hours ago) Jul 3
to Chromium-dev, Sylvain Defresne, Chromium-dev

Hello Sylvian, 
I am running through a similar issue, but in my case I am trying to integrate a Swift framework. This approach works for me for ObjC framework, but somehow not with Swift framework.
I do not get any compile error, and contents inside the framework seems to be in place too, but whenever I try to import the framework from the swift file using import SomeSDK (framework added as deps on the code used to call that framework) I get no such module error. 
Is custom Swift framework expected to work or I am missing anything? Any help/suggestions would be great :) Thanks
- Priyonto

On Wednesday 8 March 2023 at 20:00:48 UTC+1 Radu Rad wrote:

Priyonto M Rahman

unread,
Jul 3, 2024, 2:36:59 PM (14 hours ago) Jul 3
to Chromium-dev, Sylvain Defresne, Chromium-dev
Hi Sylvain, 
Thanks for writing back promptly and confirming. Guess I will have to fiddle around the swift compiler. In case you get any pointers at some point please share? Thanks :) 

- Priyonto
Reply all
Reply to author
Forward
0 new messages