From f0c5f3306fadc7dea7a13defd8b9cf20a6982493 Mon Sep 17 00:00:00 2001
From: Michal Klocek <michal.klocek@qt.io>
Date: Wed, 6 Dec 2017 16:08:12 +0100
Subject: [PATCH] Add 32bit host compiler test

The 32bit compiler is required for creating v8 snapshots.

Task-number: QTBUG-65004
Task-number: QTBUG-64869
Change-Id: I0a7a351208768f0b12900fac14d3abd5c8d99fa2
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
---
 config.tests/hostcompiler/hostcompiler.pro |  9 +++++++++
 config.tests/hostcompiler/main.cpp         |  6 ++++++
 configure.json                             | 20 ++++++++++++++++++--
 mkspecs/features/configure.prf             |  7 +++++++
 src/core/config/common.pri                 |  7 +++++++
 5 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 config.tests/hostcompiler/hostcompiler.pro
 create mode 100644 config.tests/hostcompiler/main.cpp

diff --git a/config.tests/hostcompiler/hostcompiler.pro b/config.tests/hostcompiler/hostcompiler.pro
new file mode 100644
index 000000000..5a80246ab
--- /dev/null
+++ b/config.tests/hostcompiler/hostcompiler.pro
@@ -0,0 +1,9 @@
+option(host_build)
+
+gcc:equals(QT_ARCH, "x86_64"):contains(QT_TARGET_ARCH, "arm"):!contains(QT_TARGET_ARCH, "arm64") {
+    QMAKE_CXXFLAGS += -m32
+    QMAKE_LFLAGS += -m32
+}
+
+SOURCES = main.cpp
+
diff --git a/config.tests/hostcompiler/main.cpp b/config.tests/hostcompiler/main.cpp
new file mode 100644
index 000000000..96444ae8b
--- /dev/null
+++ b/config.tests/hostcompiler/main.cpp
@@ -0,0 +1,6 @@
+#include <stdio.h>
+int main()
+{
+   printf("This works\n");
+   return 0;
+}
diff --git a/configure.json b/configure.json
index fecd83ed4..9c9285953 100644
--- a/configure.json
+++ b/configure.json
@@ -21,8 +21,8 @@
             "webengine-spellchecker": "boolean",
             "webengine-native-spellchecker": "boolean",
             "webengine-webrtc": "boolean",
-            "webengine-geolocation" : "boolean",
-
+            "webengine-geolocation": "boolean",
+            "webengine-v8-snapshot": "boolean",
             "alsa": { "type": "boolean", "name": "webengine-alsa" },
             "pulseaudio": { "type": "boolean", "name": "webengine-pulseaudio" },
             "ffmpeg": { "type": "enum", "name": "webengine-system-ffmpeg", "values": { "system": "yes", "qt": "no" } },
@@ -189,6 +189,11 @@
             "test": "alsa",
             "type": "compile"
         },
+        "webengine-host-compiler": {
+            "label": "host compiler",
+            "test": "hostcompiler",
+            "type": "compile"
+        },
         "webengine-khr": {
             "label": "khr",
             "test": "khr",
@@ -396,6 +401,16 @@
             "condition": "config.unix && tests.alsa",
             "output": [ "privateFeature" ]
         },
+        "webengine-v8-snapshot": {
+            "label" : "Use v8 snapshot",
+            "purpuse": "Enables the v8 snapshot, for fast v8 context creation",
+            "output": [ "privateFeature" ]
+        },
+        "webengine-v8-snapshot-support": {
+            "autoDetect": "features.webengine-v8-snapshot",
+            "condition": "!config.unix || !features.webengine-embedded-build || tests.webengine-host-compiler",
+            "output": [ "privateFeature" ]
+        },
         "webengine-system-khr" : {
             "label": "khr",
             "condition": "config.unix && tests.webengine-khr",
@@ -600,6 +615,7 @@
                 "webengine-webrtc",
                 "webengine-system-ninja",
                 "webengine-geolocation",
+                "webengine-v8-snapshot-support",
                 {
                     "type": "feature",
                     "args": "webengine-alsa",
diff --git a/mkspecs/features/configure.prf b/mkspecs/features/configure.prf
index 2c0908598..f8c154655 100644
--- a/mkspecs/features/configure.prf
+++ b/mkspecs/features/configure.prf
@@ -30,6 +30,13 @@ defineTest(runConfigure) {
     include($$QTWEBENGINE_OUT_ROOT/qtwebengine-config.pri)
     QT_FOR_CONFIG += webengine-private
 
+    !qtConfig(webengine-v8-snapshot-support):qtConfig(webengine-v8-snapshot) {
+        skipBuild("V8 snapshot cannot be built. Most likely, the 32-bit host compiler does not work."\
+                  "Please make sure you have 32-bit devel environment installed, or "\
+                  "configure webengine with '-no-webengine-v8-snapshot'")
+        return(false)
+    }
+
     !qtConfig(webengine-gperf) {
         skipBuild("Required gperf could not be found.")
         return(false)
diff --git a/src/core/config/common.pri b/src/core/config/common.pri
index 8961e1cd3..ab2a60978 100644
--- a/src/core/config/common.pri
+++ b/src/core/config/common.pri
@@ -84,3 +84,10 @@ optimize_size: gn_args += optimize_for_size=true
     # rtti, linking would fail at build time.
     sanitize_undefined: gn_args += is_ubsan=true use_rtti=true
 }
+
+qtConfig(webengine-v8-snapshot) {
+    gn_args += v8_use_snapshot=true
+} else {
+    gn_args += v8_use_snapshot=false
+}
+
-- 
GitLab