Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Preview 0.15.3 -- DotsRuntimeCSharpProgramCustomizer for custom .asmdef

Discussion in 'Project Tiny' started by yossi_horowitz_artie, Jun 11, 2019.

  1. yossi_horowitz_artie

    yossi_horowitz_artie

    Joined:
    Jan 30, 2019
    Posts:
    87
    Hi there. I'm trying to integrate a third-party C library into a Tiny project. For clarity, let's call the Tiny project `App` and the third-party library `Lib`. (Not their actual names.)

    Within my Unity project's assets folder I've created a folder for Lib within which I've placed a `Lib.asmdef`. I've created a `cpp~` folder next to the asmdef, and put all of the Lib's C source in there. I then set `App.asmdef` to reference `Lib.asmdef`. When I attempt to build, App, the Tiny project, Bee is indeed trying to compile the Lib's C code, since I'm seeing compiler errors inside of Lib, so so far so good!

    (Incidentally, I also tried a simpler version of this test first, before I brought in the entire Lib source, where the `cpp~` folder just had a single C function that printed something to the console. I got that version of things to the point where it fully compiled and ran and executed as expected, both as a Windows DotNet app and as a WebAssembly app.)

    The next problem to deal with, of course, is those very compiler errors. They're to be expected, since the original third party library comes with a reasonably complex makefile with preprocessor setup, various different behaviors for different platforms, and so on.

    I figure that from there the right thing to do is to recreate the logic of Lib's original makefile in a `DotsRuntimeCSharpProgramCustomizer`, following the example of libraries included with Tiny like `
    CustomizerForTinyGLFW`. So I put a `bee~` folder next to the Lib's asmdef file and `cpp~` folder and put a new child class of `DotsRuntimeCSharpProgramCustomizer` inside of the the `bee~` folder. Using `System.Console.Out.WriteLine()` and logging `program.SourcePath.FileName` I've confirmed that its the customizer's `Customize()` method is being called for many different `DotsRuntimeCSharpProgram`s, including various Tiny libraries, some of which aren't even reference by App -- but Lib is not one of them.

    What generates the list of assemblies which are converted to `DotsRuntimeCSharpProgram`s and customized by `DotsRuntimeCSharpProgramCustomizer`s, and is there a way to add `Lib` to that list?

    Thanks in advance!
     
  2. yossi_horowitz_artie

    yossi_horowitz_artie

    Joined:
    Jan 30, 2019
    Posts:
    87
    I've learned that `program.SourcePath.FileName` in `DotsRuntimeCSharpProgramCustomizer.Customize()` is the name of the folder that the asmdef is in rather than the name of the asmdef itself. That clears some things up!
     
  3. Lucas-Meijer

    Lucas-Meijer

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    175
    Hey Yossi,

    Could you elaborate a bit more on your usecase? I have been very strongly considering closing this feature to non-unity users, as it makes it much harder for us to make sure that changes in tiny/unity do not break user projects. What library are you compiling? What problem does it solve?

    Thanks, Lucas
     
  4. yossi_horowitz_artie

    yossi_horowitz_artie

    Joined:
    Jan 30, 2019
    Posts:
    87
    I'm compiling the raylib library ( https://github.com/raysan5/raylib ) in an attempt to add 3D support, and my team will likely integrate OpenCV in the coming months in an attempt to add AR/SLAM support. (I know that 3D and AR are coming down the pike for DOTS Runtime eventually, but we can't afford to wait, and C# Tiny looks to make for an amazing foundation for the kind of work we're trying to do.)

    I hope you don't decide to close them out! Being able to freely mix C/C++ libraries into Unity code is lovely, and I'm sure that anyone trying anything as crazy as this, especially while Tiny is in Preview, is doing so with the understanding that the API is subject to massive revisions. I'm fully expecting everything I'm doing to break with each upgrade for a long time to come; I just hope that you won't take away my ability to fix it! :)

    Thanks!
     
  5. Dunk86

    Dunk86

    Joined:
    May 10, 2015
    Posts:
    53
    Wow, raylib looks great. Would be interesting to see if Tiny could be used as a more general web C# platform. :D