Skip to content

feat: add support for running wasm target in browser#7293

Merged
waruqi merged 4 commits intoxmake-io:devfrom
jinke18:dev
Feb 6, 2026
Merged

feat: add support for running wasm target in browser#7293
waruqi merged 4 commits intoxmake-io:devfrom
jinke18:dev

Conversation

@jinke18
Copy link
Contributor

@jinke18 jinke18 commented Feb 5, 2026

add support for running wasm target in browser

xmake f -p wasm
xmake b
xmake r
image

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jinke18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances xmake's capabilities by enabling the direct execution of WebAssembly (Wasm) targets within a web browser. It streamlines the development workflow for Wasm applications by automating the process of serving the compiled output via a local HTTP server, providing a convenient and integrated testing environment.

Highlights

  • WebAssembly (Wasm) Target Execution: Introduced support for running WebAssembly targets directly in a web browser using the xmake r command.
  • Automatic HTTP Server: When a Wasm target is executed, xmake now automatically launches a Python 3 HTTP server to serve the Wasm output, making it accessible via http://localhost:8000/.
  • Python 3 Dependency: Running Wasm targets in the browser now requires Python 3 to be installed on the system, as it's used to host the local HTTP server.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • xmake/actions/run/main.lua
    • Added a conditional block to detect if the target platform is 'wasm'.
    • Implemented logic to find and utilize python3 for starting an HTTP server.
    • Constructed a local URL (http://localhost:8000/) for accessing the Wasm target in a browser.
    • Used os.execv to run python3 -m http.server with appropriate environment settings.
    • Ensured the process detaches if the detach option is specified.
Activity
  • The pull request was created by jinke18.
  • It introduces a new feature to support running wasm targets in the browser.
  • No further review comments or activities have been recorded yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for running wasm targets in the browser by starting a Python http.server. The implementation is a good starting point. My review includes a suggestion to improve the security and robustness of the server by explicitly binding to localhost and specifying the port, which also opens the door for making the port configurable in the future.

local url = "http://localhost:8000/" .. path.relative(targetfile, rundir):gsub("\\", "/")
print("please open the url in browser")
cprint("${color.success}%s${clear}", url)
os.execv(python.program, {"-m", "http.server"}, {curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Python's http.server binds to 0.0.0.0 by default, which exposes the server to your local network. This could be a security risk, especially on untrusted networks. It's safer to explicitly bind to 127.0.0.1 (localhost).

Additionally, while http.server defaults to port 8000, making it explicit in the command improves clarity. As a future enhancement, you could make this port configurable (e.g. via option.get("port")).

        os.execv(python.program, {"-m", "http.server", "--bind", "127.0.0.1", "8000"}, {curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs})

@SirLynix
Copy link
Member

SirLynix commented Feb 5, 2026

Hello,

It would be a better idea to rely on the official emscripten test webserver emrun instead of Python which may not be available.

Plus it opens the browser automatically

@jinke18
Copy link
Contributor Author

jinke18 commented Feb 5, 2026

emrun is used to execute WebAssembly targets, with Python serving as a fallback. @SirLynix

@waruqi waruqi closed this Feb 5, 2026
@waruqi waruqi reopened this Feb 5, 2026
-- run wasm target in browser
if target:is_plat("wasm") then
-- try to run with emrun
local emrun = find_tool("emrun")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, it is not found on windows.

It could be emrun.bat, emrun.ps1, emrun.py, or the emrun shell script. Different platforms should use different script files.

Additionally, it is located in the upstream/emscripten subdirectory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在不同系统下检测emrun的逻辑在find_emrun.lua里面处理了,与find_emcc.lua逻辑一致,应该问题不大。
如果需要改进,是不是同时需要更改find_emcc.luafind_emar.lua?

The logic for detecting emrun in different systems has been processed in find_ emrun. lua, which is consistent with the logic of find_ emcc. lua, so there should be no problem.
If improvement is needed, do we need to change both find_ emcc. lua and find_ emar. lua at the same time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

查找问题是 find emsdk 导致,已经修了,得 rebase 下

#7296

@waruqi
Copy link
Member

waruqi commented Feb 5, 2026

please rebase to dev

@waruqi waruqi added this to the v3.0.7 milestone Feb 6, 2026
@waruqi waruqi merged commit 1128735 into xmake-io:dev Feb 6, 2026
35 checks passed
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.

3 participants