Search Unity

il2cpp breaks native code plugins by moving all files into a single folder

Discussion in 'Editor & General Support' started by Zenix, Sep 9, 2020.

  1. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    We have native code files living inside the Assets folder, which get compiled automatically when doing a build in Unity. These code files are spread throughout a number of subfolders, but when using il2cpp to compile the project, Unity copies all of these files into a single output directory - namely the il2cppOutput folder. This means that any includes that reference a file in a different folder are now broken.

    eg. If you had:

    Assets/MyPlugin/Code/MyFile.c
    Assets/MyPlugin/Code/Includes/MyFile.h

    Where MyFile.c has the line "#include <Includes/MyFile.h>"

    Unity will copy the two files to both live in the one folder, so you end up with:
    il2cppOutput/MyFile.c
    il2cppOutput/MyFile.h

    So now the include line is broken.

    Has anyone found a nice workaround for this? In my particular situation I'm using a 3rd party plugin comprising of a couple hundred code files, so restructuring it to all live in the one folder would be a real hassle.
    Surely there's a way to tell Unity to not break the folder structure?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    I don't think there is a work around for this, or even a way to indicate that Unity should not copy those files and IL2CPP try to compile them.

    The "loose" C++ source file feature is kind of a simple system intended to help with native plugin code on platforms where compilation of C++ source files can be complex, like WebGL.

    Instead, I would recommend compilation of the native plugins outside of Unity, where you can have access to a proper C++ build system. Then add the compiled native plugin libraries to the Unity project.
     
    Joe-Censored likes this.
  3. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    We were having issues with using pre-built libraries in Unity - which is why we're switching to compiling from source. It's also recommended in the Unity documentation for performance reasons. It also just makes sense... we're compiling a cpp project, so why not compile all cpp code together?

    I feel like you may have misunderstood my post - I'm wasn't asking for those files to _not_ be copied, I want them to be copied, but to maintain their folder structure so includes don't break.

    This issue only happens on PC - it doesn't happen when using il2cpp for iOS - in that situation the folder structure is maintained.
     
    Last edited: Sep 10, 2020
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Unfortunately, the way the build code work for iOS is pretty different from, other platforms in this respect. I don't think the build for for the standalone Windows player or other platforms was ever intended to preserve the directory structure.

    If you would like to submit a bug report, we can have a look at this, but I think it is working as intended. The C++ build support was always planned to be pretty rudimentary, so I don't expect that we will support maintaining the directory structure soon.
     
  5. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    I will submit a bug report, as it would be a simple fix and I'm sure would help out a lot of people.

    If this system is really not that well supported, then it might be a good idea to update the documentation to reflect that.

    By creating a documentation page for this feature, that points out the benefits of compile time errors and a significant performance increase, it really feels like this is the way you're pushing for people to do things.
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Thanks for the bug report, we will investigate this.