Skip to content

Commit 61ba83f

Browse files
authored
[0084] 修复 goldfish 的 WASM 构建支持 (#882)
1 parent 2ffc766 commit 61ba83f

8 files changed

Lines changed: 42 additions & 9 deletions

File tree

devel/0084.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# [0084] 修复 goldfish 的 WASM 构建支持
2+
## What
3+
1.`liii_subprocess.cpp` 中的 `wordexp` 相关调用添加缺失的条件编译宏
4+
2. 删去 `s7_internal_helpers.h` 中的静态函数定义,在 WASM 编译条件下将导致重复定义
5+
3.`s7_scheme_inexact.c` 中的 `int_to_int` 静态函数添加缺失的条件编译宏
6+
4. 修改 emscripten 版本为 3.1.56 (原来的 3.1.55 下载源关闭了,无法拉取)
7+
5. 修改 cpr, libcurl, json_schema_validator 的 `xmake.lua`,允许 wasm 平台编译
8+
9+
## 如何测试
10+
1.
11+
```
12+
xmake f -p wasm
13+
```
14+
2.
15+
```
16+
xmake b goldfish
17+
```
18+
3.
19+
```
20+
xmake r goldfish
21+
```
22+
4.
23+
浏览器中应该显示出 goldfish 的帮助输出
24+
25+
console 中输入
26+
27+
```javascript
28+
callMain(["-e", "(+ 1 2)"])
29+
```
30+
31+
应当有输出 ‘3’

src/liii_subprocess.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,15 @@ f_subprocess_run_values (s7_scheme* sc, s7_pointer args) {
255255
const char* cmd_c= s7_string (cmd_arg);
256256
#ifdef TB_CONFIG_OS_WINDOWS
257257
process= tb_process_init_cmd (cmd_c, &attr);
258-
#else
258+
#elif !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__EMSCRIPTEN__)
259259
wordexp_t p;
260260
int ret= wordexp (cmd_c, &p, 0);
261261
if (ret == 0 && p.we_wordc > 0) {
262262
process= tb_process_init (p.we_wordv[0], (tb_char_t const**) p.we_wordv, &attr);
263263
wordfree (&p);
264264
}
265+
#else
266+
process= tb_process_init_cmd (cmd_c, &attr);
265267
#endif
266268
}
267269
else if (s7_is_pair (cmd_arg)) {

src/s7_internal_helpers.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828
#define multiply_overflow(A, B, C) __builtin_mul_overflow(A, B, C)
2929
#elif defined(__GNUC__) && (__GNUC__ >= 5)
3030
#define multiply_overflow(A, B, C) __builtin_mul_overflow(A, B, C)
31-
#else
32-
static bool multiply_overflow(s7_int A, s7_int B, s7_int *C) {*C = A * B; return(false);}
3331
#endif
34-
#else
35-
static bool multiply_overflow(s7_int A, s7_int B, s7_int *C) {*C = A * B; return(false);}
3632
#endif
3733

3834
/* forward declarations for internal types used in bridge functions */

src/s7_scheme_inexact.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,12 @@ static s7_int int_to_int(s7_int x, s7_int n)
11411141
do {
11421142
if (n & 1) value *= x;
11431143
n >>= 1;
1144+
#if HAVE_OVERFLOW_CHECKS
11441145
if (multiply_overflow(x, x, &x))
11451146
break;
1147+
#else
1148+
x *= x;
1149+
#endif
11461150
} while (n);
11471151
return(value);
11481152
}

xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ end
6464

6565
if is_plat("wasm") then
6666
if has_config("pin-deps") then
67-
add_requires("emscripten 3.1.55")
67+
add_requires("emscripten 3.1.56")
6868
else
6969
add_requires("emscripten")
7070
end

xmake/packages/c/cpr/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package("cpr")
2323
end
2424
end)
2525

26-
on_install("linux", "macosx", "windows", "mingw@windows", function (package)
26+
on_install("linux", "macosx", "windows", "mingw@windows", "wasm", function (package)
2727
local configs = {"-DCPR_BUILD_TESTS=OFF",
2828
"-DCPR_FORCE_USE_SYSTEM_CURL=ON",
2929
"-DCPR_USE_SYSTEM_CURL=ON"}

xmake/packages/j/json_schema_validator/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package("json_schema_validator")
88
add_deps("cmake", "nlohmann_json")
99
add_links("nlohmann_json_schema_validator")
1010

11-
on_install("linux", "macosx", "windows", "mingw@windows", function (package)
11+
on_install("linux", "macosx", "windows", "mingw@windows", "wasm", function (package)
1212
local nlohmann_json = package:dep("nlohmann_json")
1313
local nlohmann_json_cmake_dir = path.join(nlohmann_json:installdir("lib"), "cmake", "nlohmann_json")
1414
local configs = {

xmake/packages/l/libcurl/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ package("libcurl")
8484
end
8585
end)
8686

87-
on_install("windows", "mingw", "linux", "macosx", "iphoneos", "cross", "android", function (package)
87+
on_install("windows", "mingw", "linux", "macosx", "iphoneos", "cross", "android", "wasm", function (package)
8888
local version = package:version()
8989

9090
local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_MANUAL=OFF", "-DENABLE_CURL_MANUAL=OFF"}

0 commit comments

Comments
 (0)