-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added first class citizen emscripten support (new wasm64 architecture + emcc) #18432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7bed693
Added wasm64 architecture
perseoGI d69df31
Added MEMORY64=1 on wasm64 to architecture_flag function
perseoGI fd74916
Support asm.js arch correctly
perseoGI f448d85
Added emcc compiler support
perseoGI e3abe87
Added emcc compiler support
perseoGI 35b0b94
WIP Added functional tests
perseoGI 2055181
WIP: Added emscripten on windows
perseoGI c739f73
WIP: Added emscripten on windows
perseoGI a77a98b
WIP: Added emscripten on windows
perseoGI 2e8ce74
WIP: Added emscripten on windows
perseoGI 6ce7cb4
WIP: Added emscripten on windows
perseoGI 534712b
WIP: Added emscripten on windows
perseoGI 897d00e
Fix dockerfile
perseoGI a7b9ae1
Fix dockerfile
perseoGI ba25a85
Fix dockerfile
perseoGI 9b632a0
Fix dockerfile
perseoGI c6f28e6
Add EM_CACHE in docker container
perseoGI 1548eae
Pre build emscripten binaries on image and remove windows specific tests
perseoGI 56771f4
Pre build emscripten binaries on image and remove windows specific tests
perseoGI 3239a8e
Pre build emscripten binaries on image and remove windows specific tests
perseoGI 0fb3e7c
Only run node wasm64 on macos
perseoGI 20a4fa4
Relax tests to be os agnostic
perseoGI 43769af
Removed unneded platform_tool_requires
perseoGI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| # Test suite to check conan capabilities for cross compiling to web assembly and asmjs | ||
| import textwrap | ||
| import os | ||
| import platform | ||
| from shutil import rmtree | ||
| import pytest | ||
|
|
||
| from conan.test.utils.tools import TestClient | ||
|
|
||
| base_emscripten_profile = textwrap.dedent( | ||
| """ | ||
| [settings] | ||
| build_type=Release | ||
| compiler=emcc | ||
| compiler.cppstd=17 | ||
| compiler.libcxx=libc++ | ||
| compiler.version=4.0.10 | ||
| os=Emscripten | ||
|
|
||
| [conf] | ||
| tools.build:exelinkflags=['-sALLOW_MEMORY_GROWTH=1'] | ||
| tools.build:sharedlinkflags=['-sALLOW_MEMORY_GROWTH=1'] | ||
|
|
||
| # Define the emcc executable paths | ||
| tools.build:compiler_executables={'c':'emcc', 'cpp':'em++'} | ||
|
|
||
| # Set Ninja as default generator as it is faster and will sove issues on Windows | ||
| tools.cmake.cmaketoolchain:generator=Ninja | ||
| # Verbosity to see emcc invocations | ||
| tools.compilation:verbosity=verbose | ||
| # Distinguish between architectures | ||
| tools.cmake.cmake_layout:build_folder_vars=['settings.build_type', 'settings.arch'] | ||
|
|
||
| [buildenv] | ||
| AR=emar | ||
| NM=emnm | ||
| RANLIB=emranlib | ||
| STRIP=emstrip | ||
| """ | ||
| ) | ||
|
|
||
| wasm32_profile = textwrap.dedent( | ||
| """ | ||
| include(base_emscripten_profile) | ||
| [settings] | ||
| arch=wasm | ||
|
|
||
| [conf] | ||
| tools.build:exelinkflags+=['-sMAXIMUM_MEMORY=4GB', '-sINITIAL_MEMORY=64MB'] | ||
| tools.build:sharedlinkflags+=['-sMAXIMUM_MEMORY=4GB', '-sINITIAL_MEMORY=64MB'] | ||
| """ | ||
| ) | ||
|
|
||
| wasm_64_profile = textwrap.dedent( | ||
| """ | ||
| include(base_emscripten_profile) | ||
| [settings] | ||
| arch=wasm64 | ||
| [conf] | ||
| tools.build:exelinkflags+=['-sMAXIMUM_MEMORY=16GB', '-sINITIAL_MEMORY=16GB'] | ||
| tools.build:sharedlinkflags+=['-sMAXIMUM_MEMORY=16GB', '-sINITIAL_MEMORY=16GB'] | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| asmjs_profile = textwrap.dedent( | ||
| """ | ||
| include(base_emscripten_profile) | ||
| [settings] | ||
| arch=asm.js | ||
|
|
||
| [conf] | ||
| tools.build:exelinkflags+=['-sMAXIMUM_MEMORY=2GB', '-sINITIAL_MEMORY=64MB'] | ||
| tools.build:sharedlinkflags+=['-sMAXIMUM_MEMORY=2GB', '-sINITIAL_MEMORY=64MB'] | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.tool("cmake") | ||
| @pytest.mark.tool("emcc") | ||
| @pytest.mark.tool("node") | ||
| @pytest.mark.skipif(platform.system() == "Windows", reason = "Emscripten not installed in Windows") | ||
| def test_cmake_emscripten(): | ||
| client = TestClient() | ||
|
|
||
| client.run("new cmake_exe -d name=hello -d version=0.1") | ||
| client.save({"wasm32": wasm32_profile, "asmjs": asmjs_profile, "base_emscripten_profile": base_emscripten_profile,}) | ||
|
|
||
| client.run("build . -pr:h=wasm32") | ||
| assert "Conan toolchain: Defining libcxx as C++ flags: -stdlib=libc++" in client.out | ||
| assert os.path.exists(os.path.join(client.current_folder, "build/release-wasm" , "hello.wasm")) | ||
|
|
||
| # Run JavaScript generated code which uses .wasm file | ||
| client.run_command("node ./build/release-wasm/hello") | ||
| assert "Hello World Release!" in client.out | ||
|
|
||
| client.run("build . -pr:h=asmjs") | ||
| assert "WASM=0" in client.out | ||
| # No wasm should have been generated for asm.js architecture | ||
| assert not os.path.exists(os.path.join(client.current_folder, "build/release-asm.js" , "hello.wasm")) | ||
| client.run_command("node ./build/release-asm.js/hello") | ||
| assert "Hello World Release!" in client.out | ||
|
|
||
|
|
||
| @pytest.mark.tool("meson") | ||
| @pytest.mark.tool("emcc") | ||
| @pytest.mark.tool("node") | ||
| @pytest.mark.skipif(platform.system() == "Windows", reason = "Emscripten not installed in Windows") | ||
| def test_meson_emscripten(): | ||
| client = TestClient() | ||
| client.run("new meson_exe -d name=hello -d version=0.1") | ||
|
|
||
| client.save({"wasm32": wasm32_profile, "wasm64": wasm_64_profile, "asmjs": asmjs_profile, "base_emscripten_profile": base_emscripten_profile,}) | ||
| client.run("build . -pr:h=wasm64") | ||
| assert "C++ compiler for the host machine: em++" in client.out | ||
| assert "C++ linker for the host machine: em++ ld.wasm" in client.out | ||
| assert "Host machine cpu family: wasm64" in client.out | ||
| assert os.path.exists(os.path.join(client.current_folder, "build", "hello.wasm")) | ||
| # wasm64 only supported since node v23 so only run in MacOS where it is available | ||
| if platform.system() == "Darwin": | ||
| client.run_command("node ./build/hello") | ||
| assert "Hello World Release!" in client.out | ||
|
|
||
| rmtree(os.path.join(client.current_folder, "build")) | ||
| client.run("build . -pr:h=asmjs") | ||
| assert "C++ compiler for the host machine: em++" in client.out | ||
| assert "C++ linker for the host machine: em++ ld.wasm" in client.out | ||
| assert "Host machine cpu family: asm.js" in client.out | ||
| assert "WASM=0" in client.out | ||
|
|
||
| assert not os.path.exists(os.path.join(client.current_folder, "build", "hello.wasm")) | ||
| client.run_command("node ./build/hello") | ||
| assert "Hello World Release!" in client.out | ||
|
|
||
|
|
||
| @pytest.mark.tool("autotools") | ||
| @pytest.mark.tool("emcc") | ||
| @pytest.mark.tool("node") | ||
| @pytest.mark.skipif(platform.system() == "Windows", reason = "Emscripten not installed in Windows") | ||
| def test_autotools_emscripten(): | ||
| client = TestClient(path_with_spaces=False) | ||
| client.run("new autotools_exe -d name=hello -d version=0.1") | ||
| client.save({"wasm32": wasm32_profile, "asmjs": asmjs_profile, "base_emscripten_profile": base_emscripten_profile,}) | ||
| client.run("build . -pr:h=wasm32") | ||
| assert "checking for wasm32-local-emscripten-ranlib... emranlib" in client.out | ||
| assert "checking for wasm32-local-emscripten-gcc... emcc" in client.out | ||
| assert "checking for wasm32-local-emscripten-ar... emar" in client.out | ||
| assert "checking the archiver (emar) interface... ar" in client.out | ||
| assert "checking for wasm32-local-emscripten-strip... emstrip" in client.out | ||
|
|
||
| assert os.path.exists(os.path.join(client.current_folder, "build-release", "src", "hello.wasm")) | ||
| # Run JavaScript generated code which uses .wasm file | ||
| client.run_command("node ./build-release/src/hello") | ||
| assert "Hello World Release!" in client.out | ||
|
|
||
| rmtree(os.path.join(client.current_folder, "build-release")) | ||
| client.run("build . -pr:h=asmjs") | ||
| assert "WASM=0" in client.out | ||
| # No wasm should have been generated for asm.js architecture | ||
| assert not os.path.exists(os.path.join(client.current_folder, "build-release", "hello.wasm")) | ||
| client.run_command("node ./build-release/src/hello") | ||
| assert "Hello World Release!" in client.out | ||
|
|
||
|
|
||
| # TODO: test_bazel_emscripten(): need WIP new bazel toolchain | ||
| # TODO: test_msbuild_emscripten(): give support to msbuild | ||
| # TODO: test_premake_emscripten(): premake tests | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.