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

run ClearScript in Azure Function on Macos #542

Open Glareone opened 1 year ago

Glareone commented 1 year ago

PC: Macbook with Macos M1 Environment:

Executed code: using var engine = new V8ScriptEngine(); engine.Execute("");

When I try to run ClearScript in Console App using Microsoft.ClearScript.osx-arm64: 7.4.3 - everything is fine. But when Im trying to run it in Azure Function - I face the issue "ClearScriptV8.osx-arm64.dylib: Unable to load shared library":

SOLUTION:
1) Copy ClearScriptV8.osx-arm64.dylib from debug\net6.0\runtimes\osx-arm64\native and paste it in debug\net6.0\ folder as well. 2) For some reasons in Azure Function environment on Windows and Macos it requires Microsoft.ClearScript.V8.Native.osm-arm64 v.7.4.3 to be installed along with Microsoft.ClearScript.osx-arm64: 7.4.3 (for windows it's ClearScript.V8.Native.win-x64 along with ClearScript.V8)

Stack trace: System.TypeLoadException: Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.osx-arm64.dylib: /Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib: Unable to load shared library '/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib, 0x0001): tried: '/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib' (no such file), '/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib' (no such file) /Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/ClearScriptV8.osx-arm64.dylib: Unable to load shared library '/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/ClearScriptV8.osx-arm64.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/ClearScriptV8.osx-arm64.dylib, 0x0001): tried: '/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/ClearScriptV8.osx-arm64.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/ClearScriptV8.osx-arm64.dylib' (no such file), '/Users/Glareone/Documents/COMPANY_NAME/Azure-Function-CSharp/DSL-Functions/DSL-Parserless2/bin/Debug/net6.0/bin/ClearScriptV8.osx-arm64.dylib' (no such file) /Users/Glareone/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.55.0/ClearScriptV8.osx-arm64.dylib: Unable to load shared library '/Users/Glareone/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.55.0/ClearScriptV8.osx-arm64.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/Users/Glareone/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.55.0/ClearScriptV8.osx-arm64.dylib, 0x0001): tried: '/Users/Glareone/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.55.0/ClearScriptV8.osx-arm64.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Glareone/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.55.0/ClearScriptV8.osx-arm64.dylib' (no such file), '/Users/Glareone/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.55.0/ClearScriptV8.osx-arm64.dylib' (no such file)    at Microsoft.ClearScript.V8.V8Proxy.LoadNativeLibrary(String baseName, String platform, String architecture, String extension)

ClearScriptLib commented 1 year ago

Hi @Glareone,

To be honest, we're unfamiliar with the Azure Functions environment. We'll take a closer look, but it could take some time. We're glad you found a workaround.

Thanks!