emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
3.02k stars 688 forks source link

Self-host Python bootstrap [on Windows] #719

Open RReverser opened 3 years ago

RReverser commented 3 years ago

As I've been setting up a new Windows machine, I was installing emsdk and found it odd that:

  1. In order to run ./emsdk.ps1 install latest, you need to have Python system-wide.
  2. You install Python.
  3. Once you run ./emsdk.ps1 install latest, it downloads its own Python too.

While Python is built-in on Unix systems, it's not on Windows, and I wonder if we could make the bootstrap process easier by moving Python download step to emsdk.ps1 (PowerShell) itself.

Then, user could just run ./emsdk.ps1 install latest, it would download the Python locally, and then use it to run the main emsdk.py script.

RReverser commented 3 years ago

In fact, we could even do the same on other operating systems, and then get rid of any Python 2 hacks in our scripts, since we know we use our own Python 3 version.

sbc100 commented 3 years ago

I'd like to find a way to solve this.

One reason we do this today is so that we know exactly what version of python is being used by emsdk users. Regardless of what version is installed in (2) we control the version in (3) and the version that is then used going forward. I'd like to keep this property.

Note that we recently change the version of python that we install to not be added to the PATH so as not to mess with the version in (3) (#706). Just FYI.. i think this is way more polite.

emsdk is effectively the bootstrap script.. so it is the only place we need to continue to support python2, so those hack are not widespread.

We did used to have a downloadable version of emsdk that included everything in a single zip file (i think it was called emsdk-portable right @kripken?).

I see a few options for how to make this better:

  1. Restore emsdk-portable.zip. (that includes everything in a single zip)
  2. Create new download zip files that contains at least python.
  3. As you suggest, write the download script in .ps1 (and presumablye in bash too for macOS users), and also maybe in .bat, or can we assume all windows users are powershell users now ? I guess not?

I kind of like (2), we can use github actions to publish it, and this also removes the current dependency on git.

sbc100 commented 3 years ago

The same problem will exist on mac too I believe if they ever remove /use/bin/python (which I heard they want to do.. at least it is very deprecated today).

RReverser commented 3 years ago

Regardless of what version is installed in (2) we control the version in (3) and the version that is then used going forward. I'd like to keep this property.

If anything, the suggestion above should enforce this property even further (see the 2nd comment: https://github.com/emscripten-core/emsdk/issues/719#issuecomment-781521230).

and also maybe in .bat, or can we assume all windows users are powershell users now ? I guess not?

Not sure. I think for PowerShell we can use the built-in functionality for downloading files, while for the rest shell out to e.g. curl, expecting that it's installed.

Or .bat can even call PowerShell under the hood - I think even if user doesn't explicitly use PowerShell, they at least have it installed somewhere.

sbc100 commented 3 years ago

Yeah I like the idea of invoke powershell from cmd. According to https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.1:

"Windows PowerShell comes installed by default in every Windows, starting with Windows 7 SP1 and Windows Server 2008 R2 SP1."

So we should be good I think.