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

Commit a977465

Browse files
committed
Add support for WebAssembly build.
1 parent 56a0f54 commit a977465

File tree

8 files changed

+585
-0
lines changed

8 files changed

+585
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Open WebRTC Toolkit Native SDK
22

3+
## About this branch
4+
This branch is working on enabling WebAssembly build. Some WebRTC modules could be used for WebTransport and WebCodecs based streaming.
5+
36
## Introduction
47
The Open WebRTC Toolkit(OWT) client SDK for native Windows/Linux/Android/iOS applications is built upon the W3C WebRTC standard to accelerate the development
58
of real time communication applications on these platforms. It supports peer to peer communication, and conference mode communication working with

talk/owt/BUILD.gn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import("//build_overrides/webrtc.gni")
6+
import("//talk/owt/sdk/wasm/gn/wasm.gni")
67
import("//testing/test.gni")
78

89
# Introduced for using libvpx config files. We only enable libvpx rate
@@ -332,6 +333,15 @@ static_library("owt_sdk_p2p") {
332333
configs -= [ "//build/config/clang:find_bad_constructs" ]
333334
}
334335
}
336+
337+
wasm_lib("owt_wasm") {
338+
name = "owt"
339+
deps = [ "//third_party/webrtc/modules/rtp_rtcp" ]
340+
sources=[
341+
"sdk/wasm/main.cc",
342+
]
343+
}
344+
335345
static_library("owt_sdk_conf") {
336346
deps = [
337347
":owt_sdk_base",

talk/owt/sdk/wasm/gn/BUILD.gn

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Copyright (C) <2021> Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Copyright (C) 2018 The Android Open Source Project
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
# This file is copied from third_party/perfetto/gn/standalone/toolchain/BUILD.gn with modifications.
20+
21+
import("//build/config/compiler/compiler.gni")
22+
import("wasm.gni")
23+
24+
template("gcc_like_toolchain") {
25+
toolchain(target_name) {
26+
ar = invoker.ar
27+
cc = invoker.cc
28+
cxx = invoker.cxx
29+
lib_switch = "-l"
30+
lib_dir_switch = "-L"
31+
ld_arg = ""
32+
external_cflags = ""
33+
external_cxxflags = ""
34+
external_ldflags = ""
35+
strip = ""
36+
if (defined(invoker.linker) && invoker.linker != "") {
37+
_invoker_linker = invoker.linker
38+
ld_arg = "-fuse-ld=$_invoker_linker"
39+
}
40+
if (defined(invoker.sysroot) && invoker.sysroot != "") {
41+
_invoker_sysroot = invoker.sysroot
42+
cc = "$cc --sysroot=$_invoker_sysroot"
43+
cxx = "$cxx --sysroot=$_invoker_sysroot"
44+
}
45+
if (defined(invoker.gcc_toolchain) && invoker.gcc_toolchain != "") {
46+
assert(is_clang, "gcc_toolchain can be used only when using clang")
47+
_invoker_gcc_toolchain = invoker.gcc_toolchain
48+
ld_arg = "$ld_arg --gcc-toolchain=$_invoker_gcc_toolchain"
49+
}
50+
if (defined(invoker.external_cflags)) {
51+
external_cflags = invoker.external_cflags
52+
}
53+
if (defined(invoker.external_cxxflags)) {
54+
external_cxxflags = invoker.external_cxxflags
55+
}
56+
if (defined(invoker.external_ldflags)) {
57+
external_ldflags = invoker.external_ldflags
58+
}
59+
if (defined(invoker.strip)) {
60+
strip = invoker.strip
61+
}
62+
63+
# Object files go in this directory.
64+
object_subdir = "{{target_out_dir}}/{{label_name}}"
65+
66+
tool("cc") {
67+
depfile = "{{output}}.d"
68+
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -fno-stack-protector ${external_cflags} -msimd128 -pthread -D__wasm__ -c {{source}} -o {{output}}"
69+
depsformat = "gcc"
70+
outputs = [ "$object_subdir/{{source_name_part}}.o" ]
71+
description = "compile {{source}}"
72+
}
73+
74+
tool("cxx") {
75+
depfile = "{{output}}.d"
76+
command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -fno-stack-protector ${external_cflags} -msimd128 -pthread -D__wasm__ ${external_cxxflags} -c {{source}} -o {{output}}"
77+
depsformat = "gcc"
78+
outputs = [ "$object_subdir/{{source_name_part}}.o" ]
79+
description = "compile {{source}}"
80+
}
81+
82+
tool("asm") {
83+
depfile = "{{output}}.d"
84+
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -fno-stack-protector -c {{source}} -o {{output}}"
85+
depsformat = "gcc"
86+
outputs = [ "$object_subdir/{{source_name_part}}.o" ]
87+
description = "assemble {{source}}"
88+
}
89+
90+
tool("alink") {
91+
if (current_os == "aix") {
92+
# AIX does not support either -D (deterministic output) or response
93+
# files.
94+
command = "$ar -X64 {{arflags}} -r -c -s {{output}} {{inputs}}"
95+
} else {
96+
rspfile = "{{output}}.rsp"
97+
rspfile_content = "{{inputs}}"
98+
command = "$ar {{arflags}} -r -c -s -D {{output}} @\"$rspfile\""
99+
}
100+
101+
# Remove the output file first so that ar doesn't try to modify the
102+
# existing file.
103+
if (host_os == "win") {
104+
tool_wrapper_path =
105+
rebase_path("//build/toolchain/win/tool_wrapper.py", root_build_dir)
106+
command = "cmd /c $python_path $tool_wrapper_path delete-file {{output}} && $command"
107+
} else {
108+
command = "rm -f {{output}} && $command"
109+
}
110+
111+
# Almost all targets build with //build/config/compiler:thin_archive which
112+
# adds -T to arflags.
113+
description = "AR {{output}}"
114+
outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ]
115+
116+
# Shared libraries go in the target out directory by default so we can
117+
# generate different targets with the same name and not have them collide.
118+
default_output_dir = "{{target_out_dir}}"
119+
default_output_extension = ".a"
120+
output_prefix = "lib"
121+
}
122+
123+
tool("solink") {
124+
soname = "{{target_output_name}}{{output_extension}}"
125+
unstripped_so = "{{root_out_dir}}/$soname"
126+
rpath = "-Wl,-soname,$soname"
127+
if (is_mac) {
128+
rpath = "-Wl,-install_name,@rpath/$soname"
129+
}
130+
command = "$cc_wrapper $cxx $ld_arg -shared ${external_ldflags} -fstack-protector {{inputs}} {{solibs}} {{libs}} $rpath -o $unstripped_so"
131+
outputs = [ unstripped_so ]
132+
output_prefix = "lib"
133+
default_output_extension = ".so"
134+
description = "link $unstripped_so"
135+
if (strip != "") {
136+
stripped_so = "{{root_out_dir}}/stripped/$soname"
137+
outputs += [ stripped_so ]
138+
command += " && $strip -o $stripped_so $unstripped_so"
139+
}
140+
}
141+
142+
tool("link") {
143+
unstripped_exe =
144+
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
145+
command = "$cc_wrapper $cxx $ld_arg ${external_ldflags} {{inputs}} {{solibs}} {{libs}} -o $unstripped_exe"
146+
outputs = [ unstripped_exe ]
147+
description = "link $unstripped_exe"
148+
if (strip != "") {
149+
stripped_exe = "{{root_out_dir}}/stripped/{{target_output_name}}{{output_extension}}"
150+
outputs += [ stripped_exe ]
151+
command += " && $strip -o $stripped_exe $unstripped_exe"
152+
}
153+
}
154+
155+
tool("stamp") {
156+
command = "touch {{output}}"
157+
description = "stamp {{output}}"
158+
}
159+
160+
tool("copy") {
161+
command = "cp -af {{source}} {{output}}"
162+
description = "COPY {{source}} {{output}}"
163+
}
164+
165+
toolchain_args = {
166+
current_cpu = invoker.cpu
167+
current_os = invoker.os
168+
}
169+
}
170+
}
171+
172+
gcc_like_toolchain("wasm") {
173+
# emsdk_dir and em_config are defined in wasm.gni.
174+
cpu = host_cpu
175+
os = host_os
176+
ar = "emar --em-config $em_config"
177+
cc = "emcc --em-config $em_config"
178+
cxx = "em++ --em-config $em_config"
179+
strip = ""
180+
}

talk/owt/sdk/wasm/gn/BUILDCONFIG.gn

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Copyright (C) 2017 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
declare_args() {
16+
is_debug = true
17+
is_clang = true
18+
is_system_compiler = false
19+
is_lto = false
20+
21+
# This is defined here because it's needed below for determining the value of
22+
# |is_cross_compiling|.
23+
target_triplet = ""
24+
}
25+
26+
# Platform detection
27+
if (target_os == "") {
28+
target_os = host_os
29+
}
30+
if (current_os == "") {
31+
current_os = target_os
32+
}
33+
34+
is_android = current_os == "android"
35+
is_chromeos = current_os == "chromeos"
36+
is_linux = current_os == "linux"
37+
is_linux_host = host_os == "linux"
38+
is_mac = current_os == "mac"
39+
is_mac_host = host_os == "mac"
40+
is_win = current_os == "win"
41+
is_win_host = host_os == "win"
42+
43+
# Building with Windows/Fuchsia/nacl is currently only supported in the Chromium
44+
# tree so always set this to false.
45+
is_fuchsia = false
46+
is_nacl = false
47+
48+
if (target_cpu == "") {
49+
target_cpu = host_cpu
50+
if (is_android) {
51+
target_cpu = "arm"
52+
}
53+
}
54+
if (current_cpu == "") {
55+
current_cpu = target_cpu
56+
}
57+
58+
declare_args() {
59+
# the ossfuzz sanitizer overrides this to true. In that config the
60+
# host/target cpu and arch are identical, but we want to build only the
61+
# targets with the sanitizer/fuzzer flags
62+
is_cross_compiling =
63+
target_cpu != host_cpu || target_os != host_os || target_triplet != ""
64+
}
65+
default_configs = [
66+
"//gn/standalone:debug_symbols",
67+
"//gn/standalone:default",
68+
"//gn/standalone:c++11",
69+
"//gn/standalone:extra_warnings",
70+
"//gn/standalone:no_exceptions",
71+
"//gn/standalone:no_rtti",
72+
"//gn/standalone:visibility_hidden",
73+
"//gn/standalone/libc++:config",
74+
"//gn/standalone/sanitizers:sanitizers_cflags",
75+
]
76+
77+
if (is_win) {
78+
default_configs += [ "//gn/standalone:win32_lean_and_mean" ]
79+
}
80+
81+
if (!is_debug) {
82+
default_configs -= [ "//gn/standalone:debug_symbols" ]
83+
default_configs += [ "//gn/standalone:release" ]
84+
}
85+
86+
set_defaults("source_set") {
87+
configs = default_configs
88+
}
89+
90+
set_defaults("static_library") {
91+
configs = default_configs
92+
}
93+
94+
# Realistically the only shared_library that we build right now is libc++.so
95+
# when use_custom_libcxx=true (on Linux). Hence don't add a dependency on
96+
# libc++ itself on these targets.
97+
set_defaults("shared_library") {
98+
configs = default_configs
99+
configs += [ "//gn/standalone:shared_library" ]
100+
101+
# note: the following is not a nested config to be removable.
102+
configs += [ "//gn/standalone:android_liblog" ]
103+
}
104+
105+
set_defaults("executable") {
106+
configs = default_configs
107+
configs += [ "//gn/standalone:executable" ]
108+
109+
# note: the following is not a nested config to be removable.
110+
configs += [ "//gn/standalone:android_liblog" ]
111+
}
112+
113+
if (is_win) {
114+
_default_toolchain = "//gn/standalone/toolchain:msvc"
115+
} else {
116+
_default_toolchain = "//gn/standalone/toolchain:gcc_like"
117+
}
118+
set_default_toolchain(_default_toolchain)
119+
120+
if (is_cross_compiling) {
121+
host_toolchain = "//gn/standalone/toolchain:gcc_like_host"
122+
} else {
123+
host_toolchain = _default_toolchain
124+
}

0 commit comments

Comments
 (0)