microsoft / ClearScript

A library for adding scripting to .NET applications. Supports V8 (Windows, Linux, macOS) and JScript/VBScript (Windows).
https://microsoft.github.io/ClearScript/
MIT License
1.77k stars 148 forks source link

ClearScript tries to load x64 native library in M1 Mac #368

Open KurtGokhan opened 2 years ago

KurtGokhan commented 2 years ago

I tried to run my app in a M1 architecture MacOS. ClearScript seems to be failing to detect that it is running in Arm64 architecture. It is picking the osx-x64 file whereas it should pick the osx-arm64 file.

TypeLoadException: Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.osx-x64.dylib:
/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Resources/Data/Managed/runtimes/osx-x64/native/ClearScriptV8.osx-x64.dylib: Unknown error
/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Resources/Data/Managed/ClearScriptV8.osx-x64.dylib: dlopen(/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Resources/Data/Managed/ClearScriptV8.osx-x64.dylib, 0x000A): tried: '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Resources/Data/Managed/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file)
/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ClearScriptV8.osx-x64.dylib: dlopen(/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ClearScriptV8.osx-x64.dylib, 0x000A): tried: '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file)
/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/ClearScriptV8.osx-x64.dylib: dlopen(/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/ClearScriptV8.osx-x64.dylib, 0x000A): tried: '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file)
/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Plugins/ClearScriptV8.osx-x64.dylib: dlopen(/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Plugins/ClearScriptV8.osx-x64.dylib, 0x000A): tried: '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Plugins/ClearScriptV8.osx-x64.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/PlugIns/ClearScriptV8.osx-x64.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file)
/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Plugins/x86_64/ClearScriptV8.osx-x64.dylib: dlopen(/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Plugins/x86_64/ClearScriptV8.osx-x64.dylib, 0x000A): tried: '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ReactUnity Dev Sample.app/Contents/Plugins/x86_64/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file)
ClearScriptV8.osx-x64.dylib: dlopen(ClearScriptV8.osx-x64.dylib, 0x000A): tried: 'ClearScriptV8.osx-x64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/private/var/folders/35/bc274k0n57b08hgcvp_fn5c40000gp/T/AppTranslocation/1831CB9B-80ED-4764-9700-D793E8EBB498/d/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-x64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-x64.dylib' (no such file)
  at Microsoft.ClearScript.V8.V8Proxy.LoadNativeLibrary (System.String baseName, System.String platform, System.String architecture, System.String extension) [0x0016f] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8Proxy.LoadNativeAssembly () [0x000d0] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8Proxy.OnEntityHolderCreated () [0x00021] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.SplitProxy.V8EntityHolder..ctor (System.String name, System.Func`1[TResult] acquireHandle) [0x00007] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.SplitProxy.V8IsolateProxyImpl..ctor (System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints, Microsoft.ClearScript.V8.V8RuntimeFlags flags, System.Int32 debugPort) [0x00029] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8IsolateProxy.Create (System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints, Microsoft.ClearScript.V8.V8RuntimeFlags flags, System.Int32 debugPort) [0x00000] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8Runtime..ctor (System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints, Microsoft.ClearScript.V8.V8RuntimeFlags flags, System.Int32 debugPort) [0x00055] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8Runtime..ctor (System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints, Microsoft.ClearScript.V8.V8RuntimeFlags flags) [0x00000] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8Runtime..ctor (System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints) [0x00000] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8ScriptEngine..ctor (Microsoft.ClearScript.V8.V8Runtime runtime, System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints, Microsoft.ClearScript.V8.V8ScriptEngineFlags flags, System.Int32 debugPort) [0x00039] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8ScriptEngine..ctor (System.String name, Microsoft.ClearScript.V8.V8RuntimeConstraints constraints, Microsoft.ClearScript.V8.V8ScriptEngineFlags flags, System.Int32 debugPort) [0x00000] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at Microsoft.ClearScript.V8.V8ScriptEngine..ctor (Microsoft.ClearScript.V8.V8ScriptEngineFlags flags, System.Int32 debugPort) [0x00000] in <f1e6d8f3499e404dbf08feb088b56e3a>:0 
  at ReactUnity.Scripting.ClearScriptEngine..ctor (ReactUnity.ReactContext context, System.Boolean debug, System.Boolean awaitDebugger) [0x00066] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.Scripting.ClearScriptEngineFactory.Create (ReactUnity.ReactContext context, System.Boolean debug, System.Boolean awaitDebugger) [0x00000] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.Scripting.ScriptContext.CreateBaseEngine (System.Boolean debug, System.Boolean awaitDebugger) [0x00000] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.Scripting.ScriptContext.Initialize () [0x0001e] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.Scripting.ScriptContext.RunScript (System.String script, System.Action beforeStart, System.Action afterStart) [0x0001d] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.ReactContext+<>c__DisplayClass85_0.<Start>b__0 (System.String code) [0x000be] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.ScriptSource.GetScript (System.Action`1[T] callback, ReactUnity.Scheduling.IDispatcher dispatcher, System.Boolean useDevServer) [0x000be] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.ReactContext.Start () [0x0002c] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.ReactUnityBase.LoadAndRun (ReactUnity.ScriptSource script) [0x00068] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.ReactUnityBase.Render () [0x00006] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 
  at ReactUnity.ReactUnityBase.OnEnable () [0x00008] in <d656f35a2faa42f5b6f1320b033a5ebc>:0 

There does not seem to be anything wrong with ClearScript source code. So this is probably a Mono bug, where it fails to detect it is running on Arm64 and picks x64. I encountered this kind of issue when trying to load correct libraries in my Android implementation attempt and I added a global flag to tell that the app is running on Android. I could add another flag for this, but I would be deviating away from original source code.

Is there a better way to detect the architecture. Or can there be a global configuration for choosing which native library to load? No pressure though, I know this isn't a .NET bug and maybe out of your scope.

ClearScriptLib commented 2 years ago

Hi @KurtGokhan,

Thanks for reporting this. We're considering making OS/platform detection overridable in a future release.

Cheers!

eliashezron commented 1 year ago

Is there a workaround this? @ClearScriptLib

ClearScriptLib commented 1 year ago

Hi @eliashezron,

Is there a workaround this?

We aren't aware of a reproducible case of this. In all our testing, ClearScript correctly detects the process architecture (arm64 vs. x64) and loads the appropriate native library.

If you're on Apple Silicon and your application is loading ClearScriptV8.osx-x64.dylib, you can use Activity Monitor to verify that your application is running in emulated x64 mode (the Kind column will show "Intel").

Good luck!