Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
seperate jsb assemblies from assemblies of project with asmdef
Browse files Browse the repository at this point in the history
  • Loading branch information
ialex32x committed Oct 27, 2021
1 parent 77a2d4b commit ea0d339
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,119 @@ public class InMemoryCompilationBindingCallback : IBindingCallback, ICodeGenCall
private List<Assembly> _generatedAssemblies = new List<Assembly>();
private string _compilerOptions;

public static List<string> GetDefinedSymbols()
{
var defines = new List<string>();

#if UNITY_EDITOR // #define directive to call Unity Editor scripts from your game code.
defines.Add("UNITY_EDITOR");
#endif
#if UNITY_EDITOR_WIN // #define directive for Editor code on Windows.
defines.Add("UNITY_EDITOR_WIN");
#endif
#if UNITY_EDITOR_OSX // #define directive for Editor code on Mac OS X.
defines.Add("UNITY_EDITOR_OSX");
#endif
#if UNITY_EDITOR_LINUX // #define directive for Editor code on Linux.
defines.Add("UNITY_EDITOR_LINUX");
#endif
#if UNITY_STANDALONE_OSX // #define directive to compile or execute code specifically for Mac OS X (including Universal, PPC and Intel architectures).
defines.Add("UNITY_STANDALONE_OSX");
#endif
#if UNITY_STANDALONE_WIN // #define directive for compiling/executing code specifically for Windows standalone applications.
defines.Add("UNITY_STANDALONE_WIN");
#endif
#if UNITY_STANDALONE_LINUX // #define directive for compiling/executing code specifically for Linux standalone applications.
defines.Add("UNITY_STANDALONE_LINUX");
#endif
#if UNITY_STANDALONE // #define directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux).
defines.Add("UNITY_STANDALONE");
#endif
#if UNITY_WII // #define directive for compiling/executing code for the Wii console.
defines.Add("UNITY_WII");
#endif
#if UNITY_IOS // #define directive for compiling/executing code for the iOS platform.
defines.Add("UNITY_IOS");
#endif
#if UNITY_IPHONE // Deprecated. Use UNITY_IOS instead.
defines.Add("UNITY_IPHONE");
#endif
#if UNITY_ANDROID // #define directive for the Android platform.
defines.Add("UNITY_ANDROID");
#endif
#if UNITY_PS4 // #define directive for running PlayStation 4 code.
defines.Add("UNITY_PS4");
#endif
#if UNITY_XBOXONE // #define directive for executing Xbox One code.
defines.Add("UNITY_XBOXONE");
#endif
#if UNITY_LUMIN // #define directive for the Magic Leap OS platform. You can also use PLATFORM_LUMIN.
defines.Add("UNITY_LUMIN");
#endif
#if UNITY_TIZEN // #define directive for the Tizen platform.
defines.Add("UNITY_TIZEN");
#endif
#if UNITY_TVOS // #define directive for the Apple TV platform.
defines.Add("UNITY_TVOS");
#endif
#if UNITY_WSA // #define directive for Universal Windows Platform
defines.Add("UNITY_WSA");
#endif
#if UNITY_WSA_10_0 // #define directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C# files against .NET Core.
defines.Add("UNITY_WSA_10_0");
#endif
#if UNITY_WINRT // Same as UNITY_WSA.
defines.Add("UNITY_WINRT");
#endif
#if UNITY_WINRT_10_0 // Equivalent to UNITY_WSA_10_0
defines.Add("UNITY_WINRT_10_0");
#endif
#if UNITY_WEBGL // #define directive for WebGL
defines.Add("UNITY_WEBGL");
#endif
#if UNITY_FACEBOOK // #define directive for the Facebook platform (WebGL or Windows standalone).
defines.Add("UNITY_FACEBOOK");
#endif
#if UNITY_ANALYTICS // #define directive for calling Unity Analytics
defines.Add("UNITY_ANALYTICS");
#endif
#if UNITY_ASSERTIONS // #define directive for assertions control process.
defines.Add("UNITY_ASSERTIONS");
#endif
#if UNITY_64 // #define directive for 64-bit platforms.
defines.Add("UNITY_64");
#endif
#if UNITY_SERVER
defines.Add("UNITY_SERVER");
#endif
return defines;
}

#if !JSB_UNITYLESS && UNITY_EDITOR
public static UnityEditor.BuildTargetGroup GetBuildTargetGroup()
{
var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
switch (buildTarget)
{
case UnityEditor.BuildTarget.Android: return UnityEditor.BuildTargetGroup.Android;
case UnityEditor.BuildTarget.iOS: return UnityEditor.BuildTargetGroup.iOS;
case UnityEditor.BuildTarget.WSAPlayer: return UnityEditor.BuildTargetGroup.WSA;
#if !UNITY_2019_2_OR_NEWER
case UnityEditor.BuildTarget.StandaloneLinux:
case UnityEditor.BuildTarget.StandaloneLinuxUniversal:
#endif
case UnityEditor.BuildTarget.StandaloneLinux64:
case UnityEditor.BuildTarget.StandaloneOSX:
case UnityEditor.BuildTarget.StandaloneWindows:
case UnityEditor.BuildTarget.StandaloneWindows64: return UnityEditor.BuildTargetGroup.Standalone;
case UnityEditor.BuildTarget.Switch: return UnityEditor.BuildTargetGroup.Switch;
case UnityEditor.BuildTarget.PS4: return UnityEditor.BuildTargetGroup.PS4;
case UnityEditor.BuildTarget.XboxOne: return UnityEditor.BuildTargetGroup.XboxOne;
}
throw new NotImplementedException();
}
#endif

public InMemoryCompilationBindingCallback(ScriptRuntime runtime)
{
_runtime = runtime;
Expand All @@ -26,13 +139,13 @@ public InMemoryCompilationBindingCallback(ScriptRuntime runtime)
var compilerOptions = "-unsafe";

#if !JSB_UNITYLESS
symbolList.AddRange(Unity.UnityHelper.GetDefinedSymbols());
symbolList.AddRange(GetDefinedSymbols());
#endif

defines += string.Join(";", symbolList);

#if !JSB_UNITYLESS && UNITY_EDITOR
var customDefinedSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(Unity.UnityHelper.GetBuildTargetGroup());
var customDefinedSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(GetBuildTargetGroup());
if (!string.IsNullOrEmpty(customDefinedSymbols))
{
defines += ";" + customDefinedSymbols;
Expand Down
62 changes: 27 additions & 35 deletions Assets/jsb/Source/Binding/Editor/IBindingUtils.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;

namespace QuickJS.Binding
{
public interface IBindingUtils
{
string ReplacePathVars(string value);

bool IsExplicitEditorType(Type type);
}

public class DefaultBindingUtils : IBindingUtils
{
public string ReplacePathVars(string value)
{
#if JSB_UNITYLESS
value = value.Replace("${platform}", "unityless");
return value;
#else
return Unity.UnityHelper.ReplacePathVars(value);
#endif
}

public bool IsExplicitEditorType(Type type)
{
#if JSB_UNITYLESS
return false;
#else
return Unity.UnityHelper.IsExplicitEditorType(type);
#endif
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;

namespace QuickJS.Binding
{
public interface IBindingUtils
{
string ReplacePathVars(string value);

bool IsExplicitEditorType(Type type);
}

public class DefaultBindingUtils : IBindingUtils
{
public string ReplacePathVars(string value)
{
value = value.Replace("${platform}", "unityless");
return value;
}

public bool IsExplicitEditorType(Type type)
{
return false;
}
}
}
17 changes: 17 additions & 0 deletions Assets/jsb/Source/Binding/Editor/jsb.editor.binding.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "jsb.editor.binding",
"references": [
"GUID:118b4ca3a1852354bac065cf952c1e85"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Assets/jsb/Source/Unity/Editor/PrefsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,14 @@ protected override void OnEnable()
{
base.OnEnable();

var args = new BindingManager.Args()
{
utils = new UnityBindingUtils(),
};

_prefs = UnityHelper.LoadPrefs(out _filePath);
_selectedBindingMethod = Array.IndexOf(_bindingMethodValues, _prefs.preferredBindingMethod);
_bindingManager = new BindingManager(_prefs, new BindingManager.Args());
_bindingManager = new BindingManager(_prefs, args);
_bindingManager.Collect();
_bindingManager.Generate(TypeBindingFlags.None);
_bindingManager.Report();
Expand Down
20 changes: 20 additions & 0 deletions Assets/jsb/Source/Unity/Editor/UnityBindingUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;

namespace QuickJS.Unity
{
public class UnityBindingUtils : Binding.IBindingUtils
{
public string ReplacePathVars(string value)
{
return Unity.UnityHelper.ReplacePathVars(value);
}

public bool IsExplicitEditorType(Type type)
{
return Unity.UnityHelper.IsExplicitEditorType(type);
}
}
}
11 changes: 11 additions & 0 deletions Assets/jsb/Source/Unity/Editor/UnityBindingUtils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea0d339

Please sign in to comment.