Skip to content

Add emcc toolchain for WASM builds using Emscripten#2

Merged
waruqi merged 4 commits intoxmake-io:masterfrom
daviwil:emscripten-support
Apr 6, 2023
Merged

Add emcc toolchain for WASM builds using Emscripten#2
waruqi merged 4 commits intoxmake-io:masterfrom
daviwil:emscripten-support

Conversation

@daviwil
Copy link
Copy Markdown
Contributor

@daviwil daviwil commented Apr 6, 2023

First of all, thanks so much for creating this project, it fits my requirements perfectly! I wanted a better way to build widely cross-platform apps without relying on CMake, etc, and I happened to find XMake and xmake.sh a few weeks ago. Great work!

This PR updates path_toolname to detect the names of the Emscripten tools so that configure can be used with the emconfigure command. After these changes (and installing the Emscripten SDK), one can build their project for the web by using the following commands:

emconfigure ./configure
make

I'm not sure if a full toolchain description should be added for Emscripten instead, but these minimal changes seemed to be enough to get everything working perfectly on my end.

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 6, 2023

We should add a toolchain named (emcc). like this

toolchain "x86_64_w64_mingw32"

and add a new platform and arch, wasm and wasm32

then run

./configure --plat=wasm --arch=wasm32
make

and we can improve to detect platform/arch in emcc envs.

so we just need

./configure
make

@daviwil
Copy link
Copy Markdown
Contributor Author

daviwil commented Apr 6, 2023

Added a new toolchain called wasm32_unknown_wasm, I'm not sure if this is the correct triplet name so please let me know if I should change it.

@daviwil daviwil force-pushed the emscripten-support branch from 457faab to 03b2805 Compare April 6, 2023 07:07
@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 6, 2023

and you can check envs to detect wasm platform and arch automatically.

_target_plat_default=${os_host}

@daviwil
Copy link
Copy Markdown
Contributor Author

daviwil commented Apr 6, 2023

and you can check envs to detect wasm platform and arch automatically.

Do you have a suggestion for which environment variable to check? It looks like EMMAKEN_JUST_CONFIGURE=1 is set when emconfigure is run, that one might be useful. I suppose we could also just check for EMSCRIPTEN too. Which do you prefer?

@daviwil daviwil changed the title Add basic Emscripten support Add emcc toolchain for WASM builds using Emscripten Apr 6, 2023
@daviwil
Copy link
Copy Markdown
Contributor Author

daviwil commented Apr 6, 2023

Looks like EMSDK is the only reliable variable present when the Emscripten SDK shell has been loaded up, so I'm checking for that. Seems to work as expected when I run this:

docker run -v `pwd`:`pwd` -w `pwd` -u $(id -u):$(id -g) emscripten/emsdk /bin/sh -c "./configure"

Output:

checking for platform ... wasm
checking for architecture ... x86_64
checking for make ... ok
checking for the c (cc) ... emcc
checking for the c++ (cxx) ... emcc
checking for the assembler (as) ... emcc
checking for the objc (mm) ... emcc
checking for the objc++ (mxx) ... emcc
checking for the linker (ld) ... em++
checking for the static (ar) ... emar
checking for the shared (sh) ... em++
checking for toolchain ... emcc
...

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 6, 2023

ok, thanks!

@waruqi waruqi merged commit 9de2967 into xmake-io:master Apr 6, 2023
@daviwil
Copy link
Copy Markdown
Contributor Author

daviwil commented Apr 6, 2023

Thank you, too!

@daviwil daviwil deleted the emscripten-support branch April 6, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants