From 7bdf7822f585eafbf8c67585e23318a13be7545a Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Fri, 8 Dec 2023 14:22:36 +0100 Subject: [PATCH 1/5] Removed c2wasm-api/clang/includes submodule --- .gitmodules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index ab41e3dfbf45..5ab6a9373708 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,6 @@ [submodule "hook-cleaner-c"] path = hook-cleaner-c url = https://github.com/XRPLF/hook-cleaner-c -[submodule "c2wasm-api/clang/includes"] - path = c2wasm-api/clang/includes - url = https://github.com/XRPLF/hook-macros +[submodule "guard-checker"] + path = guard-checker + url = git@github.com:RichardAH/guard-checker.git From 6c970aa304f684c081322ed41800f7739b95ecba Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Fri, 8 Dec 2023 14:24:20 +0100 Subject: [PATCH 2/5] Updated c2wasm-api/clang/includes submodule to use Xahau/xahaud --- .gitmodules | 3 +++ c2wasm-api/clang/includes | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 5ab6a9373708..277111c49bc4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "guard-checker"] path = guard-checker url = git@github.com:RichardAH/guard-checker.git +[submodule "c2wasm-api/clang/includes"] + path = c2wasm-api/clang/includes + url = https://github.com/Xahau/xahaud diff --git a/c2wasm-api/clang/includes b/c2wasm-api/clang/includes index b444a04229b1..ac694c7c9020 160000 --- a/c2wasm-api/clang/includes +++ b/c2wasm-api/clang/includes @@ -1 +1 @@ -Subproject commit b444a04229b1af433a791ab9275243c416429fb4 +Subproject commit ac694c7c9020a993f27198382634ea035d0dcb47 From 16779f6151bdb7060e1120eb3b85d00f11843283 Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Wed, 13 Dec 2023 09:59:17 +0100 Subject: [PATCH 3/5] update header location --- c2wasm-api/copyheaders.sh | 4 ++-- docker/Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/c2wasm-api/copyheaders.sh b/c2wasm-api/copyheaders.sh index f296ddc80c79..5fcf72ff8d37 100755 --- a/c2wasm-api/copyheaders.sh +++ b/c2wasm-api/copyheaders.sh @@ -9,7 +9,7 @@ then else mkdir -p /work/c fi -cp clang/includes/*.h /work/c +cp clang/includes/hook/*.h /work/c if [ -d /app/clang/includes ] then @@ -17,4 +17,4 @@ then else mkdir -p /app/clang/includes fi -cp clang/includes/*.h /app/clang/includes +cp clang/include/hook/*.h /app/clang/includes diff --git a/docker/Dockerfile b/docker/Dockerfile index 18245aaf17de..838e70d22d73 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER Vaclav Barta "vaclav@equilibrium.co" RUN apk --no-cache add su-exec COPY clangd /usr/bin WORKDIR /app -COPY c2wasm-api/clang/includes ./clang/includes +COPY c2wasm-api/clang/includes/hook ./clang/includes COPY c2wasm-api/package.json . COPY c2wasm-api/yarn.lock . COPY c2wasm-api/tsconfig.json . From 1698c0a9bd96458324a96f7659634879c4fddba3 Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Wed, 13 Dec 2023 09:59:33 +0100 Subject: [PATCH 4/5] remove guard check --- .gitmodules | 3 --- README.md | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index 277111c49bc4..841db13bf01c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "hook-cleaner-c"] path = hook-cleaner-c url = https://github.com/XRPLF/hook-cleaner-c -[submodule "guard-checker"] - path = guard-checker - url = git@github.com:RichardAH/guard-checker.git [submodule "c2wasm-api/clang/includes"] path = c2wasm-api/clang/includes url = https://github.com/Xahau/xahaud diff --git a/README.md b/README.md index 46aba17f1e27..073297ad8e1f 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ unzip bin.zip ``` - CD to docker folder `cd docker` -- Run `make c2wasm-api && make clangd && make wasi-sdk && make hook-cleaner` +- Run `make c2wasm-api && make clangd && make wasi-sdk && make hook-cleaner && make c2wasm-api/clang/includes/src/ripple/app/hook` - Run `docker-compose build` - Run `docker-compose up` or `docker-compose up -d` - This should start server at port `:9000`, the actual compiling endpoint is this: [http://localhost:9000/api/build](localhost:9000/api/build). Note that it takes a while to start. From bd856b4210e0515995762ac131a6bff5803e03de Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Fri, 19 Jan 2024 01:57:12 +0100 Subject: [PATCH 5/5] update optimization --- c2wasm-api/src/index.ts | 76 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/c2wasm-api/src/index.ts b/c2wasm-api/src/index.ts index 8e0173a1c7f5..dac5a8739baf 100644 --- a/c2wasm-api/src/index.ts +++ b/c2wasm-api/src/index.ts @@ -100,18 +100,51 @@ function shell_exec(cmd: string, cwd: string) { return result; } +const optimization_options = [ + /* default '-O0' not included */ '-O1', '-O2', '-O3', '-O4', '-Oz' +]; + function get_optimization_options(options: string) { - const optimization_options = [ - /* default '-O0' not included */ '-O1', '-O2', '-O3', '-O4', '-Os' - ]; - let safe_options = ''; + let optimization_level = ''; for (let o of optimization_options) { if (options.includes(o)) { - safe_options += ' ' + o; + optimization_level == o; } } + let safe_options = ''; + const _options = [ + '--shrink-level=100000000', + '--coalesce-locals-learning', + '--vacuum', + '--merge-blocks', + '--merge-locals', + '--flatten', + '--ignore-implicit-traps', + '-ffm', + '--const-hoisting', + '--code-folding', + '--code-pushing', + '--dae-optimizing', + '--dce', + '--simplify-globals-optimizing', + '--simplify-locals-nonesting', + '--reorder-locals', + '--rereloop', + '--precompute-propagate', + '--local-cse', + '--remove-unused-brs', + '--memory-packing', + '-c', + '--avoid-reinterprets', + optimization_level + ] + + for (let o of _options) { + safe_options += ' ' + o; + } + return safe_options; } @@ -173,7 +206,15 @@ function validate_filename(name: string) { function link_c_files(source_files: string[], compile_options: string, link_options: string, cwd: string, output: string, result_obj: Task) { const files = source_files.join(' '); const clang = llvmDir + '/bin/clang'; - const cmd = clang + ' ' + get_clang_options(compile_options) + ' ' + get_lld_options(link_options) + ' ' + files + ' -o ' + output; + let optimization_level = ''; + for (let o of optimization_options) { + if (compile_options.includes(o)) { + optimization_level == o; + } + } + const cmd = clang + ' ' + optimization_level + ' ' + get_clang_options(compile_options) + ' ' + get_lld_options(link_options) + ' ' + files + ' -o ' + output; + console.log(cmd); + const out = shell_exec(cmd, cwd); result_obj.console = sanitize_shell_output(out); if (!existsSync(output)) { @@ -186,7 +227,7 @@ function link_c_files(source_files: string[], compile_options: string, link_opti function optimize_wasm(cwd: string, inplace: string, opt_options: string, result_obj: Task) { const unopt = cwd + '/unopt.wasm'; - const cmd = 'wasm-opt ' + opt_options + ' -o ' + inplace + ' ' + unopt; + const cmd = 'wasm-opt ' + opt_options + ' -o ' + inplace + ' ' + unopt; const out = openSync(cwd + '/opt.log', 'w'); let error = ''; let success = true; @@ -309,6 +350,27 @@ function build_project(project: RequestBody, base: string) { return complete(false, 'Optimization error'); } } + + + if (strip) { + const clean_obj = { + name: 'cleaning wasm' + }; + build_result.tasks.push(clean_obj); + if (!clean_wasm(dir, result, clean_obj)) { + return complete(false, 'Post-build error'); + } + } + + if (opt_options) { + const opt_obj = { + name: 'optimizing wasm' + }; + build_result.tasks.push(opt_obj); + if (!optimize_wasm(dir, result, opt_options, opt_obj)) { + return complete(false, 'Optimization error'); + } + } if (strip) { const clean_obj = {