Skip to content

Commit ed5f7c9

Browse files
authored
Add support for Emscripten (#1383)
1 parent 7be022f commit ed5f7c9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

foreign_cc/private/cmake_script.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ _TARGET_OS_PARAMS = {
2323
"ANDROID": "YES",
2424
"CMAKE_SYSTEM_NAME": "Linux",
2525
},
26+
"emscripten": {
27+
"CMAKE_SYSTEM_NAME": "Emscripten",
28+
},
2629
"linux": {
2730
"CMAKE_SYSTEM_NAME": "Linux",
2831
},
@@ -38,6 +41,14 @@ _TARGET_ARCH_PARAMS = {
3841
"s390x": {
3942
"CMAKE_SYSTEM_PROCESSOR": "s390x",
4043
},
44+
# Emscripten configures CMAKE_SYSTEM_PROCESSOR as follows for compatibility with libraries such as OpenCV
45+
# https://github.com/emscripten-core/emscripten/blob/79ee3d1/cmake/Modules/Platform/Emscripten.cmake#L23-L30
46+
"wasm32": {
47+
"CMAKE_SYSTEM_PROCESSOR": "x86",
48+
},
49+
"wasm64": {
50+
"CMAKE_SYSTEM_PROCESSOR": "x86_64",
51+
},
4152
"x86_64": {
4253
"CMAKE_SYSTEM_PROCESSOR": "x86_64",
4354
},

foreign_cc/private/framework/platform.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ SUPPORTED_CPU = [
44
"aarch64",
55
"ppc64le",
66
"s390x",
7+
"wasm32",
8+
"wasm64",
79
"x86_64",
810
]
911

1012
SUPPORTED_OS = [
1113
"android",
14+
"emscripten",
1215
"freebsd",
1316
"ios",
1417
"linux",
@@ -17,6 +20,7 @@ SUPPORTED_OS = [
1720
"openbsd",
1821
"qnx",
1922
"tvos",
23+
"wasi",
2024
"watchos",
2125
"windows",
2226
]
@@ -214,4 +218,10 @@ def triplet_name(os, arch):
214218
elif arch == "x86_64":
215219
return "x86_64-apple-darwin21"
216220

221+
elif os == "emscripten":
222+
if arch == "wasm32":
223+
return "wasm32-unknown-emscripten"
224+
elif arch == "wasm64":
225+
return "wasm64-unknown-emscripten"
226+
217227
return "unknown"

0 commit comments

Comments
 (0)