Skip to content

Feature/supportmultipleplatforms - #890

Closed
gentledepp wants to merge 2 commits into
MessagePack-CSharp:v1.xfrom
gentledepp:feature/supportmultipleplatforms
Closed

gentledepp wants to merge 2 commits into
MessagePack-CSharp:v1.xfrom
gentledepp:feature/supportmultipleplatforms

Conversation

@gentledepp

Copy link
Copy Markdown

Added real support for iOS and UWP by

  • introducing them as target platform.
  • introducing a compiler directive GENERATE_DYNAMIC_CODE which is disabled for UAP and iOS
  • removed all dynamic code generation for UAP and iOS

Basically, UWP and iOS should work with the default Messagepack implementation.
For example, on UWP, the .net native toolchain combined with optimize code could remove the dynamic code.
Sometimes it does, sometimes it does not. This leads to compiling an UWP release build for nearliy 1 hour just to get a runtime error that "dynamic code is not allowed".
This is very, very tedius!

@gentledepp

Copy link
Copy Markdown
Author

@BrayanKhosravian @bruzkovsky

@AArnott

AArnott commented May 4, 2020

Copy link
Copy Markdown
Collaborator

This has been tried a few times before: #401 #638 #641 #703, and perhaps more exist.

It's historically very tricky to get this write because the same source code has to compile with no project file at all inside Unity. So for example you define a new GENERATE_DYNAMIC_CODE preprocessor symbol but that won't be defined in Unity. In Unity, some targets support ref.emit while others don't. With your change, I think you're removing support for code generation even for those that don't.

My hope with #703 was to get tests working on UWP to prove that it works, but without causing problems for unity.

@neuecc do you have any other thoughts?

@gentledepp

gentledepp commented May 4, 2020 •

Copy link
Copy Markdown
Author

Well.. we are mainly focused on UWP our issues with the .net native toolchain.
If you remember, @bruzkovsky made a PR a while ago because of our UWP issues and in the discussion with you it turned out, that the PR was not necessary, as the UWP .net native toolchain somehow automatically linked away all dynamic stuff. I honestly don't understand why it worked, it just did.
Now, we added a bunch of features and with the very same MessagePack package we get a runtime error on UWP claiming that "dynamic code is not allowed". 🙄
The only way to get it working again was - again - to comment out all code that involves Ref.Emit and the like 🤷‍♂️

But I do understand your point - we have absolutely no experience with and usage for Unity

@neuecc

neuecc commented May 8, 2020

Copy link
Copy Markdown
Member

While I think it's most elegant to not have to add TargetFramework (what's the Microsoft NET_STANDARD for?)
And I thought it could be accomplished with a Lazy initialization, but I haven't taken the confirmation myself.

I'm not really interested in UWP or Xamarin, so I don't know what's better after all.
So, as long as you don't break the Unity build, I guess it's okay.

@AArnott

AArnott commented May 8, 2020

Copy link
Copy Markdown
Collaborator

@neuecc How can we (PR author first 😄) verify that none of the unity scenarios break? Our PR validation doesn't test all the unity scenarios. Is there a doc somewhere perhaps that walks us through manual validation?

@neuecc

neuecc commented May 15, 2020

Copy link
Copy Markdown
Member

@AArnott

It's much better than making no progress, so let's move forward with this PR idea.

There are a couple of points I'd like to discuss.

In the direction of define, I want to make the state that nothing is given is Generate(Normal) and the state that something is given is AOT.

#if !ENABLE_IL2CPP && !UNITY_WSA && !NET_STANDARD_2_0 && GENERATE_DYNAMIC_CODE

For example, because only GENERATE_DYNAMIC_CODE has a different orientation.

Another thing is that many code paths seem to be equal to ENABLE_IL2CPP.
How about adding ENABLE_IL2CPP to uap, xamarin.ios(and remove new GENERATE_DYNAMIC_CODE)?
This will reduce the number of branch paths and thus reduce the number of mixed bugs.

Unity and IL2CPP, now test code run on my RuntimeUnitTestToolkit so can easy to run on CI.

@gentledepp

Copy link
Copy Markdown
Author

Well, we did introduce the GENERATE_DYNAMIC_CODE directive to follow a fine grained approach.
Basiaclly, I tried to remove parts of the code (trial and error) and see if UAP finally works and removed only the problematic parts with GENERATE_DYNAMIC_CODE
As these are just very few, turning this flag around to GENERATE_DYNAMIC_CODE would require touching almost every code file in this repo - so this is high risk and a no-go.

What is ENABLE_IL2CPP?
What does it stand for?
And how is it similar to GENERATE_DYNAMIC_CODE?

I am just wondering why I never stumbled over this ENABLE_IL2CPP flag while introducing our
GENERATE_DYNAMIC_CODE fix...

@github-actions

Copy link
Copy Markdown
Contributor

This pull request is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@neuecc

neuecc commented Aug 24, 2020

Copy link
Copy Markdown
Member

#996, what do you think of the results?
If that solves the problem, then we don't have to do anything more.

@gentledepp

Copy link
Copy Markdown
Author

Yes I guess this could do the trick! Hopefully ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants