Skip to content

Commit 69f297a

Browse files
committed
add guard-checker
1 parent a2d7ff1 commit 69f297a

File tree

11 files changed

+76
-3
lines changed

11 files changed

+76
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ docker/c2wasm-api
55
docker/wasi-sdk
66
docker/clangd
77
docker/hook-cleaner
8+
docker/guard_checker
89
docker/qjsc
10+
guard-checker/guard_checker
911
wasi-sdk.ts

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "c2wasm-api/clang/includes"]
1414
path = c2wasm-api/clang/includes
1515
url = https://github.com/Xahau/xahaud
16+
[submodule "guard-checker"]
17+
path = guard-checker
18+
url = https://github.com/RichardAH/guard-checker

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ checkout:
88
git submodule update --init --recursive llvm-project
99
git submodule update --init --recursive wasi-sdk
1010
git submodule update --init --recursive hook-cleaner-c
11+
git submodule update --init --recursive guard-checker
1112
git submodule update --init --recursive quickjslite
1213
git submodule update --init --recursive c2wasm-api/clang/includes
1314

@@ -23,6 +24,7 @@ build: bin
2324
$(MAKE) -C clang-build
2425
$(MAKE) -C clangd-build
2526
$(MAKE) -C cleaner-build
27+
$(MAKE) -C guard-checker-build
2628
$(MAKE) -C qjsc-build
2729
$(MAKE) -C docker
2830

@@ -39,6 +41,8 @@ clean:
3941
$(MAKE) -C clang-build clean
4042
$(MAKE) -C clangd-build clean
4143
$(MAKE) -C cleaner-build clean
44+
$(MAKE) -C guard-checker-build clean
4245
$(MAKE) -C qjsc-build clean
4346
$(MAKE) -C docker clean
4447
-rm -rf bin doc
48+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unzip bin.zip
5656
```
5757

5858
- CD to docker folder `cd docker`
59-
- Run `make c2wasm-api && make clangd && make wasi-sdk && make hook-cleaner && make qjsc`
59+
- Run `make c2wasm-api && make clangd && make wasi-sdk && make hook-cleaner && make guard-checker && make qjsc`
6060
- Run `docker-compose build`
6161
- Run `docker-compose up` or `docker-compose up -d`
6262
- 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.

c2wasm-api/src/chooks.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function get_optimization_options(options: string) {
108108
optimization_level += ' ' + o;
109109
}
110110
}
111-
111+
112112
let safe_options = '';
113113
const _options = [
114114
'--shrink-level=100000000',
@@ -203,7 +203,7 @@ function link_c_files(source_files: string[], compile_options: string, link_opti
203203
const files = source_files.join(' ');
204204
const clang = llvmDir + '/bin/clang';
205205
let optimization_level = '';
206-
206+
207207
for (let o of optimization_options) {
208208
if (compile_options.includes(o)) {
209209
optimization_level == o;
@@ -265,6 +265,27 @@ function clean_wasm(cwd: string, inplace: string, result_obj: Task) {
265265
return success;
266266
}
267267

268+
function guard_check_wasm(cwd: string, inplace: string, result_obj: Task) {
269+
const cmd = 'guard_checker ' + inplace;
270+
const out = openSync(cwd + '/guardout.log', 'w');
271+
let error = '';
272+
let success = true;
273+
try {
274+
execSync(cmd, { cwd, stdio: [null, out, out], });
275+
} catch (ex: unknown) {
276+
success = false;
277+
if (ex instanceof Error) {
278+
error = ex?.message;
279+
}
280+
} finally {
281+
closeSync(out);
282+
}
283+
const out_msg = readFileSync(cwd + '/guardout.log').toString() || error;
284+
result_obj.console = sanitize_shell_output(out_msg);
285+
result_obj.success = success;
286+
return success;
287+
}
288+
268289
export function build_project(project: RequestBody, base: string) {
269290
const output = project.output;
270291
const compress = project.compress;
@@ -377,6 +398,14 @@ export function build_project(project: RequestBody, base: string) {
377398
}
378399
}
379400

401+
const guard_result_obj = {
402+
name: 'guard checking wasm'
403+
};
404+
build_result.tasks.push(guard_result_obj);
405+
if (!guard_check_wasm(dir, result, guard_result_obj)) {
406+
return complete(false, 'Guard checking error');
407+
}
408+
380409
build_result.output = serialize_file_data(result, compress || false);
381410

382411
return complete(true, 'Success');

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ COPY c2wasm-api/tsconfig.json .
1111
COPY c2wasm-api/src ./src
1212
COPY wasi-sdk ./clang/wasi-sdk
1313
COPY hook-cleaner /usr/bin
14+
COPY guard_checker /usr/bin
1415
COPY wasm-opt /usr/bin
1516
COPY qjsc /usr/bin
1617
COPY run.sh .

docker/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ hook-cleaner: ../bin/hook-cleaner
2727
cp $< .
2828
chmod +x hook-cleaner
2929

30+
guard-checker: ../bin/guard_checker
31+
cp $< .
32+
chmod +x guard_checker
33+
3034
c2wasm-api: ../c2wasm-api
3135
cp -LR $< .
3236

guard-checker

Submodule guard-checker added at de69e8a

guard-checker-build/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM --platform=linux/amd64 node:17-alpine
2+
MAINTAINER Vaclav Barta "vaclav@equilibrium.co"
3+
RUN apk --no-cache add --update bash build-base
4+
ADD build.sh .
5+
CMD ./build.sh

guard-checker-build/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# must be run as root
2+
3+
GUARD_CHECKER_BUILD_CONTAINER_TAG?=guard-checker-build
4+
5+
all: build1 build2 install
6+
7+
build1:
8+
docker build -t $(GUARD_CHECKER_BUILD_CONTAINER_TAG) .
9+
10+
build2:
11+
docker run -v $(realpath ../guard-checker):/mnt/guard-checker $(GUARD_CHECKER_BUILD_CONTAINER_TAG):latest
12+
13+
install:
14+
cp ../guard-checker/guard_checker ../bin
15+
16+
clean:
17+
-rm ../guard-checker/guard_checker

0 commit comments

Comments
 (0)