Skip to content

Commit

Permalink
wasm: Add WASM_OBJECT_FILES=1 build mode
Browse files Browse the repository at this point in the history
This mode significantly improves build (link) time.
Opt-in by passing “-device-option WASM_OBJECT_FILES=1”
to configure.

This requires a custom emsdk build which uses upstream
llvm.

Task-number: QTBUG-72537
Change-Id: I47bab2b58ae7e49ca104233ec14fff7b93516d36
Reviewed-by: Lorn Potter <[email protected]>
  • Loading branch information
Morten Johan Sørvig committed Mar 6, 2019
1 parent f792fed commit 9ab2579
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
2 changes: 2 additions & 0 deletions configure.pri
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ defineTest(qtConfTest_architecture) {
content = $$cat($$test_out_dir/libarch.so, blob)
else: wasm:exists($$test_out_dir/arch.wasm): \
content = $$cat($$test_out_dir/arch.wasm, blob)
else: wasm:exists($$test_out_dir/arch.o): \
content = $$cat($$test_out_dir/arch.o, blob)
else: \
error("$$eval($${1}.label) detection binary not found.")

Expand Down
63 changes: 45 additions & 18 deletions mkspecs/wasm-emscripten/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ QMAKE_PLATFORM = wasm unix
include(../common/gcc-base.conf)
include(../common/clang.conf)

load(device_config)

# Support setting WASM_OBJECT_FILES with -device-option WASM_OBJECT_FILES=1
!isEmpty(WASM_OBJECT_FILES): {
!equals(WASM_OBJECT_FILES, 1):!equals(WASM_OBJECT_FILES, 0): \
message(Error: The value for WASM_OBJECT_FILES must be 0 or 1)
QMAKE_CFLAGS += -s WASM_OBJECT_FILES=$$WASM_OBJECT_FILES
QMAKE_CXXFLAGS += -s WASM_OBJECT_FILES=$$WASM_OBJECT_FILES
QMAKE_LFLAGS += -s WASM_OBJECT_FILES=$$WASM_OBJECT_FILES
}

EMTERP_FLAGS = \
-s EMTERPRETIFY=1 \
-s EMTERPRETIFY_ASYNC=1 \
Expand All @@ -22,10 +33,14 @@ EMCC_COMMON_LFLAGS = \
-s \"BINARYEN_TRAP_MODE=\'clamp\'\"

EMCC_USE_PORTS_FLAGS = \
-s USE_LIBPNG=1 \
-s USE_FREETYPE=1 \
-s USE_ZLIB=1

# libpng does not build for WASM_OBJECT_FILES=1, see
# https://github.com/emscripten-core/emscripten/issues/8143
equals(WASM_OBJECT_FILES, 0):\
EMCC_USE_PORTS_FLAGS += -s USE_LIBPNG=1

# The -s arguments can also be used with release builds,
# but are here in debug for clarity.
EMCC_COMMON_LFLAGS_DEBUG = \
Expand All @@ -38,6 +53,35 @@ EMCC_COMMON_LFLAGS_DEBUG = \
# -s SOCKET_DEBUG \ #print out socket,network data transfer
-s GL_DEBUG=1

# Set up debug/optimization flags
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE -= -O2
equals(WASM_OBJECT_FILES, 1) {
QMAKE_LFLAGS_DEBUG += -g

QMAKE_CXXFLAGS_RELEASE += -O3
QMAKE_CFLAGS_RELEASE += -O3
QMAKE_LFLAGS_RELEASE += -O3
QMAKE_CFLAGS_OPTIMIZE += -O3
QMAKE_CFLAGS_OPTIMIZE_FULL += -Oz
} else {
# Practical debugging setup:
# "-g4" preserves function names for stack traces
# "-Os" produces reasonably sized binaries
QMAKE_CFLAGS_DEBUG -= -g
QMAKE_CXXFLAGS_DEBUG -= -g
QMAKE_CFLAGS_DEBUG += -Os -g4
QMAKE_CXXFLAGS_DEBUG += -Os -g4
QMAKE_LFLAGS_DEBUG += -Os -g4

QMAKE_CXXFLAGS_RELEASE += -O3
QMAKE_CFLAGS_RELEASE += -O3
QMAKE_LFLAGS_RELEASE += -O3
QMAKE_CFLAGS_OPTIMIZE += -O3
QMAKE_CFLAGS_OPTIMIZE_FULL += -Oz
}


QMAKE_COMPILER += emscripten

QMAKE_CC = emcc
Expand All @@ -46,23 +90,6 @@ QMAKE_CXX = em++
QMAKE_CFLAGS += $$EMCC_USE_PORTS_FLAGS
QMAKE_CXXFLAGS += $$EMCC_USE_PORTS_FLAGS

# Practical debugging setup:
# "-g4" preserves function names for stack traces
# "-Os" produces reasonably sized binaries
QMAKE_CFLAGS_DEBUG -= -g
QMAKE_CXXFLAGS_DEBUG -= -g
QMAKE_CFLAGS_DEBUG += -Os -g4
QMAKE_CXXFLAGS_DEBUG += -Os -g4
QMAKE_LFLAGS_DEBUG += -Os -g4

QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE += -O3
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -O3
QMAKE_LFLAGS_RELEASE += -O3
QMAKE_CFLAGS_OPTIMIZE += -O3
QMAKE_CFLAGS_OPTIMIZE_FULL += -Oz

QMAKE_LINK = $$QMAKE_CXX
QMAKE_LINK_SHLIB = $$QMAKE_CXX
QMAKE_LINK_C = $$QMAKE_CC
Expand Down

0 comments on commit 9ab2579

Please sign in to comment.