jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

FlatSharp.Compiler .net standard 2 #249

Closed JurjenBiewenga closed 2 years ago

JurjenBiewenga commented 2 years ago

Hi,

We're using a shared library between one of our server applications and our Unity project that contains our schemas and some helpers. This is working perfectly fine however we're stuck on .net standard 2 as our Unity version does not support any higher currently. Is there any chance of getting .net standard 2 support back in the compiler nuget or should we manually call the flatsharp compiler as a build process step?

Thanks

jamescourtney commented 2 years ago

The FlatSharp compiler is a standalone executable. I ship both net5.0 and netcoreapp3.1 versions of the compiler. The FlatSharp.Runtime package does support netstandard2.0, which should work for you. All you'll need to make sure of is that your build environment has either .NET Core 3.1 or .NET 5 installed, and you should be able to use the FlatSharp compiler as a command line tool.

Those who use Unity with FlatSharp usually do so by invoking the FlatSharp compiler as a prebuild step, since Unity does not allow editing .csproj files. You can find documentation about the compiler here.

(As an aside, .NET Standard can be thought of as headers, where as .NET Framework and .NET Core are the implementations. For this reason, you can't actually ship a .NET Standard executable, because it's an API without implementation. You can, however, produce .NET Standard DLLs that will work correctly in any runtime that supports that version of .NET Standard.)

JurjenBiewenga commented 2 years ago

Our shared library is a separate C# project (gets copied to unity with required dependencies after build), and thus we use the nuget packages there.

Somewhere in the 5.x to 6.x cycle, support on the NuGet package for net standard 2 was dropped. Taking a quick look at the compiler project, seems like adding net standard 2 as a target doesn't cause any problems. Of course, you'll know better if it's possible.

Ideally we'll want to keep using the NuGet package as it doesn't make our build pipeline any more complex but if that's really not possible then I'll look into invoking the compiler manually.

Ps. I noticed that the CSProjects are targeting C# 9 while using "interpolated string handlers" which are only available in C# 10, according to Rider that is.

jamescourtney commented 2 years ago

What got dropped in version 6 was netcoreapp2.1, which went out of support in August. The compiler has never targeted .NET Standard.

https://devblogs.microsoft.com/dotnet/net-core-2-1-will-reach-end-of-support-on-august-21-2021/

JurjenBiewenga commented 2 years ago

Oh sorry! I somehow read those as the same (although I know the difference). My point is still the same, FlatSharp.Compiler can still produce a netstandard 2 compatible binary.

jamescourtney commented 2 years ago

Is this what you're seeing?

image

If so, that's obnoxious since the compiler is just a tool package. I'm actually more surprised it worked before in version 5. I'll see what I can do to get 6.0.2 published in the next 24 hours or so.

jamescourtney commented 2 years ago

It's bedtime for me, but I'll look at this tomorrow.

JurjenBiewenga commented 2 years ago

Yeah, perhaps I should've been a bit more clear. Thanks, I really appreciate it! There's no hurry, already postponed updating for a few weeks.

jamescourtney commented 2 years ago

250 tracks the progress of me trial-and-erroring my way to fixing this

jamescourtney commented 2 years ago

This is fixed in 6.0.2, which was just published to NuGet. The full release notes for v6 are here. Keep in mind that there are some breaking changes in V6, so I really encourage you to read the full release notes. Thanks for using FlatSharp! Please let me know how Version 6 works for you when you do end up upgrading.

JurjenBiewenga commented 2 years ago

Seems to work perfect now! We were already mostly compatible with Flatc (we've got third parties consuming our schemas). Thanks a lot!