openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Add Emscripten to Windows releases

Open ofTheo opened this issue 2 years ago • 15 comments

Not sure if it works with Visual Studio compiler, but we should at least try it with msys2 / mingw64

relevant thread: https://forum.openframeworks.cc/t/webview-of-integration-how-to-dispatch/40464/16

ofTheo avatar Apr 11 '23 17:04 ofTheo

tried with the latest mingw64 msys2 nightly now that the emscripten libs are there

In the mingw64 shell these steps worked:

# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git

# Enter that directory
cd emsdk

# Download and install the latest SDK tools.
./emsdk install latest

# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest

# needed for mingw64 - NOTE: the other two env files don't work 
./emsdk activate latest --permanent

Then when I try and make an example with: emmake make

I get an error showing that the CXX is being set to the emscripten c++ path without the forward slashes.

ie: it is showing like: CUserstheoemsdkupstreamemscriptenem++.bat

instead of: /C/Users/theo/emsdk/upstream/emscripten/em++.bat

Not sure if it is our make files that is passing the CXX like that or emmake. I think it will work if we can get the CXX compiler path set.

cc @oxillo

ofTheo avatar Apr 21 '23 01:04 ofTheo

hmm looking at this issue seems to imply that on mingw64 you need to call a different make command: https://github.com/emscripten-core/emscripten/issues/2005

emmake mingw64-make

ofTheo avatar Apr 21 '23 03:04 ofTheo

@ofTheo with make I get the same error. with mingw32-make i get this error:

make: C:\msys64\mingw64\bin\mingw32-make.exe
Compiling OF library for Release
mingw32-make[1]: Entering directory 'C:/Users/Jonat/Desktop/of_v20230427_vs_release/libs/openFrameworksCompiled/project'
/usr/bin/sh: -c: line 2: syntax error: unexpected end of file
mingw32-make[2]: *** [makefileCommon/compile.core.mk:233: C:/Users/Jonat/Desktop/of_v20230427_vs_release/libs/openFrameworksCompiled/lib/emscripten/obj/Release/.compiler_flags] Error 2
mingw32-make[1]: *** [makefileCommon/compile.core.mk:204: Release] Error 2
mingw32-make[1]: Leaving directory 'C:/Users/Jonat/Desktop/of_v20230427_vs_release/libs/openFrameworksCompiled/project'
mingw32-make: *** [C:/Users/Jonat/Desktop/of_v20230427_vs_release/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:125: Release] Error 2
emmake: error: 'C:\msys64\mingw64\bin\mingw32-make.exe' failed (returned 2)

Jonathhhan avatar Apr 28 '23 02:04 Jonathhhan

@ofTheo I got Emscripten running on Windows with the wsl Linux subsystem. I followed this description: https://www.codeproject.com/Articles/5160967/Bring-Your-Cplusplus-Code-to-the-Web

Jonathhhan avatar Aug 09 '23 15:08 Jonathhhan

@Jonathhhan did you use the mingw OF nightly to do it? is it possible to document exactly what additional steps you had to do ?

We could then add it to the setup guide.

Thanks so much! Theo

ofTheo avatar Aug 09 '23 22:08 ofTheo

@ofTheo I used the linux64gcc6 nightly.

This is what I did (partly copied from https://www.codeproject.com/Articles/5160967/Bring-Your-Cplusplus-Code-to-the-Web):

Before we can install Ubuntu from Microsoft, we must first enable Developer's mode and WSL. To enable Developer mode, head to Settings > Update & Security > For Developers and select “Developer mode”.

Next, WSL has to be enabled on Windows Features. In the Windows searchbar, type "Turn Windows Features On or Off" and select that option. Scroll all the way down and check the "Windows Subsystem For Linux" option.

Next, launch Microsoft Store by clicking its button on the taskbar. Search for "Ubuntu" and click "Install" on the Ubuntu 22.04 in the search result. It takes about 5 minutes.

Start wsl in the terminal and add a Ubuntu user.

sudo apt update sudo apt upgrade git clone https://github.com/emscripten-core/emsdk.git

change to the newly cloned emsdk directory.

cd emsdk

Download and install the latest SDK tools.

./emsdk install latest

Set up the compiler configuration to point to the "latest" SDK.

./emsdk activate latest

Activate PATH and other environment variables in the current terminal

source ./emsdk_env.sh

install make

sudo apt install make

install chrome

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt install ./google-chrome-stable_current_amd64.deb

for make (optional)

sudo apt-get install pkg-config sudo apt-get install gcc cd /mnt/c/Users/Jonat/Downloads/of_v20230809_linux64gcc6_release/scripts/linux/ubuntu (your own path) sudo bash install_dependencies.sh

Jonathhhan avatar Aug 09 '23 23:08 Jonathhhan

Thanks @Jonathhhan
Ahh I see you end up essentially using the ubuntu OF release to run emscripten.

I was hoping it would enable it via the windows OF downloads :)

ofTheo avatar Aug 10 '23 02:08 ofTheo

I found this https://github.com/nokotan/VSExtForEmscripten worth checking out.

also note the official website says to install linux on your windows box to compile things image

danzeeeman avatar Aug 28 '23 05:08 danzeeeman

@danzeeeman I can confirm that it works well with windows subsystem for windows.

Jonathhhan avatar Aug 28 '23 08:08 Jonathhhan

@ofTheo if we can configure the VS project for emscripten build it should work with that extension

danzeeeman avatar Aug 28 '23 16:08 danzeeeman

On MSYS2, I've managed to go to the linker step following the instructions :

  1. launch a UCRT64 shell (not a MINGW64 !)
  2. Install emscripten with pacman -Sy mingw-w64-ucrt-x86_64-emscripten
  3. Close and restart the UCRT64 shell
  4. Download emscripten 3rdparty libraries with $OF_ROOT\script\emscripten\download_libs.sh
  5. Run emmake make...

oxillo avatar Sep 16 '23 21:09 oxillo

Hello everyone. I just tried to to build an openframeworks app with emscripten on windows. I didn't achieved to make it work, during the emmake make I've a bunch of errors. I'm too much beginner in Of and emscripten to understand if I did something wrong or if it's just not supported at the moment. Do you know what is the status of it ? Is compiling a openFramework app to wasm is supposed to work ? I'm using visual studio by the way

guillaume-leo avatar Oct 17 '24 09:10 guillaume-leo

hi @guillaume-leo , Can you please post the errors you get?

roymacdonald avatar Oct 17 '24 19:10 roymacdonald

I uninstall everything, I would like to make a new clean install of everything. @roymacdonald do you know which instructions I should follow to compile my oF project with emscripten (with visual studio) ?

guillaume-leo avatar Oct 18 '24 12:10 guillaume-leo

Yeah just run a git bash in the folder and run: emake make

Need environment variables set for emscripten full path

You can basically just build your app in VS2022 editor, then build it for emscritpen via command line and look at output html5. I think there’s some scripts to help build for the template from the project generator in the PR I did with updates for libs

I had the projectGenerator concept of adding option for em make, env location set in extra options and it would call Run script. But then I tried to make the system more secure cause it was, running and executing bash scripts, and was vulnerable so, I’ll try and recover the branch and finish that next week!

On Fri, 18 Oct 2024 at 11:39 pm, guillaume-leo @.***> wrote:

I uninstall everything, I would like to make a new clean install of everything. @roymacdonald https://github.com/roymacdonald do you know which instructions I should follow to compile my oF project with emscripten (with visual studio) ?

— Reply to this email directly, view it on GitHub https://github.com/openframeworks/openFrameworks/issues/7484#issuecomment-2422382677, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGK2HDXWUCGEXWVIP2J3PDZ4D6PRAVCNFSM6AAAAABQDLFD3SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRSGM4DENRXG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

danoli3 avatar Oct 18 '24 14:10 danoli3

so when I tried the command I've an error

PS C:\of_12\apps\myApps\mySketch> emmake make

make: C:\ProgramData\mingw64\mingw64\bin\mingw32-make.EXE

mingw32-make.EXE: *** No targets specified and no makefile found. Stop.

emmake: error: 'C:\ProgramData\mingw64\mingw64\bin\mingw32-make.EXE' failed (returned 2)

I suppose that it's because I'm not using oF with msys2 64bit ? But I don't want to, my setup is working correctly with visual studio 2022, I can build and run a openframeworks app like that.

guillaume-leo avatar Oct 20 '24 09:10 guillaume-leo

I tried also this: emcc src/main.cpp

I got an error:

'ofMain.h' file not found

guillaume-leo avatar Oct 20 '24 09:10 guillaume-leo

I think it’s emmake make Release

ofTheo avatar Oct 20 '24 13:10 ofTheo

No rule to make target 'release'. Stop. @ofTheo I'm going to investigate a bit more

guillaume-leo avatar Oct 20 '24 15:10 guillaume-leo

@guillaume-leo did you try @oxillo's steps in this thread? And did you make sure to do: source ./emsdk_env.sh ( you might need the full path to this file ) before you run the emmake commands?

ofTheo avatar Oct 21 '24 16:10 ofTheo