excubo-ag / WebCompiler

Apache License 2.0
148 stars 29 forks source link

.NET 6 on Apple Silicon #49

Closed michaelhofer closed 2 years ago

michaelhofer commented 2 years ago

Now that .NET6 supports the arm64 architecture for Apple Silicon, I am trying to get the webcompiler tool up and running on a Mac with an M1 processor.

Unfortunately, I run in this exception (thrown by LibSassHost):

 A compilation step encountered an exception During loading of Sass compiler error has occurred. Most likely it happened, because the 'libsass.dylib' assembly or one of its dependencies was not found. There is no LibSassHost.Native.osx-* package for the arm64 processor architecture. You can build the 'libsass.dylib' assembly for the current processor architecture by using following instructions - https://github.com/Taritsyn/LibSassHost#os-x-1. with stacktrace:
     at LibSassHost.SassCompiler.Initialize()
     at LibSassHost.SassCompiler.CompileFile(String inputPath, String outputPath, String sourceMapPath, CompilationOptions options)
     at WebCompiler.Compile.SassCompiler.Compile(List`1 file_sequence) in /home/runner/work/WebCompiler/WebCompiler/WebCompiler/Compile/SassCompiler.cs:line 71
     at WebCompiler.Compile.CompilationStep.With(Compiler compiler) in /home/runner/work/WebCompiler/WebCompiler/WebCompiler/Compile/CompilationStep.cs:line 22

I followed the mentioned steps and have the libsass.dylib in /usr/local/lib, but that does not help.

I can see that the latest version of WebCompiler targets net6.0 as well, but are there any other adaptions required?

stefanloerwald commented 2 years ago

Hi @michaelhofer,

I'm sadly not the best person to ask, as this concerns a dependency of webcompiler. Can you please file this in the libsasshost repo?

Thanks Stefan

michaelhofer commented 2 years ago

Hi @stefanloerwald

Sure, I will do so. I was not entirely sure if I should start there, but thanks for your reply.

Thanks Michael

michaelhofer commented 2 years ago

I can confirm that Webcompiler runs well now on Apple Silicon with .NET 6 and WebCompiler Version 3.0.1-preview.1.

Thank you @stefanloerwald !

bergkampx360 commented 2 years ago

Hi @michaelhofer,

I have a Webcompiler configuration for my project which is compiling on my Intel iMac without any problem, but not on my Apple Silicon.

I got the following error: [MSB3073] The command "dotnet webcompiler ./Styles/Sf3.scss -c excubowebcompiler.json" exited with code 137. There is no any other error message. If I run the above command in the command line, nothing happens. I just simply get my cursor back. I have installed .NET core SDK 6.0.100.

Do you have any idea what can be wrong with my setup? Do I have to install anything else other than .NET SDK?

csproj configuration

    <Target Name="ToolRestore">
        <Exec Command="dotnet tool restore" StandardOutputImportance="high" />
    </Target>

    <Target Name="WebCompiler" DependsOnTargets="ToolRestore">
        <!--compile and minify scss-->
        <Exec Command="dotnet webcompiler ./Styles/Sf3.scss -c excubowebcompiler.json" StandardOutputImportance="high" StandardErrorImportance="high" />
    </Target>

excubowebcompiler.json

{
  "Minifiers": {
    "GZip": false,
    "Enabled": true,
    "Css": {
      "CommentMode": "Important",
      "ColorNames": "Hex",
      "TermSemicolons": true,
      "OutputMode": "SingleLine",
      "IndentSize": 2
    },
    "Javascript": {
      "RenameLocals": false,
      "PreserveImportantComments": true,
      "EvalTreatment": "Ignore",
      "TermSemicolons": true,
      "OutputMode": "SingleLine",
      "IndentSize": 2
    }
  },
  "Autoprefix": {
    "Enabled": false,
    "ProcessingOptions": {
      "Browsers": [
        "last 4 versions"
      ],
      "Cascade": true,
      "Add": true,
      "Remove": true,
      "Supports": true,
      "Flexbox": "All",
      "Grid": "None",
      "IgnoreUnknownVersions": false,
      "Stats": "",
      "SourceMap": true,
      "InlineSourceMap": false,
      "SourceMapIncludeContents": false,
      "OmitSourceMapUrl": false
    }
  },
  "CompilerSettings": {
    "Sass": {
      "IndentType": "Space",
      "IndentWidth": 2,
      "OutputStyle": "Compressed",
      "RelativeUrls": true,
      "LineFeed": "Lf",
      "SourceMap": false
    }
  },
  "Output": {
    "Preserve": false,
    "Directory": "./wwwroot/css"
  }
}

dotnet-tools.json

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "excubo.webcompiler": {
      "version": "3.1.0-preview.1",
      "commands": [
        "webcompiler"
      ]
    }
  }
}
bergkampx360 commented 2 years ago

I have investigated the problem yesterday and I think the problem is not in this library.

I cloned the repository and built my own nuget from it. I think the problem is DarkSassHost itself or perhaps another dependency.

WebCompiler/Compile/SassCompiler.cs Line: 70-73

using (var compiler = new DartSassHost.SassCompiler(JsEngineFactory.Instance))
{
   compile_result = compiler.CompileFile(file, tmp_output_file, file, options);
}

When you try to access any of the properties or methods on the compiler instance, the program shuts down unexpectedly. There is no any kind of exception or error message.

Strangely if I just run the WebCompiler from my IDE(Rider), then everything works fine and the css file has been created.