NikolayKanchevski / SierraEngine

A modern rendering engine, made in C++20 and on top of the Vulkan and Metal APIs.
https://sierra.nikichatv.com
Apache License 2.0
17 stars 2 forks source link

Cross compiling #4

Closed TheVitya closed 2 months ago

TheVitya commented 2 months ago

Hello!

I really like what I see here in this repo, but I have a few questions about the structure and the compiling in general.

I am about to create a library that can be compiled for various platforms. The library would include a third-party MQTT client and an abstraction layer for easier usage. My expectations are the following, the library should build for iOS and Android at least.

Could you give me quick overview how you achieved this in you project? Sorry, if I am asking at the wrong place.

Thank you in advance.

NikolayKanchevski commented 2 months ago

Hi,

First and foremost, do not expect this to be easy, at all. Android and iOS are the two operating systems that have the least in common. For them, you will have to use Java/Kotlin and Objective-C/C++, respectively. Your library would need a custom entry point for every operating system it would support (in other words, a special int main() implementation).

Sierra has them in the Sierra/Core/Platform directory, however, for the time being, only Windows, macOS and iOS have been uploaded to the repo. Android and Linux are on the way.

Let's take a look at iOS's main.mm. The sceneDidBecomeActive function is more or less identical to int main() on Windows. It is where your application starts. In it, Sierra instantiates the user's application and runs it. The exact same thing would be happening on Android, except you would put that same logic into the special android_main function.

Now, how does Sierra (in other words, the library), know what the user's application is? In the EntryPoint header, which is included in the library's include file, there is an unimplemented function definition Sierra::CreateApplication(). Needless to say, it is what the user must implement in order for their application to start.

And here is how the Editor application's entry point is written to implement it.

TheVitya commented 2 months ago

Thank you for your reply!

I've read a few articles how it might be done, but I am confused a bit wether should I use Frameworks or compile from source directly.

Here is a quick example that I have just made to demonstrate what I am about to do. I would really appreciate if you could take a look at it: repo

Am I on a completely wrong path?

NikolayKanchevski commented 2 months ago

Hello again,

It seems you have not quite set the project properly. This will work on iOS exclusively, and, as far as I understand, you want to also feature support for Android.

The very first mistake you have made is not taking account that you are not allowed to have any operating system specific tools. You have created an Xcode project, and Xcode can only build under, and more importantly, for Apple platforms.

I would suggest you take a look at CMake, a build system that works on many platforms. It is not restricted to working under a single operating system, and is therefore a great tool for the job (unlike Xcode).

Then, I would recommend you try to build two separate C/C++ projects, with one being for Android only, and the other for iOS. Try to integrate CMake in both if that is the build system you will be using. Learning to create C/C++ projects on both platforms separately will allow you to design a middle ground solution, which would work on both operating systems.

TheVitya commented 2 months ago

Thank you for your reply!

I forgot to mention that my first attempt is to compile for iOS and use it as a Pod inside the example application. The POSIX platforms seems straight forward for now.

Also, I would use CMake for compiling it for iOS and the other platforms too.

Basically, my main struggles are related to iOS and what might be the best way to use this kind of library on iOS.

I would really appreciate if you could share your experience in this kind of situation.

NikolayKanchevski commented 2 months ago

In this case, this folder has implementations for everything related to low-level iOS you may need.

If you need anything else, or want to ask a question, I would be more than happy to help.