Skip to content

Commit 006f656

Browse files
committed
added support for closure compiler
Updated README and release notes Use closure compiler - changed code to use Module['xxx'] syntax as a result
1 parent 3695118 commit 006f656

File tree

13 files changed

+27
-23
lines changed

13 files changed

+27
-23
lines changed

.github/workflows/compute_size_manual.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
rm -rf build
3838
mkdir build
3939
emcc --version
40-
emcc -sUSE_GLFW=3 examples/example_minimal/main.cpp -O${{ matrix.optimizationLevel }} -o build/index.html
40+
emcc -sUSE_GLFW=3 examples/example_minimal/main.cpp --closure=1 -O${{ matrix.optimizationLevel }} -o build/index.html
4141
ls -l build
4242
js_size=$(stat --format="%s" build/index.js)
4343
wasm_size=$(stat --format="%s" build/index.wasm)
@@ -52,7 +52,7 @@ jobs:
5252
rm -rf build
5353
mkdir build
5454
emcc --version
55-
emcc --use-port=contrib.glfw3:optimizationLevel=${{ matrix.optimizationLevel }} examples/example_minimal/main.cpp -O${{ matrix.optimizationLevel }} -o build/index.html
55+
emcc --use-port=contrib.glfw3:optimizationLevel=${{ matrix.optimizationLevel }} examples/example_minimal/main.cpp --closure=1 -O${{ matrix.optimizationLevel }} -o build/index.html
5656
ls -l build
5757
js_size=$(stat --format="%s" build/index.js)
5858
wasm_size=$(stat --format="%s" build/index.wasm)
@@ -67,7 +67,7 @@ jobs:
6767
rm -rf build
6868
mkdir build
6969
emcc --version
70-
emcc --use-port=contrib.glfw3:disableWarning=true:disableMultiWindow=true:disableJoystick=true:disableWebGL2=true:optimizationLevel=${{ matrix.optimizationLevel }} examples/example_minimal/main.cpp -O${{ matrix.optimizationLevel }} -o build/index.html
70+
emcc --use-port=contrib.glfw3:disableWarning=true:disableMultiWindow=true:disableJoystick=true:disableWebGL2=true:optimizationLevel=${{ matrix.optimizationLevel }} examples/example_minimal/main.cpp --closure=1 -O${{ matrix.optimizationLevel }} -o build/index.html
7171
ls -l build
7272
js_size=$(stat --format="%s" build/index.js)
7373
wasm_size=$(stat --format="%s" build/index.wasm)

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
source ${{github.workspace}}/emscripten/emsdk_env.sh
6969
mkdir build-with-port
7070
emcc --version
71-
emcc --use-port=contrib.glfw3 examples/example_minimal/main.cpp -O2 -o build-with-port/index.html
71+
emcc --use-port=contrib.glfw3 examples/example_minimal/main.cpp --closure=1 -O2 -o build-with-port/index.html
7272
ls -l build-with-port
7373
7474
- name: Compile with port (small)
@@ -77,5 +77,5 @@ jobs:
7777
source ${{github.workspace}}/emscripten/emsdk_env.sh
7878
mkdir build-with-port-small
7979
emcc --version
80-
emcc --use-port=contrib.glfw3:disableWarning=true:disableMultiWindow=true:disableJoystick=true:disableWebGL2=true examples/example_minimal/main.cpp -O2 -o build-with-port-small/index.html
80+
emcc --use-port=contrib.glfw3:disableWarning=true:disableMultiWindow=true:disableJoystick=true:disableWebGL2=true examples/example_minimal/main.cpp --closure=1 -O2 -o build-with-port-small/index.html
8181
ls -l build-with-port-small

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
source ${{github.workspace}}/emscripten/emsdk_env.sh
4040
mkdir build-with-port
4141
emcc --version
42-
emcc --use-port=port/emscripten-glfw3.py examples/example_minimal/main.cpp -O2 -o build-with-port/index.html
42+
emcc --use-port=port/emscripten-glfw3.py examples/example_minimal/main.cpp --closure=1 -O2 -o build-with-port/index.html
4343
ls -l build-with-port
4444
4545
- name: Compile with released port (small)
@@ -48,5 +48,5 @@ jobs:
4848
source ${{github.workspace}}/emscripten/emsdk_env.sh
4949
mkdir build-with-port-small
5050
emcc --version
51-
emcc --use-port=port/emscripten-glfw3.py:disableWarning=true:disableMultiWindow=true:disableJoystick=true:disableWebGL2=true examples/example_minimal/main.cpp -O2 -o build-with-port-small/index.html
51+
emcc --use-port=port/emscripten-glfw3.py:disableWarning=true:disableMultiWindow=true:disableJoystick=true:disableWebGL2=true examples/example_minimal/main.cpp --closure=1 -O2 -o build-with-port-small/index.html
5252
ls -l build-with-port-small

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ macro(add_glfw_lib LIBRARY_NAME)
7777
$<$<BOOL:${EMSCRIPTEN_GLFW3_DISABLE_JOYSTICK}>:EMSCRIPTEN_GLFW3_DISABLE_JOYSTICK>
7878
$<$<BOOL:${EMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT}>:EMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT>
7979
)
80-
target_link_options(${LIBRARY_NAME} PUBLIC "-lGL" "--js-library" "${CMAKE_CURRENT_LIST_DIR}/src/js/lib_emscripten_glfw3.js")
80+
target_link_options(${LIBRARY_NAME} PUBLIC
81+
"-lGL"
82+
"--js-library" "${CMAKE_CURRENT_LIST_DIR}/src/js/lib_emscripten_glfw3.js"
83+
"$<$<CONFIG:Release>:--closure=1>"
84+
)
8185
endmacro()
8286

8387
# main library

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ Examples (part of this project)
111111
</tr>
112112
<tr>
113113
<td><a href="https://pongasoft.github.io/emscripten-glfw/examples/example_minimal/main.html">example_minimal</a> (<a href="examples/example_minimal">src</a>)</td>
114-
<td>The purpose of this example is to be as minimal as possible: initializes glfw, creates a window, then destroys it and terminates glfw.
114+
<td>The purpose of this example is to be as minimal as possible: initializes glfw, creates a window, then destroys it, and terminates glfw.
115115
Uses the default shell that comes with emscripten</td>
116116
</tr>
117117
<tr>
118118
<td><a href="https://pongasoft.github.io/emscripten-glfw/examples/example_resizable_container/main.html">example_resizable_container</a> (<a href="examples/example_resizable_container">src</a>)</td>
119119
<td>The purpose of this example is to demonstrate how to make the canvas resizable with another container (a
120120
surrounding div) driving its size. The container width is proportional to the size of the window and so as the
121-
window gets resized so does the div, and so does the canvas</td>
121+
window gets resized, so does the div, and so does the canvas</td>
122122
</tr>
123123
<tr>
124124
<td><a href="https://pongasoft.github.io/emscripten-glfw/examples/example_resizable_container_with_handle/main.html">example_resizable_container_with_handle</a> (<a href="examples/example_resizable_container_with_handle">src</a>)</td>

examples/example_asyncify/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void consoleErrorHandler(int iErrorCode, char const *iErrorMessage)
3333

3434
//! jsRenderFrame: for the sake of this example, uses the canvas2D api to change the color of the screen / display a message
3535
EM_JS(void, jsRenderFrame, (GLFWwindow *glfwWindow, int w, int h, int fw, int fh, double mx, double my, int color, bool isFullscreen), {
36-
const ctx = Module.glfwGetCanvas(glfwWindow).getContext('2d');
36+
const ctx = Module['glfwGetCanvas'](glfwWindow).getContext('2d');
3737
ctx.fillStyle = `rgb(${color}, ${color}, ${color})`;
3838
ctx.fillRect(0, 0, fw, fh); // using framebuffer width/height
3939
ctx.save();

examples/example_hi_dpi/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void consoleErrorHandler(int iErrorCode, char const *iErrorMessage)
4646

4747
//! jsRenderFrame: for the sake of this example, uses the canvas2D api to change the color of the screen / display a message
4848
EM_JS(void, jsRenderFrame, (GLFWwindow *glfwWindow, int w, int h, int sx, int sy, double mx, double my, int color, bool isFullscreen), {
49-
const ctx = Module.glfwGetCanvas(glfwWindow).getContext('2d');
49+
const ctx = Module['glfwGetCanvas'](glfwWindow).getContext('2d');
5050
ctx.save();
5151
ctx.scale(sx, sy);
5252
ctx.fillStyle = `rgb(${color}, ${color}, ${color})`;

examples/example_pthread/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void jsRenderFrame(GLFWwindow *glfwWindow, int w, int h, int fw, int fh, double
4747
{
4848
MAIN_THREAD_EM_ASM(
4949
{
50-
const ctx = Module.glfwGetCanvas($0).getContext('2d');
50+
const ctx = Module['glfwGetCanvas']($0).getContext('2d');
5151
const w = $1; const h = $2; const fw = $3; const fh = $4;
5252
const color = $7;
5353
const c1 = UTF8ToString($8); const c2 = UTF8ToString($9);

examples/example_resizable_container/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void consoleErrorHandler(int iErrorCode, char const *iErrorMessage)
3434

3535
//! jsRenderFrame: for the sake of this example, uses the canvas2D api to change the color of the screen / display a message
3636
EM_JS(void, jsRenderFrame, (GLFWwindow *glfwWindow, int w, int h, int fw, int fh, double mx, double my, int color, bool isFullscreen), {
37-
const ctx = Module.glfwGetCanvas(glfwWindow).getContext('2d');
37+
const ctx = Module['glfwGetCanvas'](glfwWindow).getContext('2d');
3838
ctx.fillStyle = `rgb(${color}, ${color}, ${color})`;
3939
ctx.fillRect(0, 0, fw, fh); // using framebuffer width/height
4040
const text = `${w}x${h} | ${mx}x${my} | CTRL+Q to terminate ${isFullscreen ? "" : '| CTRL+F for fullscreen'}`;

examples/example_resizable_container_with_handle/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void consoleErrorHandler(int iErrorCode, char const *iErrorMessage)
3434

3535
//! jsRenderFrame: for the sake of this example, uses the canvas2D api to change the color of the screen / display a message
3636
EM_JS(void, jsRenderFrame, (GLFWwindow *glfwWindow, int w, int h, int fw, int fh, double mx, double my, int color, bool isFullscreen), {
37-
const ctx = Module.glfwGetCanvas(glfwWindow).getContext('2d');
37+
const ctx = Module['glfwGetCanvas'](glfwWindow).getContext('2d');
3838
ctx.fillStyle = `rgb(${color}, ${color}, ${color})`; ctx.fillRect(0, 0, fw, fh); // using framebuffer width/height
3939
const text = `${w}x${h} | ${mx}x${my} | CTRL+Q to terminate ${isFullscreen ? "" : '| CTRL+F for fullscreen'}`;
4040
ctx.font = '15px monospace'; ctx.fillStyle = `rgb(${255 - color}, 0, 0)`; ctx.fillText(text, 10 + color, 20 + color);

examples/example_resizable_full_window/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void consoleErrorHandler(int iErrorCode, char const *iErrorMessage)
3232

3333
//! jsRenderFrame: for the sake of this example, uses the canvas2D api to change the color of the screen / display a message
3434
EM_JS(void, jsRenderFrame, (GLFWwindow *glfwWindow, int w, int h, int fw, int fh, double mx, double my, int color, bool isFullscreen), {
35-
const ctx = Module.glfwGetCanvas(glfwWindow).getContext('2d');
35+
const ctx = Module['glfwGetCanvas'](glfwWindow).getContext('2d');
3636
ctx.fillStyle = `rgb(${color}, ${color}, ${color})`;
3737
ctx.fillRect(0, 0, fw, fh); // using framebuffer width/height
3838
const text = `${w}x${h} | ${mx}x${my} | CTRL+Q to terminate ${isFullscreen ? "" : '| CTRL+F for fullscreen'}`;

test/demo/src/Triangle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,21 @@ void setHtmlValue(std::string_view iElementSelector, std::string_view iValue)
358358
//------------------------------------------------------------------------
359359
void hideHTMLElement(std::string_view iElementSelector)
360360
{
361-
EM_ASM({ Module.hideHTMLElement(UTF8ToString($0)); }, iElementSelector.data());
361+
EM_ASM({ Module['hideHTMLElement'](UTF8ToString($0)); }, iElementSelector.data());
362362
}
363363

364364
//------------------------------------------------------------------------
365365
// showHTMLElement
366366
//------------------------------------------------------------------------
367367
void showHTMLElement(std::string_view iElementSelector)
368368
{
369-
EM_ASM({ Module.showHTMLElement(UTF8ToString($0)); }, iElementSelector.data());
369+
EM_ASM({ Module['showHTMLElement'](UTF8ToString($0)); }, iElementSelector.data());
370370
}
371371

372372
//------------------------------------------------------------------------
373373
// getLMBAction
374374
//------------------------------------------------------------------------
375-
EM_JS(int, getLMBAction, (char const *iAction), { return Module.getLMBAction(UTF8ToString(iAction)); })
375+
EM_JS(int, getLMBAction, (char const *iAction), { return Module['getLMBAction'](UTF8ToString(iAction)); })
376376

377377
//------------------------------------------------------------------------
378378
// setHtmlValue

test/demo/src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ std::optional<Event> popEvent()
6767
int type{};
6868
GLFWwindow *w;
6969
EM_ASM({
70-
if(Module.hasEvents()) {
71-
const event = Module.popEvent();
70+
if(Module['hasEvents']()) {
71+
const event = Module['popEvent']();
7272
setValue($0, event.type, 'i32');
7373
setValue($1, event.canvas, '*');
7474
}
@@ -177,9 +177,9 @@ int main()
177177
setHtmlValue("#version", glfwGetVersionString());
178178
setHtmlValue("#action-key", emscripten::glfw3::IsRuntimePlatformApple() ? "&#x2318" : "CTRL");
179179

180-
auto canvas1Enabled = static_cast<bool>(EM_ASM_INT( return Module.canvas1Enabled; ));
180+
auto canvas1Enabled = static_cast<bool>(EM_ASM_INT( return Module['canvas1Enabled']; ));
181181
#ifndef EMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT
182-
auto canvas2Enabled = static_cast<bool>(EM_ASM_INT( return Module.canvas2Enabled; ));
182+
auto canvas2Enabled = static_cast<bool>(EM_ASM_INT( return Module['canvas2Enabled']; ));
183183
#else
184184
auto canvas2Enabled = false;
185185
#endif

0 commit comments

Comments
 (0)