CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
343 stars 81 forks source link

How to build and run the Linux version of Cesium for Unity in Unity? #489

Open SeokHsu opened 1 month ago

SeokHsu commented 1 month ago

I followed the steps in the documentation to clone cesium-unity-samples and cesium-unity, successfully built the native code using CMake, and published the Linux version using Unity 2022.3. However, when I run it on the Linux system, it gives me an error saying that the ‘DllNotFoundException: CesiumForUnityNative-runtime’. This file shouldn't be needed on a Linux system, so I wonder if there was an issue with the process I used to build Cesium as a plugin, or if I used the wrong commands.

I did this because I need to use Cesium on Linux, but we have only been developing for the Windows version before. I noticed that Cesium for Unreal supports Linux, so I tried to compile it myself because the Cesium for Unity plugin doesn't natively support Linux.

kring commented 4 weeks ago

Unity's .NET throws DllNotFoundException when it can't like a shared library. It shouldn't be intepreted as referring specifically to a .dll; it will be a .so on Linux. It is most definitely required, though. That .so file (two of them, actually) is what you built when you built the native code using CMake.

Linux isn't currently supported, as you know, so it's hard to say where the problem might be. Perhaps if you described the steps you followed in detail we could spot the problem. Did you run the install target from CMake? One thing that jumps out at me is CesiumForUnityNative-runtime with a lowercase r in runtime. Typically that R is capitalized.

If you're trying to build for the Editor in Linux, things are a bit simpler. But it sounds like you're trying to make a built game run on Linux (perhaps you're even packing it on Windows). There are a lot of moving parts to make that work. You'll need to change the two ConfigureReinterop files to add an #elif for linux. You'll need to modify CompileCesiumForUnityNative.cs to teach it out how to build the native code for Linux. Probably other things, but that's a start. It's not trivial to support a new platform, or else we would have already done it.

SeokHsu commented 4 weeks ago

Unity's .NET throws DllNotFoundException when it can't like a shared library. It shouldn't be intepreted as referring specifically to a .dll; it will be a .so on Linux. It is most definitely required, though. That .so file (two of them, actually) is what you built when you built the native code using CMake.

Linux isn't currently supported, as you know, so it's hard to say where the problem might be. Perhaps if you described the steps you followed in detail we could spot the problem. Did you run the install target from CMake? One thing that jumps out at me is CesiumForUnityNative-runtime with a lowercase r in runtime. Typically that R is capitalized.

If you're trying to build for the Editor in Linux, things are a bit simpler. But it sounds like you're trying to make a built game run on Linux (perhaps you're even packing it on Windows). There are a lot of moving parts to make that work. You'll need to change the two ConfigureReinterop files to add an #elif for linux. You'll need to modify CompileCesiumForUnityNative.cs to teach it out how to build the native code for Linux. Probably other things, but that's a start. It's not trivial to support a new platform, or else we would have already done it.

I did package it on Windows because we don't have a fully set up Linux environment.

image This screenshot shows what we built, and it does indeed have a .so file, but the file size doesn't seem right. I don't think it should be as small as 1KB, and there is also a .dll file. I want to know if this step was done correctly? We followed the steps in the documentation.

Additionally, we noticed the CompileCesiumForUnityNative.cs and two ConfigureReinterop files, but there is no code related to the Linux system. We wanted to try adding this part of the code, but we don't know where to start. Do we need to write a new CMake file? We're not very familiar with CMake and don't know how to set the parameters.

My understanding is that we now have at least two important steps. The first step is to write a CMake file to generate a .so library file that Linux can support. The second step is to modify the code in Reinterop so that it can execute on Linux and call the library file built in the previous step.

One last question, do you have plans to support the Linux platform? If so, when can we expect it to be released? We have many projects that require Linux system support.

kring commented 4 weeks ago

the file size doesn't seem right. I don't think it should be as small as 1KB

Nope, that's not right. If you open that file in a text editor, it'll probably have some text about it being a placeholder. That means the build failed. There should have been a message in the Unity log indicating this, and stating where you can find the log for the native code build.

we noticed the CompileCesiumForUnityNative.cs and two ConfigureReinterop files, but there is no code related to the Linux system. We wanted to try adding this part of the code, but we don't know where to start. Do we need to write a new CMake file? We're not very familiar with CMake and don't know how to set the parameters.

Right, it's not a supported platform. You'll need to add code for Linux, by copying another platform and modifying it appropriately. You shouldn't need to write any new cmake, but you will have to make sure that cmake is invoked correctly for the platform. Perhaps write a cmake toolchain file (there are existing ones for Android and iOS in the native~/extern directory). Sorry to say, but this is going to be tricky if you're not familiar with cmake.

One last question, do you have plans to support the Linux platform? If so, when can we expect it to be released? We have many projects that require Linux system support.

It's not currently a priority for us, but it would be reasonably easy for us to do if it became one. If you're currently working with anyone in sales or business development at Cesium, tell them you're interested and that they should push on us.