Flipper: Swift support for Sonar

Created on 11 Jun 2018  路  13Comments  路  Source: facebook/flipper

Currently Sonar doesn't build with Swift projects due to its dependecies being written in c++.
There are few files which are referenced by sonar's Objective-C wrapper which has reference to header with C++ code. We can either get rid off those references from header files to support swift.

enhancement iOS

Most helpful comment

@bolismauro, @priteshrnandgaonkar you can try https://appspector.com instead. Works with swift and has more features :)

All 13 comments

Is there any plan to fix this or an ETA? The tool seems extremely powerful and interesting and I have several use cases for it but unfortunately our projects are swift only

@bolismauro, @priteshrnandgaonkar you can try https://appspector.com instead. Works with swift and has more features :)

Looks very cool but it is not what I'm looking for :(

interesting, are you looking for some specific feature? @bolismauro

I want to play with layout editor and the ability of developing custom things within the tool.
Also I prefer not to go trough a 3rd party service I cannot control.

I think this isn't the proper place to discuss this though. Let's keep it clean for the sonar swift support

@bolismauro Currently its isn't in our internal roadmap.We would expect open source community to fix it. But seeing on how things pan out we may end up working on it. But I can't see that happen soon.

Gotcha. I unfortunately don't have strong c++ knowledge but I think I'll try anyway. Do you have some suggestions about how to proceed and what need to be fixed?

Just try and get rid off the c++ in the header files of sonar. In header files you may also find other inported dependency that has c++ in it. So one has to create a c wrapper over it and then use in the public headers of sonar.Basically we have to make sure that headers doesn't have c++ in it.

I took a look into building Sonar for use in Trestle, which is a Swift project. As far as I can see, Cocoapods should be able to configure the Sonar/SonarKit pods to build into modules which Swift can use using :modular_headers => true. Swift projects use pods which have C++ in them all the time - Sentry is a good example of a pod which has no Swift and some C++ and is usuable from a Swift project.

Here's what my Podfile looks like:

  pod 'RSocket', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/third-party-podspecs/RSocket.podspec'
  pod 'DoubleConversion', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/third-party-podspecs/Folly.podspec'
  pod 'PeerTalk', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/third-party-podspecs/PeerTalk.podspec'
  pod 'Yoga','~>1.8.1', :modular_headers => true
  pod 'Sonar', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/xplat/Sonar/Sonar.podspec'
  pod 'SonarKit', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/SonarKit.podspec', :modular_headers => true
  pod 'SonarKit/SonarKitLayoutComponentKitSupport', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/SonarKit.podspec'
  pod 'SonarKit/SKIOSNetworkPlugin', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/SonarKit.podspec'
  pod 'ComponentKit', :podspec => 'https://raw.githubusercontent.com/facebook/Sonar/master/iOS/third-party-podspecs/ComponentKit.podspec'

  post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
      if ['YogaKit'].include? target.name
          target.build_configurations.each do |config|
              config.build_settings['SWIFT_VERSION'] = '3.0.2'
          end
      end
    end
  end

Not running into any errors due to C++ used in headers like @priteshrnandgaonkar said, however I'm seeing the same error as in #28 ('iosfwd' file not found). Here's the full trace:

/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/SonarKit/SonarCppBridgingConnection.h:8:9: note: while building module 'Sonar' imported from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/SonarKit/SonarCppBridgingConnection.h:8:
#import <Sonar/SonarConnection.h>
        ^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Sonar-umbrella.h"
        ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/Sonar-umbrella.h:14:9: note: in file included from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/Sonar-umbrella.h:14:
#import "SonarClient.h"
        ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarClient.h:11:10: note: in file included from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarClient.h:11:
#include <Sonar/SonarConnectionImpl.h>
         ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarConnectionImpl.h:11:10: note: in file included from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarConnectionImpl.h:11:
#include <Sonar/SonarConnection.h>
         ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarConnection.h:11:10: note: in file included from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarConnection.h:11:
#include <Sonar/SonarResponder.h>
         ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarResponder.h:11:10: note: in file included from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Sonar/SonarResponder.h:11:
#include <folly/json.h>
         ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/Folly/folly/json.h:43:10: error: 'iosfwd' file not found
#include <iosfwd>
         ^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "SonarKit-umbrella.h"
        ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/SonarKit/SonarKit-umbrella.h:13:9: note: in file included from /Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/SonarKit/SonarKit-umbrella.h:13:
#import "SonarCppBridgingConnection.h"
        ^
/Users/noahgilmore/code/trest-ios/Trest/../Pods/Headers/Public/SonarKit/SonarCppBridgingConnection.h:8:9: error: could not build module 'Sonar'
#import <Sonar/SonarConnection.h>
        ^
/Users/noahgilmore/code/trest-ios/Trest/Trest/AppDelegate.swift:16:8: error: could not build Objective-C module 'SonarKit'
import SonarKit
       ^

I could be wrong but the solution to this might just be an include path configuration fix. Any advice here is appreciated :) @bolismauro were you able to make any headway here?

Quick update: I managed to get a Swift app talking to Sonar today. The main bug was a search paths issue: SonarKit/SonarClient.h was including SonarPlugin.h, but because of how Cocoapods does default search paths, it was including Sonar/SonarPlugin.h, a C++ header, instead of SonarKit/SonarPlugin.h, an Obj-C header.

This is also the cause of #28 - iosfwd is part of the C++ standard library and imported in the C++ version of the header, Sonar/SonarPlugin.h.

I'll try to get a PR up in the next couple of days with a Swift sample project and the necessary podspec changes :)

Sorry for not having answered before, I took some time off and I didn't see the notification.

It is amazing that you managed to make it work :) can't wait to try your PR! Thanks a lot!

@bolismauro PR is up (#106), let me know if it works for you (you should be able to point your Podfile at the podspecs in my branch). Note that the Network and Layout plugins are not yet supported in Swift (decided to take care of implementing core client support first).

It works perfectly!
Thanks a lot for have worked on this, I struggled to find the proper time and it is great that you guys are pushing this forward :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paschaldev picture paschaldev  路  3Comments

richardtop picture richardtop  路  3Comments

orlandobustamantep picture orlandobustamantep  路  3Comments

keshavamurthy1 picture keshavamurthy1  路  4Comments

hackaprende picture hackaprende  路  4Comments