Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Xamarin is actually doing when using an iOS build host?

Tags:

ios

build

xamarin

I've noticed that there is a possibility in Xamarin to connect Visual Studio to an iOS build host.

What is this build host, is there any documentation about its architecture? What code does Xamarin.iOS send to this build host?

[Edit]

I want, as a personal project, make an iOS build host in Windows. I know that this can be achieved, and I'm sure that technically, I have all the needed tools to re-create one. My concerns is about the architecture of an original iOS build host. I want to know what is the communication between Xamarin and a iOS build host, and what is the build flow. And this is not documented.

like image 499
Léon Pelletier Avatar asked Mar 08 '14 19:03

Léon Pelletier


People also ask

Can Xamarin be used for iOS?

Xamarin. iOS allows developers to create native iOS applications using the same UI controls that are available in Objective-C and Xcode, except with the flexibility and elegance of a modern language (C#), the power of the .

Can I build iOS app on Windows with Xamarin?

Currently it is not possible to develop for iOS using Xamarin Studio on Windows. If you want to use Windows, you can use Visual Studio. If you want to use Xamarin Studio, you can do so on a Mac. Note that you will always need a Mac around, even if you're using Visual Studio.

What do you need in order to build and deploy Xamarin iOS apps from Windows?

To build, debug, and sign iOS applications for distribution, Visual Studio 2019 must have network access to a Mac build host configured with both Apple's developer tools (Xcode) and Xamarin. iOS. Download and install Xcode from the Mac App Store. Install Visual Studio for Mac, which also installs Xamarin.


1 Answers

A great explanation from here.

Xamarin.iOS compiles c# source code against a special subset of the mono framework. This cut down version of the mono framework includes additional libraries which allow access to iOS platform specific features. The Xamarin.iOS compiler, smsc, takes source code and compiles it into an intermediate language, ECMA CIL (common intermediate language), however it does not produce ECMA ABI compatible binaries unlike the normal mono compiler, gmcs or dmsc. This means any 3rd party .Net libraries you want to include in your application will need to be recompiled against the Xamarin.iOS subset of the mono framework using smsc.

Once a Xamarin.iOS application has been compiled into CIL it needs to be compiled again into native machine code that can run on an iOS device. This process is carried out by the SDK tool ‘mtouch’, the result of which is an application bundle that can be deployed to either the iOS simulator or an actual iOS device, such as an iPhone or iPad.

Due to restrictions placed by Apple, the iOS kernel will not allow programs to generate code at runtime. This restriction has severe implications for software systems that run inside a virtual machine using just-in-time compilation. Just-in-time compilation takes the intermediate code, for example mono CIL and compiles it at runtime into machine code. This machine code is compatible for the device it is running on at the time of execution.

To work around this restriction the mtouch tool compiles the CIL ahead of time. A process that the mono team describe as AOT, ahead of time compilation.

enter image description here

Some quotes from Xamarin docs:

Xamarin iOS for Visual Studio accomplishes an amazing feat: it lets you create, build and debug iOS applications on a Windows computer using the Visual Studio IDE. It cannot do this alone, however - iOS applications cannot be created without Apple’s compiler, and they cannot be deployed without Apple’s certificates and code-signing tools. This means that your Xamarin iOS for Visual Studio installation requires a connection to a networked Mac OS-X computer to perform these tasks for you. Once configured, Xamarin’s tools will make the process as seamless as possible.

Starting with Xamarin.iOS 4.0, there are two code generation backends to Xamarin.iOS. The regular Mono code generation engine and one based on the LLVM Optimizing Compiler. Each engine has its pros and cons.

Typically, during the development process, you will likely use the Mono code generation engine as it will let you iterate quickly. For release builds and AppStore deployment, you will want to switch to the LLVM code generation engine.

Conclusion

So there is no way to make an iOS build host in Windows, as you said.

I guess Xamarin send to the build host the .Net assembly file (Orange part of the picture), to be compile into native ARM code using Apple llvm, and others tools like xcode-build to signed, link and build your application.

like image 54
Guilherme Torres Castro Avatar answered Oct 19 '22 15:10

Guilherme Torres Castro