Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding with objective Sharpie outputs huge files

I am trying to bind my swift framework with Xamarin. I am using objective Sharpie for this.

  • I have set 'Enable Bitcode' to 'No' in the framework.
  • Built the framework for running.
  • Use the following command for binding the header file.

sharpie bind -sdk iphoneos11.1 MyFramework.framework/Headers/MyFramework-Swift.h -output=MyFrameworkCS -namespace=MyFramework

I got the APIDefinitions.cs file but its more than 79 thousand lines and has lots of errors. The StructsAndEnums.cs file is huge as well.

My framework(and the .h file) has import statements for only UIKit, AVFoundation and Foundation. But the APIDefinitions.cs has this.

using System;
using AVFoundation;
using AudioToolbox;
using AudioUnit;
using CloudKit;
using CoreAnimation;
using CoreAudio;
using CoreData;
using CoreFoundation;
using CoreGraphics;
using CoreImage;
using CoreLocation;
using CoreMIDI;
using CoreMedia;
using CoreMidi;
using CoreText;
using CoreVideo;
using Darwin;
using Dispatch;
using FileProvider;
using Foundation;
using HyperSecureSDK;
using IOSurface;
using ImageIO;
using Intents;
using MediaToolbox;
using Metal;
using ObjCRuntime;
using ObjectiveC;
using OpenGLES;
using Security;
using UIKit;
using simd;

I am very new to Xamarin and super stuck here. Any help would be greatly appreciated!

like image 318
Srinija Avatar asked Dec 19 '22 02:12

Srinija


2 Answers

You need to define a scope so that not all of the other libraries are showing up in your APIDefinition.cs as stated in https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/examples/advanced/

You will notice that we passed a -scope build/Headers argument to Objective Sharpie. Because C and Objective-C libraries must #import or include other header files that are implementation details of the library and not API you wish to bind, the -scope argument tells Objective Sharpie to ignore any API that is not defined in a file somewhere within the -scope directory.

You will find the -scope argument is often optional for cleanly implemented libraries, however there is no harm in explicitly providing it.

This should remove all the bindings of other libraries in your APIDefinition.cs

sharpie bind -sdk iphoneos11.1 -scope MyFramework.framework/Headers/ MyFramework.framework/Headers/MyFramework-Swift.h
-output=MyFrameworkCS -namespace=MyFramework
like image 92
Philippe Creytens Avatar answered Feb 16 '23 18:02

Philippe Creytens


You need to limit your scope adding the path where the headers are living. Use the -scope command and library/Headers/ parameter.

eg. sharpie bind -sdk iphoneos11.2 -output myLibrary -scope myLibrary/Headers/ mainHeader.h

Hope can help you.

like image 37
Adlair Cerecedo-Mendez Avatar answered Feb 16 '23 17:02

Adlair Cerecedo-Mendez