Add Emscripten toolchain & build_config#6487
Conversation
There was a problem hiding this comment.
Hello @esotericpig, 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!
Summary of Changes
This pull request adds support for Emscripten to the mruby build system. It includes a new toolchain definition, build configurations for both C and C++ projects, and a fix for a compilation issue in the mruby-cmath gem when compiling with a C++ compiler. The changes aim to allow mruby to be compiled and run in web browsers and other environments supported by Emscripten.
Highlights
- Emscripten Toolchain: A new toolchain definition (
tasks/toolchains/emscripten.rake) is added, configuring the compiler, linker, and archiver to use Emscripten's tools (emcc,em++,emar). It also sets up compile and link flags, with links to the Emscripten documentation. - Build Configurations: New build configurations (
build_config/emscripten.rbandbuild_config/emscripten-cxx.rb) are added for Emscripten, providing instructions on how to link mruby to Emscripten applications using themruby-configflags. - C++ Compatibility Fix: A conditional compilation issue in
mrbgems/mruby-cmath/src/cmath.cis resolved by adding__EMSCRIPTEN__to the list of platforms where a specific C++ workaround is needed.
Changelog
Click here to see the changelog
- build_config/emscripten-cxx.rb
- Added a new build configuration file for Emscripten C++ projects.
- Includes instructions to use
mruby-configflags for compilation and linking (lines 1-5). - Configures the toolchain to use Emscripten (line 7).
- Enables the C++ ABI (line 11).
- build_config/emscripten.rb
- Added a new build configuration file for Emscripten C projects.
- Includes instructions to use
mruby-configflags for compilation and linking (lines 1-5). - Configures the toolchain to use Emscripten (line 7).
- mrbgems/mruby-cmath/src/cmath.c
- Modified the conditional compilation directive to include
__EMSCRIPTEN__(line 96). - This fixes a compilation issue when building with C++ on Emscripten.
- Modified the conditional compilation directive to include
- tasks/toolchains/emscripten.rake
- Added a new toolchain definition for Emscripten.
- Configures the compiler, linker, and archiver to use Emscripten's tools (lines 18-35).
- Sets up compile and link flags, with links to the Emscripten documentation (lines 4-7).
- Adds
-Wno-unused-but-set-variableto compile flags (line 12).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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.
Trivia time!
What JavaScript engine powers Emscripten, enabling it to run C and C++ code in web browsers?
Click here for the answer
WebAssembly (Wasm) is the technology that allows Emscripten to run C and C++ code in web browsers. It provides a low-level, assembly-like language that can be executed efficiently by modern JavaScript engines.
Footnotes
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces support for Emscripten, which is a valuable addition to the project. The changes seem well-structured and address the identified issues. However, there are a few points that could be improved for clarity and maintainability.
Summary of Findings
- Conditional Compilation: The change in
mrbgems/mruby-cmath/src/cmath.cuses#if defined(__cplusplus)with additional conditions. It's worth ensuring that this doesn't introduce regressions on other platforms and that the added__EMSCRIPTEN__condition is indeed necessary and sufficient. - Linking Flags: The notes in
build_config/emscripten.rbandbuild_config/emscripten-cxx.rbabout linking flags are important. Consider adding a more automated way to ensure these flags are used, rather than relying solely on comments. - Toolchain Flags: The
compile_and_link_flagsvariable intasks/toolchains/emscripten.rakeis currently empty. It would be beneficial to add some default flags or provide guidance on what flags should typically be included.
Merge Readiness
The pull request is a valuable addition, but there are a few points that should be addressed before merging. Specifically, the conditional compilation in cmath.c should be carefully reviewed, and the linking flag instructions in the build configurations could be improved. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issue should be addressed before merging.
Adds support for Emscripten. Also related: #5453
Notes
1. tasks/toolchains/emscripten.rake
Because Emscripten includes a lot options that should be used for both Compile & Link, I have a
compile_and_link_flagsvar for convenience. This was really useful for me when testing and/or adding flags to improve code optimization, etc. I also provided doc links.2. build_config/emscripten.rb & emscripten-cxx.rb
Just linking
libmruby.agave me a bunch of issues. See emscripten/issues/23858. Using themruby-configflags fixed my issue. Therefore, I added a comment about this in both of these files to ensure people use these flags when linking mruby to their Emscripten app.3. mrbgems/mruby-cmath/src/cmath.c
This wouldn't compile in C++. I figured out it's because of this if-statement. I'm wondering why it isn't just
#if defined(__cplusplus)? Maybe some other system breaks with it, not sure.