apache / cordova

Apache Cordova
https://cordova.apache.org/
614 stars 64 forks source link

[Feature] WSL2 support. #486

Open cyraid opened 1 month ago

cyraid commented 1 month ago

Feature Request

Instead of using Wine, and you're on windows doing multiplatform build, why not detect and use WSL2 instead of running wine?

Motivation Behind Feature

Wine32 doesn't seem to install on WSL2.

Alternatives or Workarounds

Attempting to install Wine32.

breautek commented 1 month ago

I don't really understand the context.

Afaik WineHQ is only available on linux & macs to provide a POSIX compatibility layer to windows kernel calls. It wouldn't be used if you're already on windows.

And I'm unaware of any apache cordova package that attempts to use wine (or WSL).

Are you able to elaborate?

cyraid commented 1 month ago

@breautek Sure. Windows Sub-System for Linux (WSL) is basically a Linux emulation layer. I use it to run Ubuntu mostly. You can of course run Linux programs within it, but you can also run Windows executables from it.

I have a project that's in my home folder in WSL (Ubuntu), and I connect to it using vscode remote to WSL. I can build Linux version of app, but it would be nice that instead of using wine32, it would detect WSL and just run the .exe (like code sign etc) directly.

Edit: I was also successful in installing wine32 in WSL and being able to build .exe, and while the final .exe would run, it would crash after showing the window.

breautek commented 1 month ago

I think I understand now.

Mixing environments is going to be a recipe for disaster. It's not something I'd recommend.

But like I said, Cordova doesn't choose to run under wine. I've done an apache-cordova wide search for wine (or WSL/WSL2) and couldn't find anything.

Cordova itself should operate under WSL, but you should install all the linux version of the tools, including a linux node, and the platform sdk for linux (e.g. android sdk tools for linux).

Platforms usually have generated environment-specific files, so having a platform installed in a linux environment (like WSL) and then attempting to use the windows-version of the platform SDK on that project probably will not work. For example, android projects generated in a linux environment will use linux/posix file paths and windows version of the SDK will fail. Likewise an android project generated on a windows environment will have windows paths and will fail in a linux environment.

If you launch windows executables from WSL, it will launch the "windows" application and will trip OS environment checks, so it's important to install the linux version of the SDKs, like using a linux nodejs build to run Cordova.

I'm using the android platform for examples because it's what I'm the most familiar with but other platforms will likely have similar situations. If a project has multiple build targets (like electron) then you might need to clean the platform when switching environments. There is limited support for cross-compiling electron apps.

Am I misunderstanding something?

cyraid commented 1 month ago

@breautek I remember back in the day I did cross compiling with Free Pascal. Was making a cross platform game engine, and set it up to build on whichever platform right from one OS (windows, Linux, android). So it's not as if we should be sticking with the can't be done and not great mindset, as we should be aiming for a future where we can cross build all our apps from one OS, especially since I've been able to do that with Free Pascal for many years.

I know people can just say, setup a Docker and run Windows / Linux. But then of course there's the greedy Apple nightmare of being the only OS where you're pretty much forced to build it's stuff on it's own OS.

Then there's the pre-built exe age (like unity does with players). Pre-build the executable and just have separate files as your content. Which in reality, as far as I know, electron does this approach?

In the end, if code signing exe is the only thing electron builder needs to run in windows mode, there are other tools (just some Google searches) that you can use in Linux to sign the exe?

breautek commented 1 month ago

So it's not as if we should be sticking with the can't be done and not great mindset, as we should be aiming for a future where we can cross build all our apps from one OS

It's not usually in the control of Cordova. It's often due to the underlying SDKs and/or licensing issues.

Like you said, anything Apple is pretty much only supported on Mac OS.

In the end, if code signing exe is the only thing electron builder needs to run in windows mode, there are other tools (just some Google searches) that you can use in Linux to sign the exe?

For code-signing windows apps on mac/linux it is possible and electron itself has a guide to do so making use of a GPL-3 licensed tool. They are always license concerns surrounding around GPL packages. Apache isn't allowed to redistribute any GPL code or tools. So code-signing on linux is definitely not something that can be supported out of the box. The electron guide also notes using jsign instead which is an Apache 2.0 licensed product, so that could be a solution for codesigning window applications from mac and/or linux. In which case, I'd suggest creating a more specific feature request in cordova-electron.

I'm not familiar with the electron platform myself, so I'm not sure if the solutions are even accessible from within Cordova project.

Which in reality, as far as I know, electron does this approach?

I believe so for the electron core itself. This is mostly because compiling electron involves compiling chromium which is a beast of a project. If the electron project depends on any node modules that uses native C++ addon API, unless if they also supply prebuilt binaries, cross-compiling won't be supported. Most node modules that does include native addons do not supply prebuilt binaries because it's significantly easier to distribute the source and have the workstation compile for their own environment against the specific nodejs engine, etc.

cyraid commented 1 month ago

That's interesting. A license for open source holding back innovation. That's awfully unfortunate.

The electron builder tool downloads needed binaries / packages, it could be aimed at getting the other signing tools? I suppose this feature request should be on electron builder?