Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

il2cpp not compiling #258

Open
sekkit opened this issue Nov 6, 2017 · 23 comments
Open

il2cpp not compiling #258

sekkit opened this issue Nov 6, 2017 · 23 comments

Comments

@sekkit
Copy link

sekkit commented Nov 6, 2017

IL2CPP error for method 'IronPython.Runtime.List IronPython.Modules.Builtin::range(IronPython.Runtime.CodeContext,System.Object,System.Object,System.Object)' in assembly '/Users/sekkit/Documents/lacg/trunk/client/Temp/StagingArea/Data/Managed/Newtonsoft.Json.dll'
Additional information: Build a development build for more information. Default value for field step must be null.

@slide
Copy link
Contributor

slide commented Nov 6, 2017

What is il2cpp? Will needs lots more information to help with this.

@sekkit
Copy link
Author

sekkit commented Nov 7, 2017

Here is demo project attached:
pytest.zip

You put ironpython into Unity2017, it works seamlessly with mono runtime.
BUT when exporting to iOS xcode project with il2cpp runtime(translating .net il to c++ code), the compilation would fail due to incompatibility issues.
Currently works fine in Windows/Mac/Android, except iOS.

@sekkit
Copy link
Author

sekkit commented Nov 7, 2017

Failed running /Applications/Unity/Unity.app/Contents/il2cpp/build/il2cppcore/il2cppcore.dll --convert-to-cpp --emit-null-checks --enable-array-bounds-check --map-file-parser="/Applications/Unity/Unity.app/Contents/Tools/MapFileParser/MapFileParser" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/UnityEngine.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/IronPython.Modules.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/IronPython.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/Microsoft.Scripting.Core.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/Microsoft.Scripting.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/System.dll" --assembly="/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/mscorlib.dll" --generatedcppdir="/Users/sekkit/Documents/pytest/Temp/il2cppOutput/il2cppOutput"

stdout:
IL2CPP error for method 'IronPython.Runtime.List IronPython.Modules.Builtin::range(IronPython.Runtime.CodeContext,System.Object,System.Object,System.Object)' in assembly '/Users/sekkit/Documents/pytest/Temp/StagingArea/Data/Managed/IronPython.dll'
Additional information: Build a development build for more information. Default value for field step must be null.
il2cpp.exe didn't catch exception: System.InvalidOperationException: Default value for field step must be null.
at Unity.IL2CPP.Metadata.MetadataUtils.ConstantDataFor(IConstantProvider constantProvider, TypeReference declaredParameterOrFieldType, String name) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataUtils.cs:line 73
at Unity.IL2CPP.Metadata.MetadataCollector.d__52.MoveNext()
at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, IEnumerable1 itemsToAdd, Action1 onAdd) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 383 at Unity.IL2CPP.Metadata.MetadataCollector.<AddMethods>b__45_0(MethodDefinition method) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 263 at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, T item, Action1 onAdd) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 397 at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, IEnumerable1 itemsToAdd, Action1 onAdd) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 383
at Unity.IL2CPP.Metadata.MetadataCollector.b__41_0(TypeDefinition type) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 186
at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, T item, Action1 onAdd) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 397
at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, IEnumerable1 itemsToAdd, Action1 onAdd) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 383 at Unity.IL2CPP.Metadata.MetadataCollector.<AddAssembly>b__36_0(ModuleDefinition module) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 119 at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, T item, Action1 onAdd) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 397 at Unity.IL2CPP.Metadata.MetadataCollector.AddAssemblies(ICollection1 assemblies) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/Metadata/MetadataCollector.cs:line 96
at Unity.IL2CPP.AssemblyConverter.Apply() in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/AssemblyConverter.cs:line 136
at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable1 assemblyDirectories, IEnumerable1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/Unity.IL2CPP/AssemblyConverter.cs:line 56
at il2cpp.Program.DoRun(String[] args) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/il2cpp/Program.cs:line 204
at il2cpp.Program.Run(String[] args) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/il2cpp/Program.cs:line 103
at il2cpp.Program.Main(String[] args) in /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/il2cpp/Program.cs:line 80
stderr:

Unhandled Exception: System.InvalidOperationException: Default value for field step must be null.
at Unity.IL2CPP.Metadata.MetadataUtils.ConstantDataFor(IConstantProvider constantProvider, TypeReference declaredParameterOrFieldType, String name)
at Unity.IL2CPP.Metadata.MetadataCollector.d__52.MoveNext()
at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, IEnumerable1 itemsToAdd, Action1 onAdd) at Unity.IL2CPP.Metadata.MetadataCollector.<AddMethods>b__45_0(MethodDefinition method) at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, T item, Action1 onAdd) at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, IEnumerable1 itemsToAdd, Action1 onAdd)
at Unity.IL2CPP.Metadata.MetadataCollector.b__41_0(TypeDefinition type)
at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, T item, Action1 onAdd)
at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, IEnumerable1 itemsToAdd, Action1 onAdd) at Unity.IL2CPP.Metadata.MetadataCollector.<AddAssembly>b__36_0(ModuleDefinition module) at Unity.IL2CPP.Metadata.MetadataCollector.AddUnique[T](Dictionary2 items, T item, Action1 onAdd) at Unity.IL2CPP.Metadata.MetadataCollector.AddAssemblies(ICollection1 assemblies)
at Unity.IL2CPP.AssemblyConverter.Apply()
at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable1 assemblyDirectories, IEnumerable1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder)
at il2cpp.Program.DoRun(String[] args)
at il2cpp.Program.Run(String[] args)
at il2cpp.Program.Main(String[] args)
at Program.Main(String[] args)

UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:128)
UnityEditorInternal.Runner:RunNetCoreProgram(String, String, String, CompilerOutputParserBase, Action1) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:79) UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List1, Action1, String) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:322) UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(ICollection1, String, String) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:305)
UnityEditorInternal.IL2CPPBuilder:Run() (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:151)
UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry, Boolean) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:34)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

@slide
Copy link
Contributor

slide commented Nov 7, 2017

This is currently outside the area of what we support. It could be something we look into in the future, but for now, this is unsupported. PR's are welcome.

@slozier
Copy link
Contributor

slozier commented Nov 7, 2017

It looks like it failing on the range definition:

public static List range(CodeContext/*!*/ context, object start, object stop, [DefaultParameterValue(1)]object step)

It doesn't like having a DefaultParameterValue which is not null for an argument of type object? To be fair the C# syntax for optional arguments also doesn't like it...

Assuming this is the only failure point the fix is simply adding an overload.

@slide
Copy link
Contributor

slide commented Nov 7, 2017

Or change it to this and see if it works:

public static List range(CodeContext/*!*/ context, object start, object stop, [DefaultParameterValue((object)1)]object step)

@sekkit
Copy link
Author

sekkit commented Nov 7, 2017

ok, if it works I'll update this issue.

@sekkit
Copy link
Author

sekkit commented Nov 7, 2017

BTW, how can I build for 3.5 mono? I previously retrieved .net3.5 builds from NuGet.

@slide
Copy link
Contributor

slide commented Nov 7, 2017

4.0 is the minimum framework supported.

@sekkit
Copy link
Author

sekkit commented Nov 7, 2017

(object)xx ain't work. Why not change it to List range(CodeContext/!/ context, object start, object stop, [DefaultParameterValue((1))]int step)? // object to int, or int step=1

@slide
Copy link
Contributor

slide commented Nov 7, 2017

Because int isn't the only type that can be accepted. If you look inside the method, it accepts anything that can convert to BigInteger (which is a few different types). Do you get the same error, or a different one?

@slozier
Copy link
Contributor

slozier commented Nov 7, 2017

Try these instead:

        /// <summary>
        /// object overload of range - attempts to convert via __int__, and __trunc__ if arg is
        /// an OldInstance
        /// </summary>
        [return: SequenceTypeInfo(typeof(int))]
        public static List range(CodeContext/*!*/ context, object start, object stop) {
            BigInteger stopInt = GetRangeInt(context, stop, "end");
            BigInteger startInt = GetRangeInt(context, start, "start");

            return range(startInt, stopInt);
        }

        /// <summary>
        /// object overload of range - attempts to convert via __int__, and __trunc__ if arg is
        /// an OldInstance
        /// </summary>
        [return: SequenceTypeInfo(typeof(int))]
        public static List range(CodeContext/*!*/ context, object start, object stop, object step) {
            BigInteger stopInt = GetRangeInt(context, stop, "end");
            BigInteger startInt = GetRangeInt(context, start, "start");
            BigInteger stepInt = GetRangeInt(context, step, "step");

            return range(startInt, stopInt, stepInt);
        }

@sekkit
Copy link
Author

sekkit commented Nov 8, 2017

Yes, it worked. But there are many other DefaultValueParameter() to delete.
Can Removing those default value cause problems to IronPython?
Is there any other workarounds to reimplement the syntax in a compatible way?

PS: When written as "object step=1)", Visual Studio throws the same error as that in Unity. So there shall be another way of doing this.

This is might be ugly but the error is gone.

public static List range(CodeContext/*!*/ context, object start, object stop, object step) {
        if (step == null)
            step = (object)1;
        BigInteger stopInt = GetRangeInt(context, stop, "end");
        BigInteger startInt = GetRangeInt(context, start, "start");
        BigInteger stepInt = GetRangeInt(context, step, "step");
        return range(startInt, stopInt, stepInt);
}

Updated:
I modded all the codes so it compiles without any error!
But when I execute python code a runtime exception is thrown as Microsoft.Interpreter.ActionCallInstruction~2[IronPython.Runtime.CodeContext, ironPython, xxx]::ctor for which no ahead of time (AOT) code was generated.
here is the guides for AOT compatibility. I googled that some people solve this issue but I've no idea what piece of code is incompatible in IronPython.

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

Update2:
Where to remove System.Windows.Forms.dll reference.

@slozier
Copy link
Contributor

slozier commented Nov 8, 2017

I'm afraid the replacement you proposed for range is incorrect since it's not equivalent to the original statement since it doesn't distinguish between null and "no argument". The method should fail on null, but use 1 if no argument is given. The proper solution is the one I gave above.

I'm not sure about the issue you're having. It sounds as if the AOT compiler is skipping over some necessary code? I don't have any specific suggestions to offer, but looking at the restrictions it sounds like you may run into quite a few issues...

I don't think we have references to System.Windows.Forms.dll outside of testing code. If we do then they should probably be removed...

@sekkit
Copy link
Author

sekkit commented Nov 8, 2017

thx, I'll try see if there is a chance porting it to iOS.

@slide
Copy link
Contributor

slide commented Nov 8, 2017

If il2cpp doesn't support default paramater values, then you are not going to have much success. They are used all over the place.

@sekkit
Copy link
Author

sekkit commented Nov 8, 2017

it seems only object params need to be treated.

@drashnane
Copy link

drashnane commented Jan 22, 2018

Hi, I have another error in Unity2017.3 and il2cpp, compiling works,but get runtime error in ios:

2018-01-22 15:11:40.497163+0800 ProductName[12971:4525475] NSURLConnection finished with error - code -1009
MissingMethodException: Constructor on type 'Microsoft.Scripting.Hosting.ScriptHost' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0
at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00000] in <00000000000000000000000000000000>:0
at Microsoft.Scripting.Hosting.ScriptRuntime..ctor (Microsoft.Scripting.Hosting.ScriptRuntimeSetup setup) [0x00000] in <00000000000000000000000000000000>:0
at IronPython.Hosting.Python.CreateRuntime () [0x00000] in <00000000000000000000000000000000>:0
at IronPython.Hosting.Python.CreateEngine () [0x00000] in <00000000000000000000000000000000>:0

@slozier
Copy link
Contributor

slozier commented Jan 22, 2018

It sounds like il2cpp is stripping (or not generating) the default constructor? Try turning off bytecode stripping in the IronPython/DLR assemblies? https://docs.unity3d.com/Manual/IL2CPP-BytecodeStripping.html

@slide
Copy link
Contributor

slide commented Jan 23, 2018

This is really not something we have the bandwidth to support right now. If you would like to submit PR's for support for this, we can review them and merge them if they are ok, but otherwise, we really can't focus on this at all.

@hello32768
Copy link

Hi, sorry to bother you, but il2cpp doesn't support System.Reflection.Emit(in LightLambda.MakeRunDelegateCtor),is there anyway I can avoid this?

1 similar comment
@xiewendan
Copy link

Hi, sorry to bother you, but il2cpp doesn't support System.Reflection.Emit(in LightLambda.MakeRunDelegateCtor),is there anyway I can avoid this?

@eusebiu
Copy link

eusebiu commented Sep 24, 2020

You can try telling il2cpp to ignore that assembly.
Create a link.xml file and put it in the Assets folder:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
	<assembly fullname="Microsoft.Scripting" preserve="all"/>
</linker>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants