Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit af59345

Browse files
committed
Patches for wasm build.
1 parent eb6cc8c commit af59345

File tree

3 files changed

+298
-1
lines changed

3 files changed

+298
-1
lines changed

scripts/prepare_dev.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
('0014-Fix-missing-ffmpeg-configure-item-for-msvc-build.patch', FFMPEG_PATH),
4646
('0015-Remove-custom-d8-dependency.patch', BUILD_PATH),
4747
('0016-Remove-deprecated-create_srcjar-property.patch', THIRD_PARTY_PATH),
48-
('0017-Build-libvpx-with-RTC-rate-control-impl-included.patch', THIRD_PARTY_PATH)
48+
('0017-Build-libvpx-with-RTC-rate-control-impl-included.patch', THIRD_PARTY_PATH),
49+
('0018-Update-GN-files-for-wasm.patch', THIRD_PARTY_PATH),
50+
('0019-Update-GN-files-for-wasm-build.patch', BUILD_PATH)
4951
]
5052

5153
def _patch(ignoreFailures=False):
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
From 5f0e3a41d44c4a5e200cb236d284ce1472f423ed Mon Sep 17 00:00:00 2001
2+
From: Jianjun Zhu <[email protected]>
3+
Date: Wed, 16 Feb 2022 13:54:38 +0800
4+
Subject: [PATCH] Update GN files for wasm.
5+
6+
---
7+
googletest/BUILD.gn | 6 +++++-
8+
libxml/BUILD.gn | 2 ++
9+
pffft/BUILD.gn | 6 +++++-
10+
3 files changed, 12 insertions(+), 2 deletions(-)
11+
12+
diff --git a/googletest/BUILD.gn b/googletest/BUILD.gn
13+
index e9b39c2968a..5bcc23e044d 100644
14+
--- a/googletest/BUILD.gn
15+
+++ b/googletest/BUILD.gn
16+
@@ -5,7 +5,11 @@
17+
import("//build_overrides/build.gni")
18+
19+
config("gtest_config") {
20+
- visibility = [ ":*" ] # gmock also shares this config.
21+
+ visibility = [
22+
+ ":*",
23+
+ "//testing/gmock:gmock",
24+
+ "//third_party/webrtc/test:test_support",
25+
+ ] # gmock also shares this config.
26+
27+
defines = [
28+
# Chromium always links googletest statically, so no API qualifier is
29+
diff --git a/libxml/BUILD.gn b/libxml/BUILD.gn
30+
index 8068e573cbd..f2dc8b46c3e 100644
31+
--- a/libxml/BUILD.gn
32+
+++ b/libxml/BUILD.gn
33+
@@ -10,6 +10,8 @@ if (is_linux || is_chromeos || is_android || is_nacl || is_fuchsia) {
34+
os_include = "mac"
35+
} else if (is_win) {
36+
os_include = "win32"
37+
+} else if (is_wasm) {
38+
+ os_include = "wasm"
39+
}
40+
41+
import("//third_party/libxml/libxml_visibility.gni")
42+
diff --git a/pffft/BUILD.gn b/pffft/BUILD.gn
43+
index 7d6c537f4f4..5a1278b03ac 100644
44+
--- a/pffft/BUILD.gn
45+
+++ b/pffft/BUILD.gn
46+
@@ -17,9 +17,13 @@ config("common_config") {
47+
# PFFFT doesn't support SIMD on some cpus, so build a scalar version.
48+
if ((current_cpu == "arm" && !arm_use_neon) || current_cpu == "mipsel" ||
49+
current_cpu == "mips64el" || current_cpu == "ppc64" ||
50+
- current_cpu == "s390x") {
51+
+ current_cpu == "s390x" || current_os == "wasm") {
52+
defines = [ "PFFFT_SIMD_DISABLE" ]
53+
}
54+
+
55+
+ if (current_os=="wasm") {
56+
+ defines += [ "M_PI=3.14159265358979323846" ]
57+
+ }
58+
}
59+
60+
static_library("pffft") {
61+
--
62+
2.35.1
63+
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
From 5eb6afab0d6db092f898515938840c120fd85561 Mon Sep 17 00:00:00 2001
2+
From: Jianjun Zhu <[email protected]>
3+
Date: Fri, 4 Mar 2022 15:54:39 +0800
4+
Subject: [PATCH] Update GN files for wasm build.
5+
6+
---
7+
config/BUILDCONFIG.gn | 7 +++++--
8+
config/compiler/BUILD.gn | 39 ++++++++++++++++++++++++++++++++-------
9+
config/linux/BUILD.gn | 1 +
10+
config/posix/BUILD.gn | 2 +-
11+
toolchain/toolchain.gni | 3 +++
12+
toolchain/wasm/BUILD.gn | 30 ++++++++++++++++++++++++++++++
13+
6 files changed, 72 insertions(+), 10 deletions(-)
14+
create mode 100644 toolchain/wasm/BUILD.gn
15+
16+
diff --git a/config/BUILDCONFIG.gn b/config/BUILDCONFIG.gn
17+
index ca9614a4b..ac9a56b24 100644
18+
--- a/config/BUILDCONFIG.gn
19+
+++ b/config/BUILDCONFIG.gn
20+
@@ -251,6 +251,8 @@ if (target_os == "android") {
21+
_default_toolchain = "//build/toolchain/win:uwp_$target_cpu"
22+
} else if (target_os == "aix") {
23+
_default_toolchain = "//build/toolchain/aix:$target_cpu"
24+
+} else if (target_os == "wasm") {
25+
+ _default_toolchain = "//talk/owt/sdk/wasm/gn:wasm"
26+
} else {
27+
assert(false, "Unsupported target_os: $target_os")
28+
}
29+
@@ -288,10 +290,11 @@ is_ios = current_os == "ios"
30+
is_linux = current_os == "linux"
31+
is_mac = current_os == "mac"
32+
is_nacl = current_os == "nacl"
33+
+is_wasm = current_os == "wasm"
34+
is_win = current_os == "win" || current_os == "winuwp"
35+
36+
is_apple = is_ios || is_mac
37+
-is_posix = !is_win && !is_fuchsia
38+
+is_posix = !is_win && !is_fuchsia && !is_wasm
39+
40+
# =============================================================================
41+
# TARGET DEFAULTS
42+
@@ -363,7 +366,7 @@ if (is_android) {
43+
[ "//build/config/android:default_orderfile_instrumentation" ]
44+
}
45+
46+
-if (is_clang && !is_nacl) {
47+
+if (is_clang && !is_nacl && !is_wasm) {
48+
default_compiler_configs += [
49+
"//build/config/clang:find_bad_constructs",
50+
"//build/config/clang:extra_warnings",
51+
diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
52+
index 48deb0b48..77563447c 100644
53+
--- a/config/compiler/BUILD.gn
54+
+++ b/config/compiler/BUILD.gn
55+
@@ -70,7 +70,7 @@ declare_args() {
56+
# Build with C++ RTTI enabled. Chromium builds without RTTI by default,
57+
# but some sanitizers are known to require it, like CFI diagnostics
58+
# and UBsan variants.
59+
- use_rtti = use_cfi_diag || is_ubsan_vptr || is_ubsan_security
60+
+ use_rtti = use_cfi_diag || is_ubsan_vptr || is_ubsan_security || is_wasm
61+
62+
# AFDO (Automatic Feedback Directed Optimizer) is a form of profile-guided
63+
# optimization that GCC supports. It used by ChromeOS in their official
64+
@@ -602,6 +602,18 @@ config("compiler") {
65+
ldflags += [ "-stdlib=libc++" ]
66+
}
67+
68+
+ if (is_wasm) {
69+
+ _emscripten_flags = [
70+
+ ]
71+
+
72+
+ # TODO(agrieve): Figure out why this causes link to fail.
73+
+ #if (is_official_build) {
74+
+ # _emscripten_flags += ["-flto=full"]
75+
+ #}
76+
+ cflags += _emscripten_flags
77+
+ ldflags += _emscripten_flags
78+
+ }
79+
+
80+
# Add flags for link-time optimization. These flags enable
81+
# optimizations/transformations that require whole-program visibility at link
82+
# time, so they need to be applied to all translation units, and we may end up
83+
@@ -723,10 +735,10 @@ config("compiler") {
84+
# present. On Android this increases binary size due to more thinks for long
85+
# jumps. Turn it off by default and enable selectively for targets where it's
86+
# beneficial.
87+
- if (use_lld && !enable_call_graph_profile_sort) {
88+
+ if (use_lld && !enable_call_graph_profile_sort && !is_wasm) {
89+
if (is_win) {
90+
ldflags += [ "/call-graph-profile-sort:no" ]
91+
- } else if (!is_apple) {
92+
+ } else if (!is_apple || !is_wasm) {
93+
# TODO(thakis): Once LLD's Mach-O port basically works, implement call
94+
# graph profile sorting for it, add an opt-out flag, and pass it here.
95+
ldflags += [ "-Wl,--no-call-graph-profile-sort" ]
96+
@@ -826,11 +838,11 @@ config("compiler_cpu_abi") {
97+
# simplicity we always explicitly set the architecture.
98+
if (current_cpu == "x64") {
99+
cflags += [
100+
- "-m64",
101+
+ #"-m64",
102+
"-march=$x64_arch",
103+
"-msse3",
104+
]
105+
- ldflags += [ "-m64" ]
106+
+ #ldflags += [ "-m64" ]
107+
} else if (current_cpu == "x86") {
108+
cflags += [ "-m32" ]
109+
ldflags += [ "-m32" ]
110+
@@ -1301,7 +1313,7 @@ config("runtime_library") {
111+
112+
# TODO(crbug.com/830987): Come up with a better name for is POSIX + Fuchsia
113+
# configuration.
114+
- if (is_posix || is_fuchsia) {
115+
+ if (is_posix || is_fuchsia || is_wasm) {
116+
configs += [ "//build/config/posix:runtime_library" ]
117+
}
118+
119+
@@ -1594,7 +1606,8 @@ config("default_warnings") {
120+
cflags += [ "-Wno-nonportable-include-path" ]
121+
}
122+
123+
- if (current_toolchain == host_toolchain || !use_xcode_clang) {
124+
+ if ((current_toolchain == host_toolchain || !use_xcode_clang) &&
125+
+ !is_wasm) {
126+
# Flags NaCl (Clang 3.7) and Xcode 9.2 (Clang clang-900.0.39.2) do not
127+
# recognize.
128+
cflags += [
129+
@@ -1637,6 +1650,15 @@ config("default_warnings") {
130+
}
131+
}
132+
}
133+
+
134+
+ if (is_wasm) {
135+
+ cflags_c += [
136+
+ # TODO(https://crbug.com/995993): Clean up and enable.
137+
+ "-Wno-implicit-fallthrough",
138+
+ "-pthread",
139+
+ "-Wno-pthreads-mem-growth"
140+
+ ]
141+
+ }
142+
}
143+
144+
# chromium_code ---------------------------------------------------------------
145+
@@ -2360,6 +2382,9 @@ config("symbols") {
146+
"-debug-info-kind=constructor",
147+
]
148+
}
149+
+ } else if (is_wasm) {
150+
+ cflags = [ "-gsource-map" ]
151+
+ ldflags = [ "-gsource-map" ]
152+
} else {
153+
cflags = []
154+
if (is_mac && enable_dsyms) {
155+
diff --git a/config/linux/BUILD.gn b/config/linux/BUILD.gn
156+
index 64b632538..5ec75834f 100644
157+
--- a/config/linux/BUILD.gn
158+
+++ b/config/linux/BUILD.gn
159+
@@ -33,6 +33,7 @@ config("runtime_library") {
160+
if ((!(is_chromeos_ash || is_chromeos_lacros) ||
161+
default_toolchain != "//build/toolchain/cros:target") &&
162+
(!use_custom_libcxx || current_cpu == "mipsel")) {
163+
+ print("link atomic")
164+
libs = [ "atomic" ]
165+
}
166+
}
167+
diff --git a/config/posix/BUILD.gn b/config/posix/BUILD.gn
168+
index e61554c56..a8d3979f0 100644
169+
--- a/config/posix/BUILD.gn
170+
+++ b/config/posix/BUILD.gn
171+
@@ -5,7 +5,7 @@
172+
import("//build/config/sysroot.gni")
173+
174+
# This build configuration is used by both Fuchsia and POSIX systems.
175+
-assert(is_posix || is_fuchsia)
176+
+assert(is_posix || is_fuchsia || is_wasm)
177+
178+
group("posix") {
179+
visibility = [ "//:optimize_gn_gen" ]
180+
diff --git a/toolchain/toolchain.gni b/toolchain/toolchain.gni
181+
index 95febfe6b..d44e4679b 100644
182+
--- a/toolchain/toolchain.gni
183+
+++ b/toolchain/toolchain.gni
184+
@@ -64,6 +64,9 @@ if (is_apple) {
185+
shlib_extension = ".so"
186+
} else if (is_win) {
187+
shlib_extension = ".dll"
188+
+} else if (is_wasm) {
189+
+ # WebAssembly does not stably support shared libraries. (as of Oct 2019)
190+
+ shlib_extension = ".wasm"
191+
} else {
192+
assert(false, "Platform not supported")
193+
}
194+
diff --git a/toolchain/wasm/BUILD.gn b/toolchain/wasm/BUILD.gn
195+
new file mode 100644
196+
index 000000000..fdc512098
197+
--- /dev/null
198+
+++ b/toolchain/wasm/BUILD.gn
199+
@@ -0,0 +1,30 @@
200+
+# Copyright 2019 The Chromium Authors. All rights reserved.
201+
+# Use of this source code is governed by a BSD-style license that can be
202+
+# found in the LICENSE file.
203+
+
204+
+import("//build/toolchain/gcc_toolchain.gni")
205+
+
206+
+gcc_toolchain("wasm") {
207+
+ cc = "emcc"
208+
+ cxx = "em++"
209+
+ nm = "emcc"
210+
+ ar = "emar"
211+
+ ld = cxx
212+
+
213+
+ toolchain_args = {
214+
+ current_cpu = "wasm"
215+
+ current_os = "wasm"
216+
+
217+
+ is_clang = true
218+
+ use_goma = false
219+
+ use_debug_fission = false
220+
+ clang_use_chrome_plugins = false
221+
+ use_allocator_shim = false
222+
+ is_component_build = false
223+
+ }
224+
+ executable_extension = ".js"
225+
+ link_outputs = [
226+
+ "{{output_dir}}/{{target_output_name}}.wasm",
227+
+ "{{output_dir}}/{{target_output_name}}.wasm.map",
228+
+ ]
229+
+}
230+
--
231+
2.35.1
232+

0 commit comments

Comments
 (0)