protobuf-net / protobuf-net

Protocol Buffers library for idiomatic .NET
Other
4.69k stars 1.06k forks source link

why need c# 6.0? mac os unity 2017 #416

Open 2731381914 opened 6 years ago

2731381914 commented 6 years ago

Assets/protobuf-net/BclHelpers.cs(212,56): error CS1644: Feature declaration expression' cannot be used because it is not part of the C# 6.0 language specification Assets/protobuf-net/Meta/MetaType.cs(1246,59): error CS1644: Featuredeclaration expression' cannot be used because it is not part of the C# 6.0 language specification

mgravell commented 6 years ago

Can you not consume it as a prebuilt nuget package?

2731381914 commented 6 years ago

I used the source code to import it into the unity project, using the package, and I was worried that there would be a problem with ios。

mgravell commented 6 years ago

Is there a particular TFM that would make it simple to consume? The latest alpha includes an UWP TFM, so we probably have the tools in place to make that work now.

2731381914 commented 6 years ago

I successfully imported the source code into unity using the protobuf-net-r668 version. I would like to know if this version supports protobuf3.0 and can be used in a production environment.

mgravell commented 6 years ago

There are no binary format changes between proto2 and proto3, so without knowing exactly what proto3 features your talking about it is very hard to answer that.

You can of course use r668, but it is unsupported at this point.

On Fri, 6 Jul 2018, 04:35 2731381914, notifications@github.com wrote:

I successfully imported the source code into unity using the protobuf-net-r668 version. I would like to know if this version supports protobuf3.0 and can be used in a production environment.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mgravell/protobuf-net/issues/416#issuecomment-402915907, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsJoSd6-ruEK4QmSPS7Vx5g7xBsNjks5uDtsDgaJpZM4VDoHt .

mgravell commented 6 years ago

There is a branch here that you may find interesting. I did it purely for curiosity. It is not quite up to date, etc. https://github.com/mgravell/protobuf-net/tree/langver4

On Fri, 6 Jul 2018, 07:33 Marc Gravell, marc.gravell@gmail.com wrote:

There are no binary format changes between proto2 and proto3, so without knowing exactly what proto3 features your talking about it is very hard to answer that.

You can of course use r668, but it is unsupported at this point.

On Fri, 6 Jul 2018, 04:35 2731381914, notifications@github.com wrote:

I successfully imported the source code into unity using the protobuf-net-r668 version. I would like to know if this version supports protobuf3.0 and can be used in a production environment.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mgravell/protobuf-net/issues/416#issuecomment-402915907, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsJoSd6-ruEK4QmSPS7Vx5g7xBsNjks5uDtsDgaJpZM4VDoHt .

mgravell commented 6 years ago

Throwing this open to community input. I'm willing to go to reasonable lengths to be a good library citizen. Preferably lengths that don't bend my build process completely (we managed to get UWP into the regular build, for example).

But: I don't have the knowledge of what unity needs to consume things cleanly as a library / package. Are there any particular guidelines? Is there a TFM we can add in nuget? I simply don't know. I really don't want to have to go to langver 4. I've spiked it purely out of curiosity, and I don't like it much.

distantcam commented 6 years ago

Two things are needed. Both require Unity 2018.1 or later.

First, update the project to use .NET 4.5. https://docs.unity3d.com/Manual/ScriptingRuntimeUpgrade.html

Then use the Package Manager to import the Incremental Compiler package. https://forum.unity.com/threads/unity-incremental-c-compiler.523993/

distantcam commented 6 years ago

@mgravell I don't do iOS unity development but AFAIK importing precompiled libraries works as usual. The Unity documentation also mentions that dynamic code doesn't work on iOS, but I don't know if that's used in this project.

mgravell commented 6 years ago

@distantcam nope, no dynamic

mgravell commented 6 years ago

so fun story: I downloaded 12GB of unity ...

no clue

So... I'm ducking out here. That UI means not a single thing to me. This is where someone who actually understands how to package things for unity is going to have to step up, 'cos ... with all the will in the world, I'm just not going to be efficient or effective with that.

gamemachine commented 6 years ago

Unity is moving to AOT only even on PC. So the main thing is no JIT.

For the api you have .Net 4.x or .Net standard 2.0.

C# 6 is the highest language level supported in their release builds. But they have a Roslyn compiler package now in preview, that will be going into the next release with C# 7.2 support.

If I was aiming for the widest compatibility, I'd target 4.x and C# 6, although C# 7.2 in 6 months or so will I think be where most Unity users are. You will find a very few users using the now deprecated .Net 3.x api. I would not be inclined to support that if it was an issue in any way.

mgravell commented 6 years ago

From a separate email discussion, I obtained the following:

No idea if that is a good option, but it is an option.

@gamemachine - it is fine saying that we "have .Net 4.x or .Net standard 2.0.", but it is often the case that we need to do some kind of special-casing to prevent AOT from even trying to do emit; the lib already has feature detection, but there are scenarios where it doesn't work - for UWP we had to add a specific TFM, for example. So: I'm still very interested in whether a TFM exists for Unity in this configuration.

gamemachine commented 6 years ago

I think this is about as close as you will get to a TFM.

https://docs.unity3d.com/Manual/ScriptingRestrictions.html

With Unity if it requires JIT, the methods simply won't be there and it will an exception at runtime. So yes you need to make sure it's not even trying to call anything requiring JIT.

Mos of the time it's simply a matter of don't use anything in Reflection.Emit.

gyx9208 commented 6 years ago

Hi, here is a easy way.

Copy the generated "proto.cs" and "protobuf-net.dll" into "Assets/" Create a file "/Assets/Editor/TestProtoBuf.cs"

using UnityEngine;
using UnityEditor;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using MoleMole.Test.GamePlayProto;
using System.IO;

public class TestProtoBuf
{
    [Test]
    public void ProtoBufTestSimplePasses()
    {
        //Arrange
        HeartBeat inbeat = new HeartBeat();
        inbeat.TimeStamp = 11;

        //Act
        MemoryStream stream = new MemoryStream();
        ProtoBuf.Serializer.Serialize(stream, inbeat);

        stream.Seek(0, SeekOrigin.Begin);

        HeartBeat outbeat = ProtoBuf.Serializer.Deserialize<HeartBeat>(stream);

        //Assert
        Assert.AreEqual(11, outbeat.TimeStamp);
    }
}

In Unity, click Window/General/Test Runner. I'm not sure whether the menu'name is correct if you're not in Unity 2018. It's easy to find. It's a unit test window.

Then you can see the TestProtoBuf case. "Run All"