jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warnings with new shared project feature

duckdoom4 opened this issue · comments

I posted this in the old issue, but I got the feeling you missed my message, so I thought I'd re-post it as an issue.

Hi there, I finally got time to test everything out properly. I am running into a small issue still though, but I think that's easy to solve. How did you intend the projects to be structured?

I now have:
ClassLibrary called pkNX.Structures.FlatBuffers.Shared
With the following properties:

<PropertyGroup>
  <FlatSharpClassDefinitionsOnly>true</FlatSharpClassDefinitionsOnly>
</PropertyGroup>

<ItemGroup>
  <FlatSharpSchema Include="Schemas\**\*.fbs">
    <IncludePath>Schemas\</IncludePath>
  </FlatSharpSchema>
</ItemGroup>

ClassLibrary called pkNX.Structures.FlatBuffers.Main
With the following properties:

<ItemGroup>
  <ProjectReference Include="..\pkNX.Structures.FlatBuffers.Shared\pkNX.Structures.FlatBuffers.Shared.csproj" />
</ItemGroup>

<PropertyGroup>
  <FlatSharpDeserializers>GreedyMutable</FlatSharpDeserializers>
  <FlatSharpInputFilesOnly>true</FlatSharpInputFilesOnly>
</PropertyGroup>

<ItemGroup>
  <FlatSharpSchema Include="Schemas\**\*.fbs">
    <IncludePath>Schemas\</IncludePath>
    <IncludePath>..\pkNX.Structures.FlatBuffers.Shared\Schemas\</IncludePath>
  </FlatSharpSchema>
</ItemGroup>

This generates the following warning:
.\pkNX.Structures.FlatBuffers.SWSH\..\FlatSharp.generated.cs(171497,21,171497,25): warning CS0436: The type 'AABB' in '.\pkNX.Structures.FlatBuffers.SWSH\..\FlatSharp.generated.cs' conflicts with the imported type 'AABB' in 'pkNX.Structures.FlatBuffers.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '.\pkNX.Structures.FlatBuffers.SWSH\..\FlatSharp.generated.cs'.

I can see that in both files it still generates the partial class for both projects in their FlatSharp.generated.cs. I'm guessing I just need to edit the project setup?

(Everything else is working wonderfully btw. Very happy with the new features :D)

Originally posted by @duckdoom4 in #388 (comment)

Hey there. I apologize for my delay. I did see your earlier message, but life happened this week and I didn't have time to respond.

So, you're close to the mark here. The problem is that you're telling FlatSharp to process everything twice. I suggest putting the shared schemas into their own folder and only including that in the common project:

<PropertyGroup>
  <FlatSharpClassDefinitionsOnly>true</FlatSharpClassDefinitionsOnly>
</PropertyGroup>

<ItemGroup>
  <FlatSharpSchema Include="Schemas\Shared\**\*.fbs">
    <IncludePath>Schemas\</IncludePath>
  </FlatSharpSchema>
</ItemGroup>

Then the specific schemas that reference those shared ones need their own folder as well:

<ItemGroup>
  <ProjectReference Include="..\pkNX.Structures.FlatBuffers.Shared\pkNX.Structures.FlatBuffers.Shared.csproj" />
</ItemGroup>

<PropertyGroup>
  <FlatSharpDeserializers>GreedyMutable</FlatSharpDeserializers>
  <FlatSharpInputFilesOnly>true</FlatSharpInputFilesOnly>
</PropertyGroup>

<ItemGroup>
  <FlatSharpSchema Include="Schemas\Specific\**\*.fbs">
    <IncludePath>Schemas\</IncludePath>
    <IncludePath>..\pkNX.Structures.FlatBuffers.Shared\Schemas\Shared\</IncludePath>
  </FlatSharpSchema>
</ItemGroup>

This leads to the common project having the shared class definitions, but no serializers and the specific project having serializers for its types and the common types, but no class definitions for the common types.

Hope that makes sense. LMK if you need more help. I'm happy to share a fuller example.

So the files are already in a different physical folder, but I tried to use the method you layed out above and it's still not working. I think there may be a deeper underlaying issue. I will try with a simple setup to see if I can get this to work and then try to figure out what breaks it. I think it's caused by multi-layered includes

🎉 My mistake it's working perfectly fine. I had a duplicate flatbuffer in the main project. (so both main and shared had the same flatbuffer definition, but placed at a different physical disk location)

include "Math/Vec3f.fbs";

namespace pkNX.Structures.FlatBuffers;

table AABB {
    Min: Vec3f;
    Max: Vec3f;
}

Had a copy both in shared/Schemas/ and main/Schemas/