19

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.

Léon Pelletier
  • 2,701
  • 2
  • 40
  • 67
  • The Xamarin docs already provide a pretty good example of how to get setup with iOS build hosts through Visual Studio: http://docs.xamarin.com/guides/ios/getting_started/introduction_to_xamarin_ios_for_visual_studio/ – Corey Sunwold Mar 08 '14 at 19:10
  • 1
    If you read the first sentence, I'm talking about an objective-c toolchain I have in Windows. Then I'm asking question about the existence of some documentation for the architecture of this build host. Then I'm asking about creating a build host in Windows. :) – Léon Pelletier Mar 08 '14 at 20:14
  • 1
    Having an Obj-C compiler is useless - what you need is a C# compiler that will compile for the iOS architecture, as well as the supporting SDKs for iOS, which Apple does not make available on Windows. – Jason Mar 08 '14 at 20:15
  • So when Xamarin.iOS is connecting to a iOS build host, it is a C# compiler that compiles for the iOS architecture? What does Xamarin sends on the wire to the build host? – Léon Pelletier Mar 08 '14 at 20:18
  • Yes. That is the whole purpose of Xamarin - it allows you to use C# and the .NET Framework to target Native iOS apps (or Android or Mac). – Jason Mar 08 '14 at 20:20
  • 1
    This is a very generic comment. Was my question so generic? Maybe I should have asked: "What Xamarin is doing being the curtain when using an iOS build host?" – Léon Pelletier Mar 08 '14 at 20:23
  • I've made the question clearer. :) – Léon Pelletier Mar 08 '14 at 20:26

1 Answers1

23

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.

Community
  • 1
  • 1
Guilherme Torres Castro
  • 15,135
  • 7
  • 59
  • 96
  • Thanks a lot for this schema. It's a good introduction. It still only answers half to my concerns as in the quote, it tells: "You cannot use Windows because you need a Mac." It is not an explanation, since it is not technical. I already have a toolchain and everything to sign my apps from Windows, using a commercial product. So I'm a bit skeptical about this quote. – Léon Pelletier Mar 11 '14 at 17:25
  • It describes this flow as "seamless", and that's the problem here. I want to build this "seamless" bridge that is missing between xamarin and my toolchain. – Léon Pelletier Mar 11 '14 at 17:26
  • 2
    ```OS applications cannot be created without Apple’s compiler, and they cannot be deployed without Apple’s certificates and code-signing tools.``` Actually, you can compile IOS application without Apple compile, mono touch support this only for ARMV6, so I guess a lot of enforced to keep the compile compatible with the upcoming architectures. I don´t know in details but probably a lot of the packing process is done by xcode-build, (sign-in, compile xib files and etc). So theoretically you can deploy on Windows if you reverse engine the xcode-build tool. – Guilherme Torres Castro Mar 11 '14 at 18:35
  • If it uses xcode compiler is it possible to turn on ARC ? – Shiva May 02 '17 at 10:21